<div class="line"> <span class="comment">// Container for exif metadata. This is an example of creating</span></div>
<div class="line"> <span class="comment">// exif metadata from scratch. If you want to add, modify, delete</span></div>
<div class="line"> <span class="comment">// metadata that exists in an image, start with ImageFactory::open</span></div>
<div class="line"> <a name="_a1"></a><a class="code" href="doc/classExiv2_1_1ExifData.html" title="A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...">Exiv2::ExifData</a> exifData;</div>
<div class="line"> std::cout << <span class="stringliteral">"Added a few tags the quick way.\n"</span>;</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Create a ASCII string value (note the use of create)</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="a3"></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="a4"></a><a class="code" href="doc/namespaceExiv2.html#a5153319711f35fe81cbc13f4b852450ca773cf6dde5caaabb3dcf9fb161fa7dfd" title="Exif ASCII type, 8-bit byte.">Exiv2::asciiString</a>);</div>
<div class="line"> <span class="comment">// Set the value to a string</span></div>
<div class="line"> <span class="comment">// Add the value together with its key to the Exif data container</span></div>
<div class="line"> <a name="_a5"></a><a class="code" href="doc/classExiv2_1_1ExifKey.html" title="Concrete keys for Exif metadata and access to Exif tag reference data.">Exiv2::ExifKey</a> key(<span class="stringliteral">"Exif.Photo.DateTimeOriginal"</span>);</div>
<div class="line"> exifData.<a name="a6"></a><a class="code" href="doc/classExiv2_1_1ExifData.html#a91d231cd1b9fefc311c5166e30ab66eb" title="Add an Exifdatum from the supplied key and value pair. This method copies (clones) key and value...">add</a>(key, v.get());</div>
<div class="line"> <span class="comment">// Now create a more interesting value (without using the create method)</span></div>
<div class="line"> <a class="code" href="doc/classExiv2_1_1ValueType.html#a0c76c512468a47f6eac463f4af278a14" title="Shortcut for a ValueType<T> auto pointer.">Exiv2::URationalValue::AutoPtr</a> rv(<span class="keyword">new</span> <a name="_a7"></a><a class="code" href="doc/classExiv2_1_1ValueType.html" title="Template for a Value of a basic type. This is used for unsigned and signed short, long and rationals...">Exiv2::URationalValue</a>);</div>
<div class="line"> <span class="comment">// Set two rational components from a string</span></div>
<div class="line"> <span class="comment">// Add the key and value pair to the Exif data</span></div>
<div class="line"> key = <a class="code" href="doc/classExiv2_1_1ExifKey.html" title="Concrete keys for Exif metadata and access to Exif tag reference data.">Exiv2::ExifKey</a>(<span class="stringliteral">"Exif.Image.PrimaryChromaticities"</span>);</div>
<div class="line"> exifData.<a class="code" href="doc/classExiv2_1_1ExifData.html#a91d231cd1b9fefc311c5166e30ab66eb" title="Add an Exifdatum from the supplied key and value pair. This method copies (clones) key and value...">add</a>(key, rv.get());</div>
<div class="line"> <span class="comment">// Since we know that the metadatum exists (or we don't mind creating a new</span></div>
<div class="line"> <span class="comment">// tag if it doesn't), we can simply do this:</span></div>
<div class="line"> <a name="_a8"></a><a class="code" href="doc/classExiv2_1_1Exifdatum.html" title="An Exif metadatum, consisting of an ExifKey and a Value and methods to manipulate these...">Exiv2::Exifdatum</a>& tag = exifData[<span class="stringliteral">"Exif.Photo.DateTimeOriginal"</span>];</div>
<div class="line"> std::string date = tag.<a name="a10"></a><a class="code" href="doc/classExiv2_1_1Exifdatum.html#a73d1e5346411c2adf520fec405f2e536" title="Return the value as a string.">toString</a>();</div>
<div class="line"> std::cout << <span class="stringliteral">"Modified key \""</span> << tag.<a name="a12"></a><a class="code" href="doc/classExiv2_1_1Exifdatum.html#a6651602de3d217dd622d33ab67289c11" title="Return the key of the Exifdatum.">key</a>()</div>
<div class="line"> << <span class="stringliteral">"\", new value \""</span> << tag.<a name="a13"></a><a class="code" href="doc/classExiv2_1_1Exifdatum.html#ad4a621c1399e02648f1fb1fb550e7a53" title="Return a constant reference to the value.">value</a>() << <span class="stringliteral">"\"\n"</span>;</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Alternatively, we can use findKey()</span></div>
<div class="line"> key = <a class="code" href="doc/classExiv2_1_1ExifKey.html" title="Concrete keys for Exif metadata and access to Exif tag reference data.">Exiv2::ExifKey</a>(<span class="stringliteral">"Exif.Image.PrimaryChromaticities"</span>);</div>
<div class="line"> <a class="code" href="doc/classExiv2_1_1ExifData.html#a02e2a2acb4cfeb0f7755c1a45f94106f" title="ExifMetadata iterator type.">Exiv2::ExifData::iterator</a> pos = exifData.<a name="a14"></a><a class="code" href="doc/classExiv2_1_1ExifData.html#a96c38cbd300ebdfa05f849864b380690" title="Find the first Exifdatum with the given key, return an iterator to it.">findKey</a>(key);</div>
<div class="line"> <span class="keywordflow">if</span> (pos == exifData.<a name="a15"></a><a class="code" href="doc/classExiv2_1_1ExifData.html#a9c15177b03489e3d4bb81e9acc1165fe" title="End of the metadata.">end</a>()) <span class="keywordflow">throw</span> <a name="_a16"></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">"Key not found"</span>);</div>
<div class="line"> <span class="comment">// Get a pointer to a copy of the value</span></div>
<div class="line"> v = pos->getValue();</div>
<div class="line"> <span class="comment">// Downcast the Value pointer to its actual type</span></div>
<div class="line"> <a class="code" href="doc/classExiv2_1_1ValueType.html" title="Template for a Value of a basic type. This is used for unsigned and signed short, long and rationals...">Exiv2::URationalValue</a>* prv = <span class="keyword">dynamic_cast<</span><a class="code" href="doc/classExiv2_1_1ValueType.html" title="Template for a Value of a basic type. This is used for unsigned and signed short, long and rationals...">Exiv2::URationalValue</a>*<span class="keyword">></span>(v.release());</div>
<div class="line"> <span class="keywordflow">if</span> (prv == 0) <span class="keywordflow">throw</span> <a name="a17"></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">"Downcast failed"</span>);</div>
<div class="line"> rv = <a name="a18"></a><a class="code" href="doc/classExiv2_1_1ValueType.html#a0c76c512468a47f6eac463f4af278a14" title="Shortcut for a ValueType<T> auto pointer.">Exiv2::URationalValue::AutoPtr</a>(prv);</div>
<div class="line"> <span class="comment">// Modify the value directly through the interface of URationalValue</span></div>
<div class="line"> <span class="comment">// Delete metadata from the Exif data container</span></div>
<div class="line"></div>
<div class="line"> <span class="comment">// Delete the metadatum at iterator position pos</span></div>
<div class="line"> key = <a class="code" href="doc/classExiv2_1_1ExifKey.html" title="Concrete keys for Exif metadata and access to Exif tag reference data.">Exiv2::ExifKey</a>(<span class="stringliteral">"Exif.Image.PrimaryChromaticities"</span>);</div>
<div class="line"> pos = exifData.<a class="code" href="doc/classExiv2_1_1ExifData.html#a96c38cbd300ebdfa05f849864b380690" title="Find the first Exifdatum with the given key, return an iterator to it.">findKey</a>(key);</div>
<div class="line"> <span class="keywordflow">if</span> (pos == exifData.<a class="code" href="doc/classExiv2_1_1ExifData.html#a9c15177b03489e3d4bb81e9acc1165fe" title="End of the metadata.">end</a>()) <span class="keywordflow">throw</span> <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">"Key not found"</span>);</div>
<div class="line"> exifData.<a name="a19"></a><a class="code" href="doc/classExiv2_1_1ExifData.html#a710a66ca8be51192c15729c541b72fb5" title="Delete the Exifdatum at iterator position pos, return the position of the next exifdatum. Note that iterators into the metadata, including pos, are potentially invalidated by this call.">erase</a>(pos);</div>
<div class="line"> <span class="comment">// Finally, write the remaining Exif data to the image file</span></div>
<div class="line"> <a class="code" href="doc/classExiv2_1_1Image.html#a89ad3ffe7a4e8a943d267d77843415fb" title="Image auto_ptr type.">Exiv2::Image::AutoPtr</a> image = <a name="a20"></a><a class="code" href="doc/classExiv2_1_1ImageFactory.html#aba929c4ca4a71625d12bcb97bcc28161" title="Create an Image subclass of the appropriate type by reading the specified file. Image type is derived...">Exiv2::ImageFactory::open</a>(file);</div>
<div class="line"><span class="keywordflow">catch</span> (<a name="_a21"></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>& e) {</div>