c2pa-c
C++ API for c2pa-c library
Loading...
Searching...
No Matches
c2pa::Context Class Reference

C2PA context implementing IContextProvider. More...

#include <c2pa.hpp>

Inheritance diagram for c2pa::Context:
Collaboration diagram for c2pa::Context:

Classes

class  ContextBuilder
 ContextBuilder for creating customized Context instances. More...
 

Public Member Functions

 Context ()
 Create a Context with default settings.
 
 Context (const Settings &settings)
 Create a Context configured with a Settings object.
 
 Context (const std::string &json)
 Create a Context configured with a JSON string.
 
 Context (const Settings &settings, Signer &&signer)
 Create a Context with a Settings object and a Signer.
 
 Context (const Context &)=delete
 
Contextoperator= (const Context &)=delete
 
 Context (Context &&) noexcept
 
Contextoperator= (Context &&) noexcept
 
 ~Context () noexcept override
 
C2paContext * c_context () const noexcept override
 Get the underlying C2PA context pointer.
 
bool is_valid () const noexcept override
 Check if this Context has a valid context (validity check for context-like types).
 
 Context (C2paContext *ctx)
 Internal constructor from raw FFI pointer (prefer public constructors).
 
- Public Member Functions inherited from c2pa::IContextProvider
virtual ~IContextProvider () noexcept=default
 

Additional Inherited Members

- Protected Member Functions inherited from c2pa::IContextProvider
 IContextProvider ()=default
 
 IContextProvider (const IContextProvider &)=delete
 
IContextProvideroperator= (const IContextProvider &)=delete
 

Detailed Description

C2PA context implementing IContextProvider.

Context objects manage C2PA SDK configuration and state. Contexts can be created via direct construction or the ContextBuilder:

Direct construction:

c2pa::Context ctx; // default
c2pa::Context ctx(settings); // from Settings
c2pa::Context ctx(json); // from JSON string
C2PA context implementing IContextProvider.
Definition c2pa.hpp:261

ContextBuilder (for multi-step configuration):

.with_settings(settings)
.with_json(json)
ContextBuilder for creating customized Context instances.
Definition c2pa.hpp:269
Context create_context()
Create a Context from the current builder configuration.
ContextBuilder & with_json(const std::string &json)
Configure settings with JSON string.
ContextBuilder & with_settings(const Settings &settings)
Configure with Settings object.

Builder and Reader take the context by reference (IContextProvider&). The context object must outlive the Builder or Reader instance.

Constructor & Destructor Documentation

◆ Context() [1/7]

c2pa::Context::Context ( )

Create a Context with default settings.

Exceptions
C2paExceptionif context creation fails.

◆ Context() [2/7]

c2pa::Context::Context ( const Settings settings)
explicit

Create a Context configured with a Settings object.

Parameters
settingsSettings configuration to apply. Must be valid (settings.is_valid() true).
Exceptions
C2paExceptionif settings are invalid, settings.is_valid() is false, or context creation fails.

◆ Context() [3/7]

c2pa::Context::Context ( const std::string &  json)
explicit

Create a Context configured with a JSON string.

Parameters
jsonJSON configuration string.
Exceptions
C2paExceptionif JSON is invalid or context creation fails.

◆ Context() [4/7]

c2pa::Context::Context ( const Settings settings,
Signer &&  signer 
)

Create a Context with a Settings object and a Signer.

Parameters
settingsSettings configuration to apply.
signerSigner to move into the context. Consumed after this call. The programmatic Signer from the signer parameter takes priority over the Signer in settings, so use this API when wanting to explicitly set a Signer (or override the Signer in settings).
Exceptions
C2paExceptionif settings or signer are invalid, or context creation fails.

◆ Context() [5/7]

c2pa::Context::Context ( const Context )
delete

◆ Context() [6/7]

c2pa::Context::Context ( Context &&  )
noexcept

◆ ~Context()

c2pa::Context::~Context ( )
overridenoexcept

◆ Context() [7/7]

c2pa::Context::Context ( C2paContext *  ctx)
explicit

Internal constructor from raw FFI pointer (prefer public constructors).

Parameters
ctxRaw C2paContext pointer — Context takes ownership.
Exceptions
C2paExceptionif ctx is nullptr.

Member Function Documentation

◆ c_context()

C2paContext * c2pa::Context::c_context ( ) const
overridevirtualnoexcept

Get the underlying C2PA context pointer.

Returns
C2paContext pointer when is_valid() is true; nullptr when moved-from (is_valid() false).
Note
Callers must check is_valid() before using the result; do not pass nullptr to the C API.

Implements c2pa::IContextProvider.

◆ is_valid()

bool c2pa::Context::is_valid ( ) const
overridevirtualnoexcept

Check if this Context has a valid context (validity check for context-like types).

Returns
true when the object holds a valid C context; false when moved-from.
Note
After move, is_valid() is false and c_context() returns nullptr.

Implements c2pa::IContextProvider.

◆ operator=() [1/2]

Context & c2pa::Context::operator= ( const Context )
delete

◆ operator=() [2/2]

Context & c2pa::Context::operator= ( Context &&  )
noexcept

The documentation for this class was generated from the following file: