diff options
author | Hubert Figuière <hub@figuiere.net> | 2013-07-15 22:51:08 -0400 |
---|---|---|
committer | Hubert Figuière <hub@figuiere.net> | 2013-07-15 22:51:08 -0400 |
commit | a39b4a46eef3ef1d48689b23d171c0e67045f197 (patch) | |
tree | 170f5d3da23741b282a8d96d15afe05644e3a8dd | |
parent | d7f5bea474eea662a0520b4e9b1b343b3f880300 (diff) |
New: API xmp_datetime_compare().
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | exempi/Makefile.am | 5 | ||||
-rw-r--r-- | exempi/exempi.cpp | 41 | ||||
-rw-r--r-- | exempi/tests/test-exempi-core.cpp | 52 | ||||
-rw-r--r-- | exempi/xmp.h | 10 |
5 files changed, 77 insertions, 32 deletions
@@ -2,6 +2,7 @@ - Public header cleanup and documentation update. - Update Doxygen config. +- New: API xmp_datetime_compare(). 2.2.1 - 2013/06/29 diff --git a/exempi/Makefile.am b/exempi/Makefile.am index 5aec920..ef7bc99 100644 --- a/exempi/Makefile.am +++ b/exempi/Makefile.am @@ -46,7 +46,10 @@ exempi_SOURCES = main.cpp exempi_CPPFLAGS = -I$(srcdir)/.. exempi_LDADD = libexempi.la -INCLUDES = -I$(top_srcdir)/public/include +INCLUDES = -I$(top_srcdir)/public/include -I$(top_srcdir)/source/XMPCore \ + -I$(top_srcdir)/build/ \ + -I$(top_srcdir)/source/common/ \ + $(NULL) AM_CPPFLAGS = -Wall -D@EXEMPI_PLATFORM_DEF@=1 lib_LTLIBRARIES = libexempi.la diff --git a/exempi/exempi.cpp b/exempi/exempi.cpp index a57aba6..63a2e31 100644 --- a/exempi/exempi.cpp +++ b/exempi/exempi.cpp @@ -1,7 +1,7 @@ /* * exempi - exempi.cpp * - * Copyright (C) 2007-2009 Hubert Figuiere + * Copyright (C) 2007-2013 Hubert Figuiere * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ #define TXMP_STRING_TYPE std::string #include "XMP.hpp" #include "XMP.incl_cpp" +#include "XMPUtils.hpp" #if HAVE_NATIVE_TLS @@ -128,17 +129,18 @@ static void set_error(const XMP_Error & e) #define RESET_ERROR set_error(0) +// Hack: assign between XMP_DateTime and XmpDateTime #define ASSIGN(dst, src) \ - dst.year = src.year; \ - dst.month = src.month;\ - dst.day = src.day; \ - dst.hour = src.hour; \ - dst.minute = src.minute; \ - dst.second = src.second; \ - dst.tzSign = src.tzSign; \ - dst.tzHour = src.tzHour; \ - dst.tzMinute = src.tzMinute; \ - dst.nanoSecond = src.nanoSecond; + (dst).year = (src).year; \ + (dst).month = (src).month; \ + (dst).day = (src).day; \ + (dst).hour = (src).hour; \ + (dst).minute = (src).minute; \ + (dst).second = (src).second; \ + (dst).tzSign = (src).tzSign; \ + (dst).tzHour = (src).tzHour; \ + (dst).tzMinute = (src).tzMinute; \ + (dst).nanoSecond = (src).nanoSecond; @@ -1063,6 +1065,23 @@ bool xmp_iterator_skip(XmpIteratorPtr iter, XmpIterSkipOptions options) return true; } +int xmp_datetime_compare(XmpDateTime* left, XmpDateTime* right) +{ + if(!left && !right) { + return 0; + } + if(!left) { + return -1; + } + if(!right) { + return 1; + } + XMP_DateTime _left; + ASSIGN(_left, *left); + XMP_DateTime _right; + ASSIGN(_right, *right); + return XMPUtils::CompareDateTime(_left, _right); +} #ifdef __cplusplus } diff --git a/exempi/tests/test-exempi-core.cpp b/exempi/tests/test-exempi-core.cpp index d78eeba..0eb1bae 100644 --- a/exempi/tests/test-exempi-core.cpp +++ b/exempi/tests/test-exempi-core.cpp @@ -1,7 +1,7 @@ /* * exempi - test-exempi-core.cpp * - * Copyright (C) 2007-2008 Hubert Figuiere + * Copyright (C) 2007-2013 Hubert Figuiere * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -163,42 +163,56 @@ int test_main(int argc, char *argv[]) BOOST_CHECK(xmp_get_property(xmp, NS_XAP, "Rating", the_prop, NULL)); - BOOST_CHECK(strcmp("3", xmp_string_cstr(the_prop)) == 0); - + BOOST_CHECK(strcmp("3", xmp_string_cstr(the_prop)) == 0); + xmp_string_free(the_prop); // testing date time get XmpDateTime the_dt; bool ret; - BOOST_CHECK(ret = xmp_get_property_date(xmp, NS_EXIF, "DateTimeOriginal", - &the_dt, NULL)); + BOOST_CHECK(ret = xmp_get_property_date(xmp, NS_EXIF, + "DateTimeOriginal", + &the_dt, NULL)); BOOST_CHECK(the_dt.year == 2006); BOOST_CHECK(the_dt.minute == 20); BOOST_CHECK(the_dt.tzSign == XMP_TZ_WEST); + // testing compare + XmpDateTime the_other_dt; + BOOST_CHECK(ret = xmp_get_property_date(xmp, NS_EXIF, + "DateTimeOriginal", + &the_other_dt, NULL)); + BOOST_CHECK(xmp_datetime_compare(&the_dt, &the_other_dt) == 0); + the_other_dt.year++; + BOOST_CHECK(xmp_datetime_compare(&the_dt, &the_other_dt) < 0); + BOOST_CHECK(xmp_datetime_compare(&the_other_dt, &the_dt) > 0); + // NULL checks - this is Exempi API + BOOST_CHECK(xmp_datetime_compare(NULL, NULL) == 0); + BOOST_CHECK(xmp_datetime_compare(NULL, &the_other_dt) < 0); + BOOST_CHECK(xmp_datetime_compare(&the_other_dt, NULL) > 0); // testing float get set double float_value = 0.0; - BOOST_CHECK(xmp_get_property_float(xmp, NS_CAMERA_RAW_SETTINGS, - "SharpenRadius", &float_value, NULL)); + BOOST_CHECK(xmp_get_property_float(xmp, NS_CAMERA_RAW_SETTINGS, + "SharpenRadius", &float_value, NULL)); BOOST_CHECK(float_value == 1.0); - BOOST_CHECK(xmp_set_property_float(xmp, NS_CAMERA_RAW_SETTINGS, - "SharpenRadius", 2.5, 0)); - BOOST_CHECK(xmp_get_property_float(xmp, NS_CAMERA_RAW_SETTINGS, - "SharpenRadius", &float_value, NULL)); + BOOST_CHECK(xmp_set_property_float(xmp, NS_CAMERA_RAW_SETTINGS, + "SharpenRadius", 2.5, 0)); + BOOST_CHECK(xmp_get_property_float(xmp, NS_CAMERA_RAW_SETTINGS, + "SharpenRadius", &float_value, NULL)); BOOST_CHECK(float_value == 2.5); - + // testing bool get set bool bool_value = true; - BOOST_CHECK(xmp_get_property_bool(xmp, NS_CAMERA_RAW_SETTINGS, - "AlreadyApplied", &bool_value, NULL)); + BOOST_CHECK(xmp_get_property_bool(xmp, NS_CAMERA_RAW_SETTINGS, + "AlreadyApplied", &bool_value, NULL)); BOOST_CHECK(!bool_value); - BOOST_CHECK(xmp_set_property_bool(xmp, NS_CAMERA_RAW_SETTINGS, - "AlreadyApplied", true, 0)); - BOOST_CHECK(xmp_get_property_bool(xmp, NS_CAMERA_RAW_SETTINGS, - "AlreadyApplied", &bool_value, NULL)); - BOOST_CHECK(bool_value); + BOOST_CHECK(xmp_set_property_bool(xmp, NS_CAMERA_RAW_SETTINGS, + "AlreadyApplied", true, 0)); + BOOST_CHECK(xmp_get_property_bool(xmp, NS_CAMERA_RAW_SETTINGS, + "AlreadyApplied", &bool_value, NULL)); + BOOST_CHECK(bool_value); // testing int get set int32_t value = 0; diff --git a/exempi/xmp.h b/exempi/xmp.h index 7ab1a7f..f56803c 100644 --- a/exempi/xmp.h +++ b/exempi/xmp.h @@ -307,7 +307,7 @@ typedef struct _XmpString *XmpStringPtr; typedef struct _XmpIterator *XmpIteratorPtr; typedef struct _XmpDateTime { - int32_t year; + int32_t year; int32_t month; /* 1..12 */ int32_t day; /* 1..31 */ int32_t hour; /* 0..23 */ @@ -699,6 +699,14 @@ bool xmp_iterator_next(XmpIteratorPtr iter, XmpStringPtr schema, bool xmp_iterator_skip(XmpIteratorPtr iter, XmpIterSkipOptions options); +/** Compare two XmpDateTime + * @param left value + * @param right value + * @return if left < right, return < 0. If left > right, return > 0. + * if left == right, return 0. + */ +int xmp_datetime_compare(XmpDateTime* left, XmpDateTime* right); + #ifdef __cplusplus } #endif |