metavalue.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "debug.h"
00024 #include "exception.h"
00025 #include "metavalue.h"
00026
00027 using namespace Debug;
00028
00029 namespace OpenRaw {
00030
00031 MetaValue::MetaValue(const MetaValue & r)
00032 : m_value(r.m_value)
00033 {
00034 }
00035
00036 MetaValue::MetaValue(const value_t &v)
00037 : m_value(v)
00038 {
00039 }
00040
00041 namespace {
00042
00043 template <class T>
00044 MetaValue::value_t convert(const Internals::IFDEntry::Ref & e)
00045 {
00046 T v;
00047 v = Internals::IFDTypeTrait<T>::get(*e, 0, false);
00048 return MetaValue::value_t(v);
00049 }
00050
00051 }
00052
00053 MetaValue::MetaValue(const Internals::IFDEntry::Ref & e)
00054 {
00055 switch(e->type()) {
00056 case Internals::IFD::EXIF_FORMAT_BYTE:
00057 {
00058 m_value = convert<uint8_t>(e);
00059 break;
00060 }
00061 case Internals::IFD::EXIF_FORMAT_ASCII:
00062 {
00063 m_value = convert<std::string>(e);
00064 break;
00065 }
00066 case Internals::IFD::EXIF_FORMAT_SHORT:
00067 {
00068 m_value = convert<uint16_t>(e);
00069 break;
00070 }
00071 case Internals::IFD::EXIF_FORMAT_LONG:
00072 {
00073 m_value = convert<uint32_t>(e);
00074 break;
00075 }
00076 default:
00077 Trace(DEBUG1) << "unhandled type " << e->type() << "\n";
00078 break;
00079 }
00080 }
00081
00082 template<typename T>
00083 inline T MetaValue::get() const
00084 throw(Internals::BadTypeException)
00085 {
00086 T v;
00087 assert(!m_value.empty());
00088 try {
00089 v = boost::get<T>(m_value);
00090 }
00091 catch(...) {
00092 throw Internals::BadTypeException();
00093 }
00094 return v;
00095 }
00096
00097
00098 uint32_t MetaValue::getInteger() const
00099 throw(Internals::BadTypeException)
00100 {
00101 return get<uint32_t>();
00102 }
00103
00104 std::string MetaValue::getString() const
00105 throw(Internals::BadTypeException)
00106 {
00107 return get<std::string>();
00108 }
00109
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119