<div class="fragment"><div class="line"><span class="comment">// ***************************************************************** -*- C++ -*-</span></div>
<div class="line"><span class="comment">// xmpsample.cpp, $Rev: 3090 $</span></div>
<div class="line"><span class="comment">// Sample/test for high level XMP classes. See also addmoddel.cpp</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="doc/exiv2_8hpp.html" title="Include all Exiv2 header files.">exiv2/exiv2.hpp</a>&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iomanip&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cassert&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cmath&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">bool</span> isEqual(<span class="keywordtype">float</span> a, <span class="keywordtype">float</span> b)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordtype">double</span> d = std::fabs(a - b);</div>
<div class="line">    <span class="keywordflow">return</span> d &lt; 0.00001;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line"><span class="keyword">try</span> {</div>
<div class="line">    <span class="comment">// The XMP property container</span></div>
<div class="line">    <a name="_a0"></a><a class="code" href="doc/classExiv2_1_1XmpData.html" title="A container for XMP data. This is a top-level class of the Exiv2 library.">Exiv2::XmpData</a> xmpData;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// -------------------------------------------------------------------------</span></div>
<div class="line">    <span class="comment">// Teaser: Setting XMP properties doesn&#39;t get much easier than this:</span></div>
<div class="line"></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.source&quot;</span>]  = <span class="stringliteral">&quot;xmpsample.cpp&quot;</span>;    <span class="comment">// a simple text value</span></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.subject&quot;</span>] = <span class="stringliteral">&quot;Palmtree&quot;</span>;         <span class="comment">// an array item</span></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.subject&quot;</span>] = <span class="stringliteral">&quot;Rubbertree&quot;</span>;       <span class="comment">// add a 2nd array item</span></div>
<div class="line">    <span class="comment">// a language alternative with two entries and without default</span></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.title&quot;</span>]   = <span class="stringliteral">&quot;lang=de-DE Sonnenuntergang am Strand&quot;</span>;</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.title&quot;</span>]   = <span class="stringliteral">&quot;lang=en-US Sunset on the beach&quot;</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// -------------------------------------------------------------------------</span></div>
<div class="line">    <span class="comment">// Any properties can be set provided the namespace is known. Values of any</span></div>
<div class="line">    <span class="comment">// type can be assigned to an Xmpdatum, if they have an output operator. The</span></div>
<div class="line">    <span class="comment">// default XMP value type for unknown properties is a simple text value.</span></div>
<div class="line"></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.one&quot;</span>]     = -1;</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.two&quot;</span>]     = 3.1415;</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.three&quot;</span>]   = <a name="a1"></a><a class="code" href="doc/namespaceExiv2.html#a95756f3f7fa19103f83addf5fa088a30" title="8 byte signed rational type.">Exiv2::Rational</a>(5, 7);</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.four&quot;</span>]    = uint16_t(255);</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.five&quot;</span>]    = int32_t(256);</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.six&quot;</span>]     = <span class="keyword">false</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// In addition, there is a dedicated assignment operator for Exiv2::Value</span></div>
<div class="line">    <a name="_a2"></a><a class="code" href="doc/classExiv2_1_1XmpTextValue.html" title="Value type suitable for simple XMP properties and XMP nodes of complex types which are not parsed int...">Exiv2::XmpTextValue</a> val(<span class="stringliteral">&quot;Seven&quot;</span>);</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.seven&quot;</span>]   = val;</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.eight&quot;</span>]   = <span class="keyword">true</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Extracting values</span></div>
<div class="line">    assert(xmpData[<span class="stringliteral">&quot;Xmp.dc.one&quot;</span>].toLong() == -1);</div>
<div class="line">    assert(xmpData[<span class="stringliteral">&quot;Xmp.dc.one&quot;</span>].value().ok());</div>
<div class="line"></div>
<div class="line">    <span class="keyword">const</span> <a name="_a3"></a><a class="code" href="doc/classExiv2_1_1Value.html" title="Common interface for all types of values used with metadata.">Exiv2::Value</a> &amp;getv1 = xmpData[<span class="stringliteral">&quot;Xmp.dc.one&quot;</span>].value();</div>
<div class="line">    assert(isEqual(getv1.<a name="a4"></a><a class="code" href="doc/classExiv2_1_1Value.html#a22d257caa6c1ffe6416ce02de7bd8c1c" title="Convert the n-th component of the value to a float. The behaviour of this method may be undefined if ...">toFloat</a>(), -1)); </div>
<div class="line">    assert(getv1.<a name="a5"></a><a class="code" href="doc/classExiv2_1_1Value.html#a161550b3ef31b3a14b1d75149ba9ba71" title="Check the ok status indicator. After a to&lt;Type&gt; conversion, this indicator shows whether the conversi...">ok</a>());</div>
<div class="line">    assert(getv1.<a name="a6"></a><a class="code" href="doc/classExiv2_1_1Value.html#a595a4cb549bec8c19d290ca3e95a2678" title="Convert the n-th component of the value to a Rational. The behaviour of this method may be undefined ...">toRational</a>() == <a class="code" href="doc/namespaceExiv2.html#a95756f3f7fa19103f83addf5fa088a30" title="8 byte signed rational type.">Exiv2::Rational</a>(-1, 1));</div>
<div class="line">    assert(getv1.<a class="code" href="doc/classExiv2_1_1Value.html#a161550b3ef31b3a14b1d75149ba9ba71" title="Check the ok status indicator. After a to&lt;Type&gt; conversion, this indicator shows whether the conversi...">ok</a>());</div>
<div class="line"></div>
<div class="line">    <span class="keyword">const</span> <a class="code" href="doc/classExiv2_1_1Value.html" title="Common interface for all types of values used with metadata.">Exiv2::Value</a> &amp;getv2 = xmpData[<span class="stringliteral">&quot;Xmp.dc.two&quot;</span>].value();</div>
<div class="line">    assert(isEqual(getv2.toFloat(), 3.1415f)); </div>
<div class="line">    assert(getv2.ok());</div>
<div class="line">    assert(getv2.toLong() == 3);</div>
<div class="line">    assert(getv2.ok());</div>
<div class="line">    <a class="code" href="doc/namespaceExiv2.html#a95756f3f7fa19103f83addf5fa088a30" title="8 byte signed rational type.">Exiv2::Rational</a> R = getv2.toRational();</div>
<div class="line">    assert(getv2.ok());</div>
<div class="line">    assert(isEqual(static_cast&lt;float&gt;(R.first) / R.second, 3.1415f ));</div>
<div class="line"></div>
<div class="line">    <span class="keyword">const</span> <a class="code" href="doc/classExiv2_1_1Value.html" title="Common interface for all types of values used with metadata.">Exiv2::Value</a> &amp;getv3 = xmpData[<span class="stringliteral">&quot;Xmp.dc.three&quot;</span>].value();</div>
<div class="line">    assert(isEqual(getv3.<a class="code" href="doc/classExiv2_1_1Value.html#a22d257caa6c1ffe6416ce02de7bd8c1c" title="Convert the n-th component of the value to a float. The behaviour of this method may be undefined if ...">toFloat</a>(), 5.0f/7.0f)); </div>
<div class="line">    assert(getv3.<a class="code" href="doc/classExiv2_1_1Value.html#a161550b3ef31b3a14b1d75149ba9ba71" title="Check the ok status indicator. After a to&lt;Type&gt; conversion, this indicator shows whether the conversi...">ok</a>());</div>
<div class="line">    assert(getv3.<a name="a7"></a><a class="code" href="doc/classExiv2_1_1Value.html#a4530a3fc3e2305cf994de5476f46f953" title="Convert the n-th component of the value to a long. The behaviour of this method may be undefined if t...">toLong</a>() == 0);  <span class="comment">// long(5.0 / 7.0) </span></div>
<div class="line">    assert(getv3.<a class="code" href="doc/classExiv2_1_1Value.html#a161550b3ef31b3a14b1d75149ba9ba71" title="Check the ok status indicator. After a to&lt;Type&gt; conversion, this indicator shows whether the conversi...">ok</a>());</div>
<div class="line">    assert(getv3.<a class="code" href="doc/classExiv2_1_1Value.html#a595a4cb549bec8c19d290ca3e95a2678" title="Convert the n-th component of the value to a Rational. The behaviour of this method may be undefined ...">toRational</a>() == <a class="code" href="doc/namespaceExiv2.html#a95756f3f7fa19103f83addf5fa088a30" title="8 byte signed rational type.">Exiv2::Rational</a>(5, 7));</div>
<div class="line">    assert(getv3.<a class="code" href="doc/classExiv2_1_1Value.html#a161550b3ef31b3a14b1d75149ba9ba71" title="Check the ok status indicator. After a to&lt;Type&gt; conversion, this indicator shows whether the conversi...">ok</a>());</div>
<div class="line">    </div>
<div class="line">    <span class="keyword">const</span> <a class="code" href="doc/classExiv2_1_1Value.html" title="Common interface for all types of values used with metadata.">Exiv2::Value</a> &amp;getv6 = xmpData[<span class="stringliteral">&quot;Xmp.dc.six&quot;</span>].value();</div>
<div class="line">    assert(getv6.toLong() == 0);</div>
<div class="line">    assert(getv6.ok());</div>
<div class="line">    assert(getv6.toFloat() == 0.0);</div>
<div class="line">    assert(getv6.ok());</div>
<div class="line">    assert(getv6.toRational() == <a class="code" href="doc/namespaceExiv2.html#a95756f3f7fa19103f83addf5fa088a30" title="8 byte signed rational type.">Exiv2::Rational</a>(0, 1));</div>
<div class="line">    assert(getv6.ok());</div>
<div class="line">    </div>
<div class="line">    <span class="keyword">const</span> <a class="code" href="doc/classExiv2_1_1Value.html" title="Common interface for all types of values used with metadata.">Exiv2::Value</a> &amp;getv7 = xmpData[<span class="stringliteral">&quot;Xmp.dc.seven&quot;</span>].value();</div>
<div class="line">    getv7.toLong(); <span class="comment">// this should fail</span></div>
<div class="line">    assert(!getv7.ok()); </div>
<div class="line"></div>
<div class="line">    <span class="keyword">const</span> <a class="code" href="doc/classExiv2_1_1Value.html" title="Common interface for all types of values used with metadata.">Exiv2::Value</a> &amp;getv8 = xmpData[<span class="stringliteral">&quot;Xmp.dc.eight&quot;</span>].value();</div>
<div class="line">    assert(getv8.toLong() == 1);</div>
<div class="line">    assert(getv8.ok());</div>
<div class="line">    assert(getv8.toFloat() == 1.0);</div>
<div class="line">    assert(getv8.ok());</div>
<div class="line">    assert(getv8.toRational() == <a class="code" href="doc/namespaceExiv2.html#a95756f3f7fa19103f83addf5fa088a30" title="8 byte signed rational type.">Exiv2::Rational</a>(1, 1));</div>
<div class="line">    assert(getv8.ok());</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Deleting an XMP property</span></div>
<div class="line">    <a class="code" href="doc/classExiv2_1_1XmpData.html#a6ad054efbea675843895e3f74c3c1923" title="XmpMetadata iterator type.">Exiv2::XmpData::iterator</a> pos = xmpData.<a name="a8"></a><a class="code" href="doc/classExiv2_1_1XmpData.html#af4d4e63ed5641dbc6e211b880f6d0990" title="Find the first Xmpdatum with the given key, return an iterator to it.">findKey</a>(<a name="_a9"></a><a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.dc.eight&quot;</span>));</div>
<div class="line">    <span class="keywordflow">if</span> (pos == xmpData.<a name="a10"></a><a class="code" href="doc/classExiv2_1_1XmpData.html#a1db4d5a92a7ec0694da08a7dee58faac" title="End of the metadata.">end</a>()) <span class="keywordflow">throw</span> <a name="_a11"></a><a class="code" href="doc/classExiv2_1_1BasicError.html" title="Simple error class used for exceptions. An output operator is provided to print errors to a stream...">Exiv2::Error</a>(1, <span class="stringliteral">&quot;Key not found&quot;</span>);</div>
<div class="line">    xmpData.<a name="a12"></a><a class="code" href="doc/classExiv2_1_1XmpData.html#aa608042a71623e7dac640c135cb768e6" title="Delete the Xmpdatum at iterator position pos, return the position of the next Xmpdatum.">erase</a>(pos);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// -------------------------------------------------------------------------</span></div>
<div class="line">    <span class="comment">// Exiv2 has specialized values for simple XMP properties, arrays of simple</span></div>
<div class="line">    <span class="comment">// properties and language alternatives.</span></div>
<div class="line"></div>
<div class="line">    <span class="comment">// Add a simple XMP property in a known namespace    </span></div>
<div class="line">    <a class="code" href="doc/classExiv2_1_1Value.html#a0f62e585b82c97738858b743e60dff21" title="Shortcut for a Value auto pointer.">Exiv2::Value::AutoPtr</a> v = <a name="a13"></a><a class="code" href="doc/classExiv2_1_1Value.html#ad6ff043921cd1a5c399a9a4fc8257006" title="A (simple) factory to create a Value type.">Exiv2::Value::create</a>(<a name="a14"></a><a class="code" href="doc/namespaceExiv2.html#a5153319711f35fe81cbc13f4b852450ca77cea60f60ef2c6f0f986137c5404c02" title="XMP text type.">Exiv2::xmpText</a>);</div>
<div class="line">    v-&gt;read(<span class="stringliteral">&quot;image/jpeg&quot;</span>);</div>
<div class="line">    xmpData.<a name="a15"></a><a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.dc.format&quot;</span>), v.get());</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Add an ordered array of text values.</span></div>
<div class="line">    v = <a class="code" href="doc/classExiv2_1_1Value.html#ad6ff043921cd1a5c399a9a4fc8257006" title="A (simple) factory to create a Value type.">Exiv2::Value::create</a>(<a name="a16"></a><a class="code" href="doc/namespaceExiv2.html#a5153319711f35fe81cbc13f4b852450ca969c20e44455272599e3a273471546e8" title="XMP sequence type.">Exiv2::xmpSeq</a>); <span class="comment">// or xmpBag or xmpAlt.</span></div>
<div class="line">    v-&gt;read(<span class="stringliteral">&quot;1) The first creator&quot;</span>);         <span class="comment">// The sequence in which the array</span></div>
<div class="line">    v-&gt;read(<span class="stringliteral">&quot;2) The second creator&quot;</span>);        <span class="comment">// elements are added is their</span></div>
<div class="line">    v-&gt;read(<span class="stringliteral">&quot;3) And another one&quot;</span>);           <span class="comment">// order in the array.</span></div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.dc.creator&quot;</span>), v.get());</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Add a language alternative property</span></div>
<div class="line">    v = <a class="code" href="doc/classExiv2_1_1Value.html#ad6ff043921cd1a5c399a9a4fc8257006" title="A (simple) factory to create a Value type.">Exiv2::Value::create</a>(<a name="a17"></a><a class="code" href="doc/namespaceExiv2.html#a5153319711f35fe81cbc13f4b852450ca52dce1d022dd8927bc651d2e51dc1bcd" title="XMP language alternative type.">Exiv2::langAlt</a>);</div>
<div class="line">    v-&gt;read(<span class="stringliteral">&quot;lang=de-DE Hallo, Welt&quot;</span>);       <span class="comment">// The default doesn&#39;t need a </span></div>
<div class="line">    v-&gt;read(<span class="stringliteral">&quot;Hello, World&quot;</span>);                 <span class="comment">// qualifier</span></div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.dc.description&quot;</span>), v.get());</div>
<div class="line"></div>
<div class="line">    <span class="comment">// According to the XMP specification, Xmp.tiff.ImageDescription is an</span></div>
<div class="line">    <span class="comment">// alias for Xmp.dc.description. Exiv2 treats an alias just like any</span></div>
<div class="line">    <span class="comment">// other property and leaves it to the application to implement specific</span></div>
<div class="line">    <span class="comment">// behaviour if desired.</span></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.tiff.ImageDescription&quot;</span>] = <span class="stringliteral">&quot;TIFF image description&quot;</span>;</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.tiff.ImageDescription&quot;</span>] = <span class="stringliteral">&quot;lang=de-DE TIFF Bildbeschreibung&quot;</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// -------------------------------------------------------------------------</span></div>
<div class="line">    <span class="comment">// Register a namespace which Exiv2 doesn&#39;t know yet. This is only needed</span></div>
<div class="line">    <span class="comment">// when properties are added manually. If the XMP metadata is read from an</span></div>
<div class="line">    <span class="comment">// image, namespaces are decoded and registered at the same time.</span></div>
<div class="line">    <a name="a18"></a><a class="code" href="doc/classExiv2_1_1XmpProperties.html#ae58ee081625b7924563e93a1ba184fec" title="Register namespace ns with preferred prefix prefix.">Exiv2::XmpProperties::registerNs</a>(<span class="stringliteral">&quot;myNamespace/&quot;</span>, <span class="stringliteral">&quot;ns&quot;</span>);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// -------------------------------------------------------------------------</span></div>
<div class="line">    <span class="comment">// Add a property in the new custom namespace.</span></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.ns.myProperty&quot;</span>] = <span class="stringliteral">&quot;myValue&quot;</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// -------------------------------------------------------------------------</span></div>
<div class="line">    <span class="comment">// There are no specialized values for structures, qualifiers and nested</span></div>
<div class="line">    <span class="comment">// types. However, these can be added by using an XmpTextValue and a path as</span></div>
<div class="line">    <span class="comment">// the key.</span></div>
<div class="line"></div>
<div class="line">    <span class="comment">// Add a structure</span></div>
<div class="line">    <a class="code" href="doc/classExiv2_1_1XmpTextValue.html" title="Value type suitable for simple XMP properties and XMP nodes of complex types which are not parsed int...">Exiv2::XmpTextValue</a> tv(<span class="stringliteral">&quot;16&quot;</span>);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.xmpDM.videoFrameSize/stDim:w&quot;</span>), &amp;tv);</div>
<div class="line">    tv.read(<span class="stringliteral">&quot;9&quot;</span>);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.xmpDM.videoFrameSize/stDim:h&quot;</span>), &amp;tv);</div>
<div class="line">    tv.read(<span class="stringliteral">&quot;inch&quot;</span>);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.xmpDM.videoFrameSize/stDim:unit&quot;</span>), &amp;tv);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Add an element with a qualifier (using the namespace registered above)</span></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.publisher&quot;</span>] = <span class="stringliteral">&quot;James Bond&quot;</span>;  <span class="comment">// creates an unordered array</span></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.dc.publisher[1]/?ns:role&quot;</span>] = <span class="stringliteral">&quot;secret agent&quot;</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Add a qualifer to an array element of Xmp.dc.creator (added above)</span></div>
<div class="line">    tv.read(<span class="stringliteral">&quot;programmer&quot;</span>);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.dc.creator[2]/?ns:role&quot;</span>), &amp;tv);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Add an array of structures</span></div>
<div class="line">    tv.read(<span class="stringliteral">&quot;&quot;</span>);                                         <span class="comment">// Clear the value</span></div>
<div class="line">    tv.setXmpArrayType(Exiv2::XmpValue::xaBag);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.xmpBJ.JobRef&quot;</span>), &amp;tv); <span class="comment">// Set the array type.</span></div>
<div class="line"></div>
<div class="line">    tv.setXmpArrayType(Exiv2::XmpValue::xaNone);</div>
<div class="line">    tv.read(<span class="stringliteral">&quot;Birthday party&quot;</span>);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.xmpBJ.JobRef[1]/stJob:name&quot;</span>), &amp;tv);</div>
<div class="line">    tv.read(<span class="stringliteral">&quot;Photographer&quot;</span>);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.xmpBJ.JobRef[1]/stJob:role&quot;</span>), &amp;tv);</div>
<div class="line"></div>
<div class="line">    tv.read(<span class="stringliteral">&quot;Wedding ceremony&quot;</span>);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.xmpBJ.JobRef[2]/stJob:name&quot;</span>), &amp;tv);</div>
<div class="line">    tv.read(<span class="stringliteral">&quot;Best man&quot;</span>);</div>
<div class="line">    xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a8ce28ae5c68a30b8e646c7ddfed75843" title="Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value...">add</a>(<a class="code" href="doc/classExiv2_1_1XmpKey.html" title="Concrete keys for XMP metadata.">Exiv2::XmpKey</a>(<span class="stringliteral">&quot;Xmp.xmpBJ.JobRef[2]/stJob:role&quot;</span>), &amp;tv);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Add a creator contact info structure</span></div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.iptc.CreatorContactInfo/Iptc4xmpCore:CiAdrCity&quot;</span>] = <span class="stringliteral">&quot;Kuala Lumpur&quot;</span>;</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.iptc.CreatorContactInfo/Iptc4xmpCore:CiAdrCtry&quot;</span>] = <span class="stringliteral">&quot;Malaysia&quot;</span>;</div>
<div class="line">    xmpData[<span class="stringliteral">&quot;Xmp.iptc.CreatorContactInfo/Iptc4xmpCore:CiUrlWork&quot;</span>] = <span class="stringliteral">&quot;http://www.exiv2.org&quot;</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// -------------------------------------------------------------------------</span></div>
<div class="line">    <span class="comment">// Output XMP properties</span></div>
<div class="line">    <span class="keywordflow">for</span> (<a class="code" href="doc/classExiv2_1_1XmpData.html#a9c0a6575296f3da8bfc200091da40f2e" title="XmpMetadata const iterator type.">Exiv2::XmpData::const_iterator</a> md = xmpData.<a name="a19"></a><a class="code" href="doc/classExiv2_1_1XmpData.html#aa6649bbd9d1f35555778febb49d5857a" title="Begin of the metadata.">begin</a>(); </div>
<div class="line">         md != xmpData.<a class="code" href="doc/classExiv2_1_1XmpData.html#a1db4d5a92a7ec0694da08a7dee58faac" title="End of the metadata.">end</a>(); ++md) {</div>
<div class="line">        std::cout &lt;&lt; std::setfill(<span class="charliteral">&#39; &#39;</span>) &lt;&lt; std::left</div>
<div class="line">                  &lt;&lt; std::setw(44)</div>
<div class="line">                  &lt;&lt; md-&gt;key() &lt;&lt; <span class="stringliteral">&quot; &quot;</span></div>
<div class="line">                  &lt;&lt; std::setw(9) &lt;&lt; std::setfill(<span class="charliteral">&#39; &#39;</span>) &lt;&lt; std::left</div>
<div class="line">                  &lt;&lt; md-&gt;typeName() &lt;&lt; <span class="stringliteral">&quot; &quot;</span></div>
<div class="line">                  &lt;&lt; std::dec &lt;&lt; std::setw(3)</div>
<div class="line">                  &lt;&lt; std::setfill(<span class="charliteral">&#39; &#39;</span>) &lt;&lt; std::right</div>
<div class="line">                  &lt;&lt; md-&gt;<a name="a20"></a><a class="code" href="doc/classExiv2_1_1XmpData.html#a65b24c7bef3d7e9f2b58edfc19571753" title="Get the number of metadata entries.">count</a>() &lt;&lt; <span class="stringliteral">&quot;  &quot;</span></div>
<div class="line">                  &lt;&lt; std::dec &lt;&lt; md-&gt;value()</div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">// -------------------------------------------------------------------------</span></div>
<div class="line">    <span class="comment">// Serialize the XMP data and output the XMP packet</span></div>
<div class="line">    std::string xmpPacket;</div>
<div class="line">    <span class="keywordflow">if</span> (0 != <a name="a22"></a><a class="code" href="doc/classExiv2_1_1XmpParser.html#afad88c80404f9f35b687b33fe9ea9c63" title="Encode (serialize) XMP metadata from xmpData into a string xmpPacket. The XMP packet returned in the ...">Exiv2::XmpParser::encode</a>(xmpPacket, xmpData)) {</div>
<div class="line">        <span class="keywordflow">throw</span> <a name="a23"></a><a class="code" href="doc/namespaceExiv2.html#accd3e49cafe9db52c1e0e6f648753cae" title="Error class used for exceptions (std::string based)">Exiv2::Error</a>(1, <span class="stringliteral">&quot;Failed to serialize XMP data&quot;</span>);</div>
<div class="line">    }</div>
<div class="line">    std::cout &lt;&lt; xmpPacket &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Cleanup</span></div>
<div class="line">    <a name="a24"></a><a class="code" href="doc/classExiv2_1_1XmpParser.html#a46ff7c85b860ef81310e0ac8dd6b62a2" title="Terminate the XMP Toolkit and unregister custom namespaces.">Exiv2::XmpParser::terminate</a>();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"><span class="keywordflow">catch</span> (<a name="_a25"></a><a class="code" href="doc/classExiv2_1_1AnyError.html" title="Error class interface. Allows the definition and use of a hierarchy of error classes which can all be...">Exiv2::AnyError</a>&amp; e) {</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Caught Exiv2 exception &#39;&quot;</span> &lt;&lt; e &lt;&lt; <span class="stringliteral">&quot;&#39;\n&quot;</span>;</div>
<div class="line">    <span class="keywordflow">return</span> -1;</div>
<div class="line">}</div>
</div><!-- fragment -->
