Exiv2::Value Class Referenceabstract

Common interface for all types of values used with metadata. More...

#include <value.hpp>

Inheritance diagram for Exiv2::Value:

Public Types

using UniquePtr = std::unique_ptr< Value >
 Shortcut for a Value auto pointer.
 

Public Member Functions

Creators
 Value (TypeId typeId)
 Constructor, taking a type id to initialize the base class with.
 
virtual ~Value ()=default
 Virtual destructor.
 
Manipulators
virtual int read (const byte *buf, size_t len, ByteOrder byteOrder)=0
 Read the value from a character buffer. More...
 
virtual int read (const std::string &buf)=0
 Set the value from a string buffer. The format of the string corresponds to that of the write() method, i.e., a string obtained through the write() method can be read by this function. More...
 
virtual int setDataArea (const byte *buf, size_t len)
 Set the data area, if the value has one by copying (cloning) the buffer pointed to by buf. More...
 

Accessors

bool ok_ {true}
 Indicates the status of the previous to<Type> conversion.
 
TypeId typeId () const
 Return the type identifier (Exif data format type).
 
UniquePtr clone () const
 Return an auto-pointer to a copy of itself (deep copy). The caller owns this copy and the auto-pointer ensures that it will be deleted.
 
virtual size_t copy (byte *buf, ByteOrder byteOrder) const =0
 Write value to a data buffer. More...
 
virtual size_t count () const =0
 Return the number of components of the value.
 
virtual size_t size () const =0
 Return the size of the value in bytes.
 
virtual std::ostream & write (std::ostream &os) const =0
 Write the value to an output stream. You do not usually have to use this function; it is used for the implementation of the output operator for Value, operator<<(std::ostream &os, const Value &value).
 
std::string toString () const
 Return the value as a string. Implemented in terms of write(std::ostream& os) const of the concrete class.
 
virtual std::string toString (size_t n) const
 Return the n-th component of the value as a string. The default implementation returns toString(). The behaviour of this method may be undefined if there is no n-th component.
 
virtual int64_t toInt64 (size_t n=0) const =0
 Convert the n-th component of the value to an int64_t. The behaviour of this method may be undefined if there is no n-th component. More...
 
virtual uint32_t toUint32 (size_t n=0) const =0
 Convert the n-th component of the value to a float. The behaviour of this method may be undefined if there is no n-th component. More...
 
virtual float toFloat (size_t n=0) const =0
 Convert the n-th component of the value to a float. The behaviour of this method may be undefined if there is no n-th component. More...
 
virtual Rational toRational (size_t n=0) const =0
 Convert the n-th component of the value to a Rational. The behaviour of this method may be undefined if there is no n-th component. More...
 
virtual size_t sizeDataArea () const
 Return the size of the data area, 0 if there is none.
 
virtual DataBuf dataArea () const
 Return a copy of the data area if the value has one. The caller owns this copy and DataBuf ensures that it will be deleted. More...
 
bool ok () const
 Check the ok status indicator. After a to<Type> conversion, this indicator shows whether the conversion was successful.
 
static UniquePtr create (TypeId typeId)
 A (simple) factory to create a Value type. More...
 
 Value (const Value &)=default
 
Valueoperator= (const Value &)=default
 Assignment operator. Protected so that it can only be used by subclasses but not directly.
 

Detailed Description

Common interface for all types of values used with metadata.

The interface provides a uniform way to access values independent of their actual C++ type for simple tasks like reading the values from a string or data buffer. For other tasks, like modifying values you may need to downcast it to a specific subclass to access its interface.

Examples
xmpsample.cpp.

Member Function Documentation

◆ copy()

virtual size_t Exiv2::Value::copy ( byte buf,
ByteOrder  byteOrder 
) const
pure virtual

Write value to a data buffer.

The user must ensure that the buffer has enough memory. Otherwise the call results in undefined behaviour.

Parameters
bufData buffer to write to.
byteOrderApplicable byte order (little or big endian).
Returns
Number of bytes written.

Implemented in Exiv2::TimeValue, Exiv2::DateValue, Exiv2::XmpValue, Exiv2::StringValueBase, Exiv2::DataValue, Exiv2::ValueType< T >, and Exiv2::CommentValue.

◆ create()

static UniquePtr Exiv2::Value::create ( TypeId  typeId)
static

A (simple) factory to create a Value type.

The following Value subclasses are created depending on typeId:

typeIdValue subclass
invalidTypeIdDataValue(invalidTypeId)
unsignedByteDataValue(unsignedByte)
asciiStringAsciiValue
stringStringValue
unsignedShortValueType < uint16_t >
unsignedLongValueType < uint32_t >
unsignedRationalValueType < URational >
invalid6DataValue(invalid6)
undefinedDataValue
signedShortValueType < int16_t >
signedLongValueType < int32_t >
signedRationalValueType < Rational >
tiffFloatValueType < float >
tiffDoubleValueType < double >
tiffIfdValueType < uint32_t >
dateDateValue
timeTimeValue
commentCommentValue
xmpTextXmpTextValue
xmpBagXmpArrayValue
xmpSeqXmpArrayValue
xmpAltXmpArrayValue
langAltLangAltValue
defaultDataValue(typeId)
Parameters
typeIdType of the value.
Returns
Auto-pointer to the newly created Value. The caller owns this copy and the auto-pointer ensures that it will be deleted.
Examples
addmoddel.cpp, and xmpsample.cpp.

◆ dataArea()

virtual DataBuf Exiv2::Value::dataArea ( ) const
virtual

Return a copy of the data area if the value has one. The caller owns this copy and DataBuf ensures that it will be deleted.

Values may have a data area, which can contain additional information besides the actual value. This method is used to access such a data area.

Returns
A DataBuf containing a copy of the data area or an empty DataBuf if the value does not have a data area assigned.

Reimplemented in Exiv2::ValueType< T >.

◆ read() [1/2]

virtual int Exiv2::Value::read ( const byte buf,
size_t  len,
ByteOrder  byteOrder 
)
pure virtual

Read the value from a character buffer.

Parameters
bufPointer to the data buffer to read from
lenNumber of bytes in the data buffer
byteOrderApplicable byte order (little or big endian).
Returns
0 if successful.

Implemented in Exiv2::TimeValue, Exiv2::DateValue, Exiv2::XmpValue, Exiv2::StringValueBase, Exiv2::DataValue, Exiv2::ValueType< T >, and Exiv2::CommentValue.

◆ read() [2/2]

virtual int Exiv2::Value::read ( const std::string &  buf)
pure virtual

Set the value from a string buffer. The format of the string corresponds to that of the write() method, i.e., a string obtained through the write() method can be read by this function.

Parameters
bufThe string to read from.
Returns
0 if successful.

Implemented in Exiv2::CommentValue, Exiv2::XmpValue, Exiv2::ValueType< T >, Exiv2::TimeValue, Exiv2::DateValue, Exiv2::LangAltValue, Exiv2::XmpArrayValue, Exiv2::XmpTextValue, Exiv2::AsciiValue, Exiv2::StringValueBase, and Exiv2::DataValue.

◆ setDataArea()

virtual int Exiv2::Value::setDataArea ( const byte buf,
size_t  len 
)
virtual

Set the data area, if the value has one by copying (cloning) the buffer pointed to by buf.

Values may have a data area, which can contain additional information besides the actual value. This method is used to set such a data area.

Parameters
bufPointer to the source data area
lenSize of the data area
Returns
Return -1 if the value has no data area, else 0.

Reimplemented in Exiv2::ValueType< T >.

◆ toFloat()

virtual float Exiv2::Value::toFloat ( size_t  n = 0) const
pure virtual

Convert the n-th component of the value to a float. The behaviour of this method may be undefined if there is no n-th component.

Returns
The converted value.

Implemented in Exiv2::ValueType< T >, Exiv2::TimeValue, Exiv2::DateValue, Exiv2::LangAltValue, Exiv2::XmpArrayValue, Exiv2::XmpTextValue, Exiv2::StringValueBase, Exiv2::DataValue, Exiv2::ValueType< T >, and Exiv2::ValueType< T >.

Examples
xmpsample.cpp.

◆ toInt64()

virtual int64_t Exiv2::Value::toInt64 ( size_t  n = 0) const
pure virtual

Convert the n-th component of the value to an int64_t. The behaviour of this method may be undefined if there is no n-th component.

Returns
The converted value.

Implemented in Exiv2::ValueType< T >, Exiv2::TimeValue, Exiv2::DateValue, Exiv2::LangAltValue, Exiv2::XmpArrayValue, Exiv2::XmpTextValue, Exiv2::StringValueBase, Exiv2::DataValue, Exiv2::ValueType< T >, Exiv2::ValueType< T >, Exiv2::ValueType< T >, and Exiv2::ValueType< T >.

Examples
xmpsample.cpp.

◆ toRational()

virtual Rational Exiv2::Value::toRational ( size_t  n = 0) const
pure virtual

Convert the n-th component of the value to a Rational. The behaviour of this method may be undefined if there is no n-th component.

Returns
The converted value.

Implemented in Exiv2::ValueType< T >, Exiv2::TimeValue, Exiv2::DateValue, Exiv2::LangAltValue, Exiv2::XmpArrayValue, Exiv2::XmpTextValue, Exiv2::StringValueBase, Exiv2::DataValue, Exiv2::ValueType< T >, Exiv2::ValueType< T >, Exiv2::ValueType< T >, and Exiv2::ValueType< T >.

Examples
xmpsample.cpp.

◆ toUint32()

virtual uint32_t Exiv2::Value::toUint32 ( size_t  n = 0) const
pure virtual

Convert the n-th component of the value to a float. The behaviour of this method may be undefined if there is no n-th component.

Returns
The converted value.

Implemented in Exiv2::ValueType< T >, Exiv2::TimeValue, Exiv2::DateValue, Exiv2::LangAltValue, Exiv2::XmpArrayValue, Exiv2::XmpTextValue, Exiv2::StringValueBase, Exiv2::DataValue, Exiv2::ValueType< T >, Exiv2::ValueType< T >, Exiv2::ValueType< T >, and Exiv2::ValueType< T >.


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