diff --git a/src/uni-exiv2.cpp b/src/uni-exiv2.cpp index 0d14b9f..567a50f 100644 --- a/src/uni-exiv2.cpp +++ b/src/uni-exiv2.cpp @@ -22,12 +22,22 @@ #include #include +#include #include "uni-exiv2.hpp" #define ARRAY_SIZE(array) (sizeof array/sizeof(array[0])) -static Exiv2::Image::AutoPtr cached_image; +#define EXIV_ERROR Exiv2::AnyError +#ifdef EXIV2_VERSION + #ifdef EXIV2_TEST_VERSION + #if EXIV2_TEST_VERSION(0,28,0) + #define EXIV_ERROR Exiv2::Error + #endif + #endif +#endif + +static std::unique_ptr cached_image; extern "C" void @@ -35,8 +45,8 @@ uni_read_exiv2_map(const char *uri, void (*callback)(const char*, const char*, v { Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute); try { - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(uri); - if ( image.get() == 0 ) { + std::unique_ptr image = Exiv2::ImageFactory::open(uri); + if (image == nullptr) { return; } @@ -80,7 +90,7 @@ uni_read_exiv2_map(const char *uri, void (*callback)(const char*, const char*, v } } } - } catch (Exiv2::AnyError& e) { + } catch (EXIV_ERROR& e) { std::cerr << "Exiv2: '" << e << "'\n"; } } @@ -91,19 +101,19 @@ uni_read_exiv2_to_cache(const char *uri) { Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute); - if ( cached_image.get() != NULL ) { + if (cached_image != nullptr) { cached_image->clearMetadata(); - cached_image.reset(NULL); + cached_image.reset(nullptr); } try { cached_image = Exiv2::ImageFactory::open(uri); - if ( cached_image.get() == 0 ) { + if (cached_image == nullptr) { return 1; } cached_image->readMetadata(); - } catch (Exiv2::AnyError& e) { + } catch (EXIV_ERROR& e) { std::cerr << "Exiv2: '" << e << "'\n"; } @@ -116,13 +126,13 @@ uni_write_exiv2_from_cache(const char *uri) { Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute); - if ( cached_image.get() == NULL ) { + if (cached_image == nullptr) { return 1; } try { - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(uri); - if ( image.get() == 0 ) { + std::unique_ptr image = Exiv2::ImageFactory::open(uri); + if (image == nullptr) { return 2; } @@ -130,10 +140,10 @@ uni_write_exiv2_from_cache(const char *uri) image->writeMetadata(); cached_image->clearMetadata(); - cached_image.reset(NULL); + cached_image.reset(nullptr); return 0; - } catch (Exiv2::AnyError& e) { + } catch (EXIV_ERROR& e) { std::cerr << "Exiv2: '" << e << "'\n"; }