1
// ***************************************************************** -*- C++ -*-
2
// xmpparse.cpp, $Rev: 1271 $
3
// Read an XMP packet from a file, parse it and print all (known) properties.
5
#include <exiv2/basicio.hpp>
6
#include <exiv2/xmp.hpp>
7
#include <exiv2/error.hpp>
13
int main(int argc, char* const argv[])
16
std::cout << "Usage: " << argv[0] << " file\n";
19
Exiv2::DataBuf buf = Exiv2::readFile(argv[1]);
20
std::string xmpPacket;
21
xmpPacket.assign(reinterpret_cast<char*>(buf.pData_), buf.size_);
22
Exiv2::XmpData xmpData;
23
if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket)) {
24
std::string error(argv[1]);
25
error += ": Failed to parse file contents (XMP packet)";
26
throw Exiv2::Error(1, error);
28
if (xmpData.empty()) {
29
std::string error(argv[1]);
30
error += ": No XMP properties found in the XMP packet";
31
throw Exiv2::Error(1, error);
33
for (Exiv2::XmpData::const_iterator md = xmpData.begin();
34
md != xmpData.end(); ++md) {
35
std::cout << std::setfill(' ') << std::left
38
<< std::setw(9) << std::setfill(' ') << std::left
39
<< md->typeName() << " "
40
<< std::dec << std::setw(3)
41
<< std::setfill(' ') << std::right
43
<< std::dec << md->value()
46
Exiv2::XmpParser::terminate();
49
catch (Exiv2::AnyError& e) {
50
std::cout << "Caught Exiv2 exception '" << e << "'\n";