Refactored op<< for Metadatum, introduced std::string Metadatum::print(). Fixes #474.

v0.27.3
Andreas Huggel 18 years ago
parent 9f0b41c57d
commit d8e6b51c69

@ -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
// *****************************************************************************

@ -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<typename T> 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\<T\> value

@ -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

@ -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
'<b>Iptc</b>.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<Iptcdatum> IptcMetadata;

@ -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)

@ -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.

@ -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
// *****************************************************************************

@ -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
'<b>Xmp</b>.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<Xmpdatum> XmpMetadata;

Loading…
Cancel
Save