diff --git a/src/exif.cpp b/src/exif.cpp index ca45b79c..121a24de 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -111,6 +111,11 @@ namespace Exiv2 { if (rhs.value_.get() != 0) value_ = rhs.value_->clone(); // deep copy } + std::ostream& Exifdatum::write(std::ostream& os) const + { + return ExifTags::printTag(os, tag(), ifdId(), value()); + } + const Value& Exifdatum::value() const { if (value_.get() == 0) throw Error(8); @@ -1281,10 +1286,6 @@ namespace Exiv2 { makerNote->add(e); } // addToMakerNote - std::ostream& operator<<(std::ostream& os, const Exifdatum& md) - { - return ExifTags::printTag(os, md.tag(), md.ifdId(), md.value()); - } } // namespace Exiv2 // ***************************************************************************** diff --git a/src/exif.hpp b/src/exif.hpp index 1f348c8f..dee57ab9 100644 --- a/src/exif.hpp +++ b/src/exif.hpp @@ -66,7 +66,6 @@ namespace Exiv2 { an ExifKey and a Value and provides methods to manipulate these. */ class Exifdatum : public Metadatum { - friend std::ostream& operator<<(std::ostream&, const Exifdatum&); template friend Exifdatum& setValue(Exifdatum&, const T&); public: //! @name Creators @@ -202,6 +201,7 @@ namespace Exiv2 { */ long copy(byte* buf, ByteOrder byteOrder) const { return value_.get() == 0 ? 0 : value_->copy(buf, byteOrder); } + std::ostream& write(std::ostream& os) const; //! Return the type id of the value TypeId typeId() const { return value_.get() == 0 ? invalidTypeId : value_->typeId(); } @@ -257,12 +257,6 @@ namespace Exiv2 { }; // class Exifdatum - /*! - @brief Output operator for Exifdatum types, prints the interpreted - tag value. - */ - std::ostream& operator<<(std::ostream& os, const Exifdatum& md); - /*! @brief Set the value of \em exifDatum to \em value. If the object already has a value, it is replaced. Otherwise a new ValueType\ value diff --git a/src/iptc.cpp b/src/iptc.cpp index 247af917..3d880cb2 100644 --- a/src/iptc.cpp +++ b/src/iptc.cpp @@ -63,6 +63,11 @@ namespace Exiv2 { { } + std::ostream& Iptcdatum::write(std::ostream& os) const + { + return os << value(); + } + const Value& Iptcdatum::value() const { if (value_.get() == 0) throw Error(8); @@ -323,11 +328,4 @@ namespace Exiv2 { return iptcMetadata_.erase(pos); } - // ************************************************************************* - // free functions - std::ostream& operator<<(std::ostream& os, const Iptcdatum& md) - { - return os << md.value(); - } - } // namespace Exiv2 diff --git a/src/iptc.hpp b/src/iptc.hpp index d9129469..35ea2de8 100644 --- a/src/iptc.hpp +++ b/src/iptc.hpp @@ -111,6 +111,7 @@ namespace Exiv2 { //@{ long copy(byte* buf, ByteOrder byteOrder) const { return value_.get() == 0 ? 0 : value_->copy(buf, byteOrder); } + std::ostream& write(std::ostream& os) const; /*! @brief Return the key of the Iptcdatum. The key is of the form 'Iptc.recordName.datasetName'. Note however that the key @@ -169,12 +170,6 @@ namespace Exiv2 { }; // class Iptcdatum - /*! - @brief Output operator for Iptcdatum types, printing the interpreted - tag value. - */ - std::ostream& operator<<(std::ostream& os, const Iptcdatum& md); - //! Container type to hold all metadata typedef std::vector IptcMetadata; diff --git a/src/metadatum.cpp b/src/metadatum.cpp index 3155a589..b0e070de 100644 --- a/src/metadatum.cpp +++ b/src/metadatum.cpp @@ -70,17 +70,11 @@ namespace Exiv2 { return *this; } - std::ostream& operator<<(std::ostream& os, const Metadatum& md) + std::string Metadatum::print() const { - os << "0x" << std::setw(4) << std::setfill('0') << std::right - << std::hex << md.tag() << " " - << std::setw(40) << std::setfill(' ') << std::left - << md.key() << " " - << std::setw(9) << std::setfill(' ') << std::left - << md.typeName() << " " - << std::dec << md.value() - << "\n"; - return os; + std::ostringstream os; + write(os); + return os.str(); } bool cmpMetadataByTag(const Metadatum& lhs, const Metadatum& rhs) diff --git a/src/metadatum.hpp b/src/metadatum.hpp index 2079b52d..b9423d37 100644 --- a/src/metadatum.hpp +++ b/src/metadatum.hpp @@ -154,6 +154,12 @@ namespace Exiv2 { //! @name Accessors //@{ + /*! + @brief Write the interpreted value to a string. + + Implemented in terms of std::ostream& write(std::ostream& os). + */ + std::string print() const; /*! @brief Write value to a data buffer and return the number of bytes written. @@ -166,6 +172,17 @@ namespace Exiv2 { @return Number of characters written. */ virtual long copy(byte* buf, ByteOrder byteOrder) const =0; + /*! + @brief Write the interpreted value to an output stream, return + the stream. + + You do not usually have to use this function; it is used for the + implementation of the output operator for %Metadatum, + operator<<(std::ostream &os, const Metadatum &md). See also + std::string print() const, which prints the interpreted value + to a string. + */ + virtual std::ostream& write(std::ostream& os) const =0; /*! @brief Return the key of the metadatum. The key is of the form 'familyName.ifdItem.tagName'. Note however that the key @@ -280,12 +297,15 @@ namespace Exiv2 { }; // class FindMetadatumByTag - /*! - @brief Output operator for Metadatum types, printing the interpreted + @brief Output operator for Metadatum types, writing the interpreted tag value. */ - std::ostream& operator<<(std::ostream& os, const Metadatum& md); + inline std::ostream& operator<<(std::ostream& os, const Metadatum& md) + { + return md.write(os); + } + /*! @brief Compare two metadata by tag. Return true if the tag of metadatum lhs is less than that of rhs. diff --git a/src/xmp.cpp b/src/xmp.cpp index 6898d78b..941491e9 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -246,6 +246,11 @@ namespace Exiv2 { return 0; } + std::ostream& Xmpdatum::write(std::ostream& os) const + { + return XmpProperties::printProperty(os, key(), value()); + } + Xmpdatum& Xmpdatum::operator=(const std::string& value) { setValue(value); @@ -665,14 +670,6 @@ namespace Exiv2 { } // XmpParser::encode #endif // !EXV_HAVE_XMP_TOOLKIT - // ************************************************************************* - // free functions - - std::ostream& operator<<(std::ostream& os, const Xmpdatum& md) - { - return XmpProperties::printProperty(os, md.key(), md.value()); - } - } // namespace Exiv2 // ***************************************************************************** diff --git a/src/xmp.hpp b/src/xmp.hpp index 0cbc630c..82857d2f 100644 --- a/src/xmp.hpp +++ b/src/xmp.hpp @@ -120,6 +120,7 @@ namespace Exiv2 { //@{ //! Not implemented. Calling this method will raise an exception. long copy(byte* buf, ByteOrder byteOrder) const; + std::ostream& write(std::ostream& os) const; /*! @brief Return the key of the Xmpdatum. The key is of the form 'Xmp.prefix.property'. Note however that the @@ -157,12 +158,6 @@ namespace Exiv2 { }; // class Xmpdatum - /*! - @brief Output operator for Xmpdatum types, printing the interpreted - tag value. - */ - std::ostream& operator<<(std::ostream& os, const Xmpdatum& md); - //! Container type to hold all metadata typedef std::vector XmpMetadata;