Loading...
Searching...
No Matches
Exiv2::CommentValue Class Reference

Value for an Exif comment. More...

`#include <value.hpp>`

Inheritance diagram for Exiv2::CommentValue:
[legend]

## Classes

class | CharsetInfo
| Charset information lookup functions. Implemented as a static class. More...
struct | CharsetTable
| Information pertaining to the defined character sets. More...

## Public Types

enum | CharsetId { ascii , jis , unicode , undefined , invalidCharsetId , lastCharsetId }
| Character set identifiers for the character sets defined by Exif.
using | UniquePtr = std::unique_ptr< CommentValue >
| Shortcut for a CommentValue auto pointer.
Public Types inherited from Exiv2::StringValueBase
using | UniquePtr = std::unique_ptr< StringValueBase >
| Shortcut for a StringValueBase auto pointer.
Public Types inherited from Exiv2::Value
using | UniquePtr = std::unique_ptr< Value >
| Shortcut for a Value auto pointer.

## Public Member Functions

Creators
| CommentValue ()
| Default constructor.
| CommentValue (const std::string &comment)
| Constructor, uses read(const std::string& comment)
Manipulators
int | read (const std::string &comment) override
| Read the value from a comment.
int | read (const byte *buf, size_t len, ByteOrder byteOrder) override
| Read the value from a character buffer.
Public Member Functions inherited from Exiv2::StringValueBase
| StringValueBase (TypeId typeId, const std::string &buf)
| Constructor for subclasses.
int | read (const std::string &buf) override
| Read the value from buf. This default implementation uses buf as it is.
int | read (const byte *buf, size_t len, ByteOrder byteOrder=invalidByteOrder) override
| Read the value from a character buffer.
UniquePtr | clone () const
size_t | copy (byte *buf, ByteOrder byteOrder=invalidByteOrder) const override
| Write value to a character data buffer.
size_t | count () const override
| Return the number of components of the value.
size_t | size () const override
| Return the size of the value in bytes.
int64_t | toInt64 (size_t n=0) const override
| 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.
uint32_t | toUint32 (size_t n=0) const override
| 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.
float | toFloat (size_t n=0) const override
| 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.
Rational | toRational (size_t n=0) const override
| 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.
std::ostream & | write (std::ostream &os) const override
| 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).
Public Member Functions inherited from Exiv2::Value
| Value (TypeId typeId)
| Constructor, taking a type id to initialize the base class with.
virtual | ~Value ()=default
| Virtual destructor.
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.
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.
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 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.
bool | ok () const
| Check the ok status indicator. After a to<Type> conversion, this indicator shows whether the conversion was successful.

## Accessors

ByteOrder | byteOrder_ {littleEndian}
| Byte order of the comment string that was read.
UniquePtr | clone () const
size_t | copy (byte *buf, ByteOrder byteOrder) const override
| Write value to a data buffer.
std::ostream & | write (std::ostream &os) const override
| Write the comment in a format which can be read by read(const std::string& comment).
std::string | comment (const char *encoding=nullptr) const
| Return the comment (without a charset="..." prefix)
const char * | detectCharset (std::string &c) const
| Determine the character encoding that was used to encode the UNICODE comment value as an iconv(3) name.
CharsetId | charsetId () const
| Return the Exif charset id of the comment.

## Additional Inherited Members

Static Public Member Functions inherited from Exiv2::Value
static UniquePtr | create (TypeId typeId)
| A (simple) factory to create a Value type.
Public Attributes inherited from Exiv2::StringValueBase
std::string | value_
| Stores the string value.
Protected Member Functions inherited from Exiv2::StringValueBase
Protected Member Functions inherited from Exiv2::Value
| Value (const Value &)=default
Value & | operator= (const Value &)=default
| Assignment operator. Protected so that it can only be used by subclasses but not directly.
Protected Attributes inherited from Exiv2::Value
bool | ok_ {true}
| Indicates the status of the previous to<Type> conversion.

## Detailed Description

Value for an Exif comment.

This can be a plain Ascii string or a multiple byte encoded string. The comment is expected to be encoded in the character set indicated (default undefined), but this is not checked. It is left to caller to decode and encode the string to and from readable text if that is required.

## Member Function Documentation

## comment()

std::string Exiv2::CommentValue::comment | ( | const char * | encoding = `nullptr` | ) | const

Return the comment (without a charset="..." prefix)

The comment is decoded to UTF-8. For Exif UNICODE comments, the function makes an attempt to correctly determine the character encoding of the value. Alternatively, the optional encoding parameter can be used to specify it.

Parameters

  encoding | Optional argument to specify the character encoding that the comment is encoded in, as an iconv(3) name. Only used for Exif UNICODE comments.

Returns
  A string containing the comment converted to UTF-8.

References charsetId(), Exiv2::convertStringCharset(), detectCharset(), and Exiv2::StringValueBase::value_.

Referenced by Exiv2::Converter::cnvExifComment().

## copy()

size_t Exiv2::CommentValue::copy | ( | byte * | buf,
|  | ByteOrder | byteOrder
| ) |  | const

override 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

  buf | Data buffer to write to.
  byteOrder | Applicable byte order (little or big endian).

Returns
  Number of bytes written.

Implements Exiv2::Value.

References byteOrder_, charsetId(), Exiv2::convertStringCharset(), and Exiv2::StringValueBase::value_.

## detectCharset()

const char * Exiv2::CommentValue::detectCharset | ( | std::string & | c | ) | const

Determine the character encoding that was used to encode the UNICODE comment value as an iconv(3) name.

If the comment c starts with a BOM, the BOM is interpreted and removed from the string.

Todo: Implement rules to guess if the comment is UTF-8 encoded.

References byteOrder_.

Referenced by comment().

## read() [1/2]

int Exiv2::CommentValue::read | ( | const byte * | buf,
|  | size_t | len,
|  | ByteOrder | byteOrder
| ) |  |

override virtual

Read the value from a character buffer.

Parameters

  buf | Pointer to the data buffer to read from
  len | Number of bytes in the data buffer
  byteOrder | Applicable byte order (little or big endian).

Returns
  0 if successful.

Implements Exiv2::Value.

References byteOrder_, and Exiv2::StringValueBase::read().

## read() [2/2]

int Exiv2::CommentValue::read | ( | const std::string & | comment | ) |

override virtual

Read the value from a comment.

The format of comment is:
`[charset=["]Ascii|Jis|Unicode|Undefined["] ]comment`
The default charset is Undefined.

Returns
  0 if successful
  1 if an invalid character set is encountered

Implements Exiv2::Value.

References byteOrder_, charsetId(), Exiv2::CommentValue::CharsetInfo::charsetIdByName(), Exiv2::CommentValue::CharsetInfo::code(), Exiv2::comment, Exiv2::convertStringCharset(), and EXV_WARNING.

Referenced by CommentValue().

## write()

std::ostream & Exiv2::CommentValue::write | ( | std::ostream & | os | ) | const

override virtual

Write the comment in a format which can be read by read(const std::string& comment).

Implements Exiv2::Value.

References charsetId(), Exiv2::comment, and Exiv2::CommentValue::CharsetInfo::name().

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

- value.hpp
- value.cpp