diff --git a/src/exif.cpp b/src/exif.cpp index 619659b2..71f79b46 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -19,13 +19,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* + File: exif.cpp + Version: $Name: $ $Revision: 1.10 $ Author(s): Andreas Huggel (ahu) - History: - 13-Jan-04, ahu: created - - RCS information - $Name: $ - $Revision: 1.9 $ + History: 26-Jan-04, ahu: created */ // ***************************************************************************** // included header files @@ -224,6 +221,13 @@ namespace Exif { return value; } // Value::create + std::string Value::toString() const + { + std::ostringstream os; + write(os); + return os.str(); + } + void DataValue::read(const char* buf, long len, ByteOrder byteOrder) { // byteOrder not needed diff --git a/src/exif.hpp b/src/exif.hpp index c7a0051c..e4fd0f4a 100644 --- a/src/exif.hpp +++ b/src/exif.hpp @@ -21,7 +21,7 @@ /*! @file exif.hpp @brief Encoding and decoding of %Exif data - @version $Name: $ $Revision: 1.10 $ + @version $Name: $ $Revision: 1.11 $ @author Andreas Huggel (ahu) ahuggel@gmx.net @date 09-Jan-04, ahu: created @@ -228,6 +228,8 @@ namespace Exif { @return The converted value. */ virtual long toLong(long n =0) const =0; + //! Return the value as a string + std::string toString() const; //! Return the type identifier (Exif data format type). TypeId typeId() const { return TypeId(type_); } @@ -235,6 +237,23 @@ namespace Exif { /*! @brief A (simple) factory to create a Value type. + The following Value subclasses are created depending on typeId:

+ + + + + + + + + + + + + + +
typeId%Value subclass
invalid%DataValue(invalid)
unsignedByte%DataValue(unsignedByte)
asciiString%AsciiValue
unsignedShort%ValueType < uint16 >
unsignedLong%ValueType < uint32 >
unsignedRational%ValueType < URational >
invalid6%DataValue(invalid6)
undefined%DataValue
signedShort%ValueType < int16 >
signedLong%ValueType < int32 >
signedRational%ValueType < Rational >
default:%DataValue(typeId)
+ @param typeId Type of the value. @return Pointer to the newly created Value. The caller owns this copy and is responsible to delete it! @@ -429,6 +448,18 @@ namespace Exif { not have a value yet, then an AsciiValue is created. */ void setValue(const std::string& buf); + /*! + @brief Return a pointer to a copy (clone) of the value. The caller + is responsible to delete this copy when it's no longer needed. + + This method is provided for users who need full control over the + value. A caller may, e.g., downcast the pointer to the appropriate + subclass of Value to make use of the interface of the subclass to set + or modify its contents. + + @return A pointer to a copy (clone) of the value. + */ + Value* getValue() const { return value_->clone(); } //! Return the name of the tag const char* tagName() const { return ExifTags::tagName(tag_, ifdId_); } //! Return the name of the type @@ -459,6 +490,9 @@ namespace Exif { */ long toLong(long n =0) const { return value_ == 0 ? -1 : value_->toLong(n); } + //! Return the value as a string. + std::string toString() const + { return value_ == 0 ? "" : value_->toString(); } //! Return the IFD id IfdId ifdId() const { return ifdId_; } //! Return the position in the IFD (-1: not set) @@ -466,18 +500,19 @@ namespace Exif { /*! @brief Return a constant reference to the value. - This method is provided mostly for convenient and versatile output - of the value, for example + This method is provided mostly for convenient and versatile output of + the value which can (to some extent) be formatted through standard + stream manipulators. Do not attempt to write to the value through + this reference. The behaviour of the method is undefined if value is + not set. + Example:
@code ExifData::const_iterator i = exifData.findKey(key); if (i != exifData.end()) { std::cout << i->key() << " " << std::hex << i->value() << "\n"; } @endcode - - Do not attempt to write to the value through this reference. - The behaviour of the method is undefined if value is not set. */ const Value& value() const { return *value_; } /*!