c2pa-cpp
C++ API for the C2PA SDK
Loading...
Searching...
No Matches
c2pa::Context::ContextBuilder Class Reference

ContextBuilder for creating customized Context instances. More...

#include <c2pa.hpp>

Public Member Functions

 ContextBuilder ()
 
 ~ContextBuilder () noexcept
 
 ContextBuilder (ContextBuilder &&) noexcept
 
ContextBuilderoperator= (ContextBuilder &&) noexcept
 
 ContextBuilder (const ContextBuilder &)=delete
 
ContextBuilderoperator= (const ContextBuilder &)=delete
 
bool is_valid () const noexcept
 Check if the builder is in a valid state.
 
ContextBuilderwith_settings (const Settings &settings)
 Configure with Settings object.
 
ContextBuilderwith_json (const std::string &json)
 Configure settings with JSON string.
 
ContextBuilderwith_json_settings_file (const std::filesystem::path &settings_path)
 Configure settings from a JSON settings file.
 
ContextBuilderwith_signer (Signer &&signer)
 Set a Signer on the context being built.
 
ContextBuilderwith_progress_callback (ProgressCallbackFunc callback)
 Attach a progress callback to the context being built.
 
Context create_context ()
 Create a Context from the current builder configuration.
 
C2paContextBuilder * release () noexcept
 Release ownership of the underlying C2paContextBuilder pointer. After this call, the ContextBuilder no longer owns the pointer and is_valid() returns false. The caller is responsible for managing the lifetime of the returned pointer.
 

Detailed Description

ContextBuilder for creating customized Context instances.

Provides a builder pattern for configuring contexts with multiple settings. Note: create_context() consumes the builder.

Note
For most use cases, prefer direct construction via the Context constructors. The ContextBuilder is useful when you need to layer multiple configuration sources (e.g. with_settings() followed by with_json()).

Constructor & Destructor Documentation

◆ ContextBuilder() [1/3]

c2pa::Context::ContextBuilder::ContextBuilder ( )

◆ ~ContextBuilder()

c2pa::Context::ContextBuilder::~ContextBuilder ( )
noexcept

◆ ContextBuilder() [2/3]

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

◆ ContextBuilder() [3/3]

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

Member Function Documentation

◆ create_context()

Context c2pa::Context::ContextBuilder::create_context ( )

Create a Context from the current builder configuration.

Returns
A new Context instance.
Exceptions
C2paExceptionif context creation fails.
Note
This consumes the builder. After calling this, is_valid() returns false.

◆ is_valid()

bool c2pa::Context::ContextBuilder::is_valid ( ) const
noexcept

Check if the builder is in a valid state.

Returns
true if the builder can be used, false if moved from.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ release()

C2paContextBuilder * c2pa::Context::ContextBuilder::release ( )
noexcept

Release ownership of the underlying C2paContextBuilder pointer. After this call, the ContextBuilder no longer owns the pointer and is_valid() returns false. The caller is responsible for managing the lifetime of the returned pointer.

Returns
Pointer to the C2paContextBuilder object, or nullptr if moved from.

◆ with_json()

ContextBuilder & c2pa::Context::ContextBuilder::with_json ( const std::string &  json)

Configure settings with JSON string.

Parameters
jsonJSON configuration string.
Returns
Reference to this ContextBuilder for method chaining.
Exceptions
C2paExceptionif JSON is invalid.

◆ with_json_settings_file()

ContextBuilder & c2pa::Context::ContextBuilder::with_json_settings_file ( const std::filesystem::path &  settings_path)

Configure settings from a JSON settings file.

Parameters
settings_pathFull path to the JSON settings file.
Returns
Reference to this ContextBuilder for method chaining.
Exceptions
C2paExceptionif file cannot be read or JSON is invalid.

◆ with_progress_callback()

ContextBuilder & c2pa::Context::ContextBuilder::with_progress_callback ( ProgressCallbackFunc  callback)

Attach a progress callback to the context being built.

The callback is invoked at each major phase of signing and reading operations performed with the resulting context. Return false from the callback to abort the current operation with an OperationCancelled error.

Phases emitted during a typical sign cycle (in order): VerifyingIngredient → VerifyingManifest → VerifyingSignature → VerifyingAssetHash → Thumbnail → Hashing → Signing → Embedding → (if verify_after_sign) VerifyingManifest → … → VerifyingIngredient

Phases emitted during reading: Reading → VerifyingManifest → VerifyingSignature → VerifyingAssetHash → VerifyingIngredient

Parameters
callbackA callable matching ProgressCallbackFunc. The callback is heap-allocated and owned by the resulting Context. Calling this method more than once on the same builder replaces the previous callback. The callable must not throw when invoked (see ProgressCallbackFunc).
Returns
Reference to this ContextBuilder for method chaining.
Exceptions
C2paExceptionif the builder is invalid or the C API call fails.

◆ with_settings()

ContextBuilder & c2pa::Context::ContextBuilder::with_settings ( const Settings settings)

Configure with Settings object.

Parameters
settingsSettings to use (will be copied into the context). Must be valid (is_valid() true).
Returns
Reference to this ContextBuilder for method chaining.
Exceptions
C2paExceptionif settings are invalid or settings.is_valid() is false.

◆ with_signer()

ContextBuilder & c2pa::Context::ContextBuilder::with_signer ( Signer &&  signer)

Set a Signer on the context being built.

After this call the source Signer object is consumed and must not be reused, as it becomes part to the context and tied to it. If settings also contain a signer, the programmatic signer set through this API will be used for signing.

Parameters
signerSigner to put into the context.
Returns
Reference to this ContextBuilder for method chaining.
Exceptions
C2paExceptionif the builder or signer is invalid.

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