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

Reader class for reading a manifest. More...

#include <c2pa.hpp>

Public Member Functions

 Reader (IContextProvider &context, const std::string &format, std::istream &stream)
 Create a Reader from a context and stream.
 
 Reader (IContextProvider &context, const std::filesystem::path &source_path)
 Create a Reader from a context and file path.
 
 Reader (const std::string &format, std::istream &stream)
 Create a Reader from a stream (will use global settings if any loaded).
 
 Reader (const std::filesystem::path &source_path)
 Create a Reader from a file path (will use global settings if any loaded).
 
 Reader (const Reader &)=delete
 
Readeroperator= (const Reader &)=delete
 
 Reader (Reader &&other) noexcept
 
Readeroperator= (Reader &&other) noexcept
 
 ~Reader ()
 
bool is_embedded () const
 Check if the reader was created from an embedded manifest.
 
std::optional< std::string > remote_url () const
 Returns the remote url of the manifest if this Reader obtained the manifest remotely.
 
std::string json () const
 Get the manifest as a JSON string.
 
int64_t get_resource (const std::string &uri, const std::filesystem::path &path)
 Get a resource from the reader and write it to a file.
 
int64_t get_resource (const std::string &uri, std::ostream &stream)
 Get a resource from the reader and write it to an output stream.
 
C2paReader * get_api_internal_raw_reader () const
 Get the raw C2paReader pointer.
 

Static Public Member Functions

static std::vector< std::string > supported_mime_types ()
 Get a list of mime types that the SDK can read manifests from.
 

Detailed Description

Reader class for reading a manifest.

This class is used to read and validate a manifest from a stream or file. Resources are managed using RAII; member order ensures cpp_stream (which holds a C stream pointing at the ifstream) is destroyed before owned_stream.

Constructor & Destructor Documentation

◆ Reader() [1/6]

c2pa::Reader::Reader ( IContextProvider context,
const std::string &  format,
std::istream &  stream 
)

Create a Reader from a context and stream.

Parameters
contextContext provider; used at construction to configure settings.
formatThe mime format of the stream.
streamThe input stream to read from.
Exceptions
C2paExceptionif context.is_valid() returns false, or for other errors encountered by the C2PA library.

◆ Reader() [2/6]

c2pa::Reader::Reader ( IContextProvider context,
const std::filesystem::path &  source_path 
)

Create a Reader from a context and file path.

Parameters
contextContext provider; used at construction only to configure settings.
source_pathThe path to the file to read.
Exceptions
C2paExceptionif context.is_valid() returns false, or for other errors encountered by the C2PA library.
Note
Prefer using the streaming APIs if possible.

◆ Reader() [3/6]

c2pa::Reader::Reader ( const std::string &  format,
std::istream &  stream 
)

Create a Reader from a stream (will use global settings if any loaded).

The validation_status field in the JSON contains validation results.

Parameters
formatThe mime format of the stream.
streamThe input stream to read from.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.
Deprecated:
Use Reader(IContextProvider& context, format, stream) instead.

◆ Reader() [4/6]

c2pa::Reader::Reader ( const std::filesystem::path &  source_path)

Create a Reader from a file path (will use global settings if any loaded).

Parameters
source_pathThe path to the file to read.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.
Deprecated:
Use Reader(IContextProvider& context, source_path) instead.
Note
Prefer using the streaming APIs if possible.

◆ Reader() [5/6]

c2pa::Reader::Reader ( const Reader )
delete

◆ Reader() [6/6]

c2pa::Reader::Reader ( Reader &&  other)
inlinenoexcept
662 : c2pa_reader(std::exchange(other.c2pa_reader, nullptr)),
663 owned_stream(std::move(other.owned_stream)),
664 cpp_stream(std::move(other.cpp_stream)) {
665 }

◆ ~Reader()

c2pa::Reader::~Reader ( )

Member Function Documentation

◆ get_api_internal_raw_reader()

C2paReader * c2pa::Reader::get_api_internal_raw_reader ( ) const
inline

Get the raw C2paReader pointer.

Returns
The raw C2paReader pointer.
Note
This is intended for internal API use and compatibility with C APIs.
715{ return c2pa_reader; }

◆ get_resource() [1/2]

int64_t c2pa::Reader::get_resource ( const std::string &  uri,
const std::filesystem::path &  path 
)

Get a resource from the reader and write it to a file.

Parameters
uriThe URI of the resource.
pathThe file path to write the resource to.
Returns
The number of bytes written.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.
Note
Prefer using the streaming APIs if possible.

◆ get_resource() [2/2]

int64_t c2pa::Reader::get_resource ( const std::string &  uri,
std::ostream &  stream 
)

Get a resource from the reader and write it to an output stream.

Parameters
uriThe URI of the resource.
streamThe output stream to write the resource to.
Returns
The number of bytes written.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.

◆ is_embedded()

bool c2pa::Reader::is_embedded ( ) const
inline

Check if the reader was created from an embedded manifest.

Returns
true if the manifest was embedded in the asset, false if external.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.
682 {
683 return c2pa_reader_is_embedded(c2pa_reader);
684 }

◆ json()

std::string c2pa::Reader::json ( ) const

Get the manifest as a JSON string.

Returns
The manifest as a JSON string.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Reader & c2pa::Reader::operator= ( Reader &&  other)
inlinenoexcept
667 {
668 if (this != &other) {
669 c2pa_free(c2pa_reader);
670 c2pa_reader = std::exchange(other.c2pa_reader, nullptr);
671 owned_stream = std::move(other.owned_stream);
672 cpp_stream = std::move(other.cpp_stream);
673 }
674 return *this;
675 }

◆ remote_url()

std::optional< std::string > c2pa::Reader::remote_url ( ) const

Returns the remote url of the manifest if this Reader obtained the manifest remotely.

Returns
Optional string containing the remote URL, or std::nullopt if manifest was embedded.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.

◆ supported_mime_types()

static std::vector< std::string > c2pa::Reader::supported_mime_types ( )
static

Get a list of mime types that the SDK can read manifests from.

Returns
Vector of supported MIME type strings.

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