Changed operator hack to be more consistent, added op=(const Value&)

v0.27.3
Andreas Huggel 21 years ago
parent 0fc84a1a80
commit c8d9fe0b35

@ -155,6 +155,12 @@ namespace Exiv2 {
return Exiv2::setValue(*this, value); return Exiv2::setValue(*this, value);
} }
Exifdatum& Exifdatum::operator=(const Value& value)
{
setValue(&value);
return *this;
}
void Exifdatum::setValue(const Value* pValue) void Exifdatum::setValue(const Value* pValue)
{ {
value_.reset(); value_.reset();
@ -168,10 +174,10 @@ namespace Exiv2 {
value_->setDataArea(e.dataArea(), e.sizeDataArea()); value_->setDataArea(e.dataArea(), e.sizeDataArea());
} }
void Exifdatum::setValue(const std::string& buf) void Exifdatum::setValue(const std::string& value)
{ {
if (value_.get() == 0) value_ = Value::create(asciiString); if (value_.get() == 0) value_ = Value::create(asciiString);
value_->read(buf); value_->read(value);
} }
int TiffThumbnail::setDataArea(ExifData& exifData, Ifd& ifd1, int TiffThumbnail::setDataArea(ExifData& exifData, Ifd& ifd1,

@ -62,7 +62,8 @@ namespace Exiv2 {
// class definitions // class definitions
/*! /*!
@brief Information related to one Exif tag. @brief Information related to one Exif tag. An Exif metadatum consists of
an ExifKey and a Value and provides methods to manipulate these.
*/ */
class Exifdatum : public Metadatum { class Exifdatum : public Metadatum {
friend std::ostream& operator<<(std::ostream&, const Exifdatum&); friend std::ostream& operator<<(std::ostream&, const Exifdatum&);
@ -95,62 +96,60 @@ namespace Exiv2 {
//! Assignment operator //! Assignment operator
Exifdatum& operator=(const Exifdatum& rhs); Exifdatum& operator=(const Exifdatum& rhs);
/*! /*!
@brief Assign \em value to the %Exifdatum. If the object already has a @brief Assign \em value to the %Exifdatum. The type of the new Value
value, it is replaced with \em value. Otherwise a new is set to UShortValue.
AsciiValue value is created and set to \em value.
*/
Exifdatum& operator=(const std::string& value);
/*!
@brief Assign \em value to the %Exifdatum. If the object already has a
value, it is replaced with \em value. Otherwise a new
UShortValue value is created and set to \em value.
*/ */
Exifdatum& operator=(const uint16_t& value); Exifdatum& operator=(const uint16_t& value);
/*! /*!
@brief Assign \em value to the %Exifdatum. If the object already has a @brief Assign \em value to the %Exifdatum. The type of the new Value
value, it is replaced with \em value. Otherwise a new is set to ULongValue.
ULongValue value is created and set to \em value.
*/ */
Exifdatum& operator=(const uint32_t& value); Exifdatum& operator=(const uint32_t& value);
/*! /*!
@brief Assign \em value to the %Exifdatum. If the object already has a @brief Assign \em value to the %Exifdatum. The type of the new Value
value, it is replaced with \em value. Otherwise a new is set to URationalValue.
URational value is created and set to \em value.
*/ */
Exifdatum& operator=(const URational& value); Exifdatum& operator=(const URational& value);
/*! /*!
@brief Assign \em value to the %Exifdatum. If the object already has a @brief Assign \em value to the %Exifdatum. The type of the new Value
value, it is replaced with \em value. Otherwise a new is set to ShortValue.
ShortValue value is created and set to \em value.
*/ */
Exifdatum& operator=(const int16_t& value); Exifdatum& operator=(const int16_t& value);
/*! /*!
@brief Assign \em value to the %Exifdatum. If the object already has a @brief Assign \em value to the %Exifdatum. The type of the new Value
value, it is replaced with \em value. Otherwise a new is set to LongValue.
LongValue value is created and set to \em value.
*/ */
Exifdatum& operator=(const int32_t& value); Exifdatum& operator=(const int32_t& value);
/*! /*!
@brief Assign \em value to the %Exifdatum. If the object already has a @brief Assign \em value to the %Exifdatum. The type of the new Value
value, it is replaced with \em value. Otherwise a new is set to RationalValue.
Rational value is created and set to \em value.
*/ */
Exifdatum& operator=(const Rational& value); Exifdatum& operator=(const Rational& value);
/*!
@brief Assign \em value to the %Exifdatum.
Calls setValue(const std::string&).
*/
Exifdatum& operator=(const std::string& value);
/*!
@brief Assign \em value to the %Exifdatum.
Calls setValue(const Value*).
*/
Exifdatum& operator=(const Value& value);
/*! /*!
@brief Set the value. This method copies (clones) the value pointed @brief Set the value. This method copies (clones) the value pointed
to by \em pValue. to by \em pValue.
*/ */
void setValue(const Value* pValue); void setValue(const Value* pValue);
/*! /*!
@brief Set the value from an IFD entry. @brief Set the value to the string \em value.
Uses Value::read(const std::string&). If the %Exifdatum
does not have a value yet, then an AsciiValue is created.
*/ */
void setValue(const Entry& e, ByteOrder byteOrder); void setValue(const std::string& value);
/*! /*!
@brief Set the value to the string \em buf. @brief Set the value from an IFD entry.
Uses Value::read(const std::string& buf). If the %Exifdatum does
not have a value yet, then an AsciiValue is created.
*/ */
void setValue(const std::string& buf); void setValue(const Entry& e, ByteOrder byteOrder);
/*! /*!
@brief Set the data area by copying (cloning) the buffer pointed to @brief Set the data area by copying (cloning) the buffer pointed to
by \em buf. by \em buf.
@ -897,15 +896,10 @@ namespace Exiv2 {
template<typename T> template<typename T>
Exifdatum& setValue(Exifdatum& exifDatum, const T& value) Exifdatum& setValue(Exifdatum& exifDatum, const T& value)
{ {
if (exifDatum.value_.get() == 0) { std::auto_ptr<ValueType<T> > v
std::auto_ptr<ValueType<T> > v = std::auto_ptr<ValueType<T> >(new ValueType<T>);
= std::auto_ptr<ValueType<T> >(new ValueType<T>); v->value_.push_back(value);
v->value_.push_back(value); exifDatum.value_ = v;
exifDatum.value_ = v;
}
else {
exifDatum.value_->read(Exiv2::toString(value));
}
return exifDatum; return exifDatum;
} }
/*! /*!

@ -96,6 +96,12 @@ namespace Exiv2 {
return *this; return *this;
} }
Iptcdatum& Iptcdatum::operator=(const Value& value)
{
setValue(&value);
return *this;
}
void Iptcdatum::setValue(const Value* pValue) void Iptcdatum::setValue(const Value* pValue)
{ {
modified_ = true; modified_ = true;
@ -103,19 +109,13 @@ namespace Exiv2 {
if (pValue) value_ = pValue->clone(); if (pValue) value_ = pValue->clone();
} }
void Iptcdatum::setValue(const std::string& buf) void Iptcdatum::setValue(const std::string& value)
{ {
Value::AutoPtr value; if (value_.get() == 0) {
try {
TypeId type = IptcDataSets::dataSetType(tag(), record()); TypeId type = IptcDataSets::dataSetType(tag(), record());
value = Value::create(type); value_ = Value::create(type);
}
catch (const Error&) {
// Default to a StringValue if the type is unknown or the parse fails
value = Value::create(string);
} }
value->read(buf); value_->read(value);
value_ = value;
modified_ = true; modified_ = true;
} }
@ -213,18 +213,9 @@ namespace Exiv2 {
const byte* data, uint32_t sizeData) const byte* data, uint32_t sizeData)
{ {
Value::AutoPtr value; Value::AutoPtr value;
try { TypeId type = IptcDataSets::dataSetType(dataSet, record);
// If the type is unknown or the parse fails then value = Value::create(type);
// default to undefined type below. value->read(data, sizeData, bigEndian);
TypeId type = IptcDataSets::dataSetType(dataSet, record);
value = Value::create(type);
value->read(data, sizeData, bigEndian);
}
catch (const Error&) {
// Default to loading as raw bytes
value = Value::create(undefined);
value->read(data, sizeData, bigEndian);
}
IptcKey key(dataSet, record); IptcKey key(dataSet, record);
add(key, value.get()); add(key, value.get());
return 0; return 0;

@ -49,7 +49,8 @@ namespace Exiv2 {
// class definitions // class definitions
/*! /*!
@brief Information related to one Iptc dataset. @brief Information related to one Iptc dataset. An Iptc metadatum consists
of an IptcKey and a Value and provides methods to manipulate these.
*/ */
class Iptcdatum : public Metadatum { class Iptcdatum : public Metadatum {
public: public:
@ -80,28 +81,34 @@ namespace Exiv2 {
//! Assignment operator //! Assignment operator
Iptcdatum& operator=(const Iptcdatum& rhs); Iptcdatum& operator=(const Iptcdatum& rhs);
/*! /*!
@brief Assign \em value to the %Iptcdatum. The type of the new value @brief Assign \em value to the %Iptcdatum. The type of the new Value
is determined from %Iptcdatum. If that fails, a StringValue is is set to UShortValue.
used. Calls setValue(const std::string&). */
Iptcdatum& operator=(const uint16_t& value);
/*!
@brief Assign \em value to the %Iptcdatum.
Calls setValue(const std::string&).
*/ */
Iptcdatum& operator=(const std::string& value); Iptcdatum& operator=(const std::string& value);
/*! /*!
@brief Assign \em value to the %Iptcdatum. The type of the new value @brief Assign \em value to the %Iptcdatum.
is set to UShortValue. Calls setValue(const Value*).
*/ */
Iptcdatum& operator=(const uint16_t& value); Iptcdatum& operator=(const Value& value);
/*! /*!
@brief Set the value. This method copies (clones) the value pointed @brief Set the Value. This method copies (clones) the %Value pointed
to by pValue. to by \em pValue.
*/ */
void setValue(const Value* pValue); void setValue(const Value* pValue);
/*! /*!
@brief Set the value to the string buf. Uses Value::read(const @brief Set the value to the string \em value, using
std::string& buf). If the %Iptcdatum does not have a value yet, Value::read(const std::string&).
then a value of the correct type for this %Iptcdatum is If the %Iptcdatum does not have a Value yet, then a %Value of
created. If that fails, a StringValue is created. the correct type for this %Iptcdatum is created. If that
fails (because of an unknown dataset), a StringValue is
created.
*/ */
void setValue(const std::string& buf); void setValue(const std::string& value);
//@} //@}
//! @name Accessors //! @name Accessors

@ -10,7 +10,6 @@ void printIptc(const Exiv2::IptcData& iptcData);
int main() int main()
try { try {
Exiv2::IptcData iptcData; Exiv2::IptcData iptcData;
iptcData["Iptc.Application2.Headline"] = "The headline I am"; iptcData["Iptc.Application2.Headline"] = "The headline I am";
@ -21,6 +20,11 @@ try {
iptcData["Iptc.Envelope.ModelVersion"] = 2; iptcData["Iptc.Envelope.ModelVersion"] = 2;
iptcData["Iptc.Envelope.TimeSent"] = "14:41:0-05:00"; iptcData["Iptc.Envelope.TimeSent"] = "14:41:0-05:00";
iptcData["Iptc.Application2.RasterizedCaption"] = "230 42 34 2 90 84 23 146"; iptcData["Iptc.Application2.RasterizedCaption"] = "230 42 34 2 90 84 23 146";
iptcData["Iptc.0x0009.0x0001"] = "Who am I?";
Exiv2::StringValue value;
value.read("Hi there!");
iptcData["Iptc.Envelope.ModelVersion"] = value;
std::cout << "Time sent: " << iptcData["Iptc.Envelope.TimeSent"] << "\n\n"; std::cout << "Time sent: " << iptcData["Iptc.Envelope.TimeSent"] << "\n\n";

Loading…
Cancel
Save