Generalized Xmpdatum::operator=.
This commit is contained in:
parent
dbe900dde7
commit
ce170e093b
@ -246,14 +246,6 @@ namespace Exiv2 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Xmpdatum& Xmpdatum::operator=(const uint16_t& value)
|
||||
{
|
||||
XmpTextValue::AutoPtr v(new XmpTextValue);
|
||||
v->read(toString(value));
|
||||
p_->value_ = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Xmpdatum& Xmpdatum::operator=(const std::string& value)
|
||||
{
|
||||
setValue(value);
|
||||
|
||||
45
src/xmp.hpp
45
src/xmp.hpp
@ -80,17 +80,28 @@ namespace Exiv2 {
|
||||
//! Assignment operator
|
||||
Xmpdatum& operator=(const Xmpdatum& rhs);
|
||||
/*!
|
||||
@brief Assign \em value to the %Xmpdatum. The type of the new Value
|
||||
is set to XmpTextValue.
|
||||
*/
|
||||
Xmpdatum& operator=(const uint16_t& value);
|
||||
/*!
|
||||
@brief Assign \em value to the %Xmpdatum.
|
||||
@brief Assign std::string \em value to the %Xmpdatum.
|
||||
Calls setValue(const std::string&).
|
||||
*/
|
||||
Xmpdatum& operator=(const std::string& value);
|
||||
/*!
|
||||
@brief Assign \em value to the %Xmpdatum.
|
||||
@brief Assign const char* \em value to the %Xmpdatum.
|
||||
Calls operator=(const std::string&).
|
||||
*/
|
||||
Xmpdatum& operator=(const char* value);
|
||||
/*!
|
||||
@brief Assign a boolean \em value to the %Xmpdatum.
|
||||
Translates the value to a string "true" or "false".
|
||||
*/
|
||||
Xmpdatum& operator=(const bool& value);
|
||||
/*!
|
||||
@brief Assign a \em value of any type with an output operator
|
||||
to the %Xmpdatum. Calls operator=(const std::string&).
|
||||
*/
|
||||
template<typename T>
|
||||
Xmpdatum& operator=(const T& value);
|
||||
/*!
|
||||
@brief Assign Value \em value to the %Xmpdatum.
|
||||
Calls setValue(const Value*).
|
||||
*/
|
||||
Xmpdatum& operator=(const Value& value);
|
||||
@ -311,6 +322,26 @@ namespace Exiv2 {
|
||||
|
||||
}; // class XmpParser
|
||||
|
||||
// *****************************************************************************
|
||||
// free functions, template and inline definitions
|
||||
|
||||
inline Xmpdatum& Xmpdatum::operator=(const char* value)
|
||||
{
|
||||
return Xmpdatum::operator=(std::string(value));
|
||||
}
|
||||
|
||||
inline Xmpdatum& Xmpdatum::operator=(const bool& value)
|
||||
{
|
||||
return operator=(value ? "true" : "false");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Xmpdatum& Xmpdatum::operator=(const T& value)
|
||||
{
|
||||
setValue(Exiv2::toString(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace Exiv2
|
||||
|
||||
#endif // #ifndef XMP_HPP_
|
||||
|
||||
@ -15,13 +15,27 @@ try {
|
||||
Exiv2::XmpData xmpData;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Teaser: The quickest way to add simple XMP properties using Exiv2
|
||||
// Teaser: Setting XMP properties doesn't get much easier than this:
|
||||
|
||||
xmpData["Xmp.dc.source"] = "xmpsample.cpp"; // a simple text value
|
||||
xmpData["Xmp.dc.subject"] = "Palmtree"; // an array item
|
||||
xmpData["Xmp.dc.subject"] = "Rubbertree"; // add a 2nd array item
|
||||
xmpData["Xmp.dc.title"] = "lang=en-US Beach"; // a language alternative
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Any properties can be set provided the namespace is known. Values of any
|
||||
// type can be assigned to an Xmpdatum (requires an output operator). The
|
||||
// default XMP value type for unknown properties is a simple text value.
|
||||
|
||||
xmpData["Xmp.dc.one"] = -1;
|
||||
xmpData["Xmp.dc.two"] = 3.1415;
|
||||
xmpData["Xmp.dc.three"] = Exiv2::Rational(5, 7);
|
||||
xmpData["Xmp.dc.four"] = uint16_t(255);
|
||||
xmpData["Xmp.dc.five"] = int32_t(256);
|
||||
xmpData["Xmp.dc.six"] = false;
|
||||
Exiv2::XmpTextValue val("Seven");
|
||||
xmpData["Xmp.dc.seven"] = val;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Exiv2 has specialized values for simple XMP properties, arrays of simple
|
||||
// properties and language alternatives.
|
||||
@ -52,7 +66,7 @@ try {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// There are no specialized values for structures, qualifiers and nested
|
||||
// types. However, these can be added by using a XmpTextValue and a path as
|
||||
// types. However, these can be added by using an XmpTextValue and a path as
|
||||
// the key.
|
||||
|
||||
// Add a structure
|
||||
@ -74,11 +88,11 @@ try {
|
||||
xmpData.add(Exiv2::XmpKey("Xmp.dc.creator[2]/?ns:role"), &tv);
|
||||
|
||||
// Add an array of structures
|
||||
tv.read("");
|
||||
tv.read(""); // Clear the value
|
||||
tv.setXmpArrayType(Exiv2::XmpValue::xaBag);
|
||||
xmpData.add(Exiv2::XmpKey("Xmp.xmpBJ.JobRef"), &tv); // Set the array type.
|
||||
tv.setXmpArrayType(Exiv2::XmpValue::xaNone);
|
||||
|
||||
tv.setXmpArrayType(Exiv2::XmpValue::xaNone);
|
||||
tv.read("Birtday party");
|
||||
xmpData.add(Exiv2::XmpKey("Xmp.xmpBJ.JobRef[1]/stJob:name"), &tv);
|
||||
tv.read("Photographer");
|
||||
|
||||
@ -282,6 +282,13 @@ Xmp.ns1.NestedStructProp/ns2:Outer/ns2:Middle/ns2:Inner/ns2:Field2 XmpText 12
|
||||
Xmp.dc.source XmpText 13 xmpsample.cpp
|
||||
Xmp.dc.subject XmpBag 2 Palmtree, Rubbertree
|
||||
Xmp.dc.title LangAlt 1 lang="en-US" Beach
|
||||
Xmp.dc.one XmpText 2 -1
|
||||
Xmp.dc.two XmpText 6 3.1415
|
||||
Xmp.dc.three XmpText 3 5/7
|
||||
Xmp.dc.four XmpText 3 255
|
||||
Xmp.dc.five XmpText 3 256
|
||||
Xmp.dc.six XmpText 5 false
|
||||
Xmp.dc.seven XmpText 5 Seven
|
||||
Xmp.dc.format XmpText 10 image/jpeg
|
||||
Xmp.dc.creator XmpSeq 3 1) The first creator, 2) The second creator, 3) And another one
|
||||
Xmp.dc.description LangAlt 2 lang="de-DE" Hallo, Welt, lang="x-default" Hello, World
|
||||
@ -307,6 +314,13 @@ Xmp.xmpBJ.JobRef[2]/stJob:role XmpText 8 Best man
|
||||
xmlns:xapBJ="http://ns.adobe.com/xap/1.0/bj/"
|
||||
xmlns:stJob="http://ns.adobe.com/xap/1.0/sType/Job#"
|
||||
dc:source="xmpsample.cpp"
|
||||
dc:one="-1"
|
||||
dc:two="3.1415"
|
||||
dc:three="5/7"
|
||||
dc:four="255"
|
||||
dc:five="256"
|
||||
dc:six="false"
|
||||
dc:seven="Seven"
|
||||
dc:format="image/jpeg">
|
||||
<dc:subject>
|
||||
<rdf:Bag>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user