| 13 | } |
| 14 | |
| 15 | int main() try { |
| 16 | Exiv2::XmpParser::initialize(); |
| 17 | ::atexit(Exiv2::XmpParser::terminate); |
| 18 | |
| 19 | // The XMP property container |
| 20 | Exiv2::XmpData xmpData; |
| 21 | |
| 22 | // ------------------------------------------------------------------------- |
| 23 | // Teaser: Setting XMP properties doesn't get much easier than this: |
| 24 | |
| 25 | xmpData["Xmp.dc.source"] = "xmpsample.cpp"; // a simple text value |
| 26 | xmpData["Xmp.dc.subject"] = "Palmtree"; // an array item |
| 27 | xmpData["Xmp.dc.subject"] = "Rubbertree"; // add a 2nd array item |
| 28 | // a language alternative with two entries and without default |
| 29 | xmpData["Xmp.dc.title"] = "lang=de-DE Sonnenuntergang am Strand"; |
| 30 | xmpData["Xmp.dc.title"] = "lang=en-US Sunset on the beach"; |
| 31 | |
| 32 | // ------------------------------------------------------------------------- |
| 33 | // Any properties can be set provided the namespace is known. Values of any |
| 34 | // type can be assigned to an Xmpdatum, if they have an output operator. The |
| 35 | // default XMP value type for unknown properties is a simple text value. |
| 36 | |
| 37 | xmpData["Xmp.dc.one"] = -1; |
| 38 | xmpData["Xmp.dc.two"] = 3.1415; |
| 39 | xmpData["Xmp.dc.three"] = Exiv2::Rational(5, 7); |
| 40 | xmpData["Xmp.dc.four"] = static_cast<uint16_t>(255); |
| 41 | xmpData["Xmp.dc.five"] = 256; |
| 42 | xmpData["Xmp.dc.six"] = false; |
| 43 | |
| 44 | // In addition, there is a dedicated assignment operator for Exiv2::Value |
| 45 | Exiv2::XmpTextValue val("Seven"); |
| 46 | xmpData["Xmp.dc.seven"] = val; |
| 47 | xmpData["Xmp.dc.eight"] = true; |
| 48 | |
| 49 | // Extracting values |
| 50 | assert(xmpData["Xmp.dc.one"].toInt64() == -1); |
| 51 | assert(xmpData["Xmp.dc.one"].value().ok()); |
| 52 | |
| 53 | [[maybe_unused]] const Exiv2::Value& getv1 = xmpData["Xmp.dc.one"].value(); |
| 54 | assert(isEqual(getv1.toFloat(), -1)); |
| 55 | assert(getv1.ok()); |
| 56 | assert(getv1.toRational() == Exiv2::Rational(-1, 1)); |
| 57 | assert(getv1.ok()); |
| 58 | |
| 59 | [[maybe_unused]] const Exiv2::Value& getv2 = xmpData["Xmp.dc.two"].value(); |
| 60 | assert(isEqual(getv2.toFloat(), 3.1415f)); |
| 61 | assert(getv2.ok()); |
| 62 | assert(getv2.toInt64() == 3); |
| 63 | assert(getv2.ok()); |
| 64 | [[maybe_unused]] Exiv2::Rational R = getv2.toRational(); |
| 65 | assert(getv2.ok()); |
| 66 | assert(isEqual(static_cast<float>(R.first) / R.second, 3.1415f)); |
| 67 | |
| 68 | [[maybe_unused]] const Exiv2::Value& getv3 = xmpData["Xmp.dc.three"].value(); |
| 69 | assert(isEqual(getv3.toFloat(), 5.0f / 7.0f)); |
| 70 | assert(getv3.ok()); |
| 71 | assert(getv3.toInt64() == 0); // long(5.0 / 7.0) |
| 72 | assert(getv3.ok()); |
nothing calls this directly
no test coverage detected