c2pa-c
C++ API for c2pa-c library
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.
 
Context create_context ()
 Create a Context from the current builder configuration.
 

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

◆ 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_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: