25 #include "metavalue.hpp"
26 #include "exception.hpp"
30 using Internals::IFD::ORRational;
31 using Internals::IFD::ORSRational;
33 MetaValue::MetaValue(
const MetaValue & r)
34 : m_values(r.m_values)
38 MetaValue::MetaValue(
const value_t &v)
40 m_values.push_back(v);
43 MetaValue::MetaValue(
const std::vector<value_t> &v)
50 inline T MetaValue::get(
int idx)
const noexcept(
false)
52 assert(!m_values.empty());
54 return boost::get<T>(m_values[idx]);
57 throw Internals::BadTypeException();
62 inline const T & MetaValue::getRef(
int idx)
const noexcept(
false)
65 assert(!m_values.empty());
67 return boost::get<T>(m_values[idx]);
70 throw Internals::BadTypeException();
75 uint32_t MetaValue::getUInteger(
int idx)
const
77 return get<uint32_t>(idx);
80 int32_t MetaValue::getSInteger(
int idx)
const
82 return get<int32_t>(idx);
85 const std::string & MetaValue::getString(
int idx)
const
87 return getRef<std::string>(idx);
90 double MetaValue::getDouble(
int idx)
const
92 int type = m_values[idx].which();
95 return to_double(get<OpenRaw::Internals::IFD::ORRational>(idx));
97 return to_double(get<OpenRaw::Internals::IFD::ORSRational>(idx));
101 return get<double>(idx);
106 :
public boost::static_visitor<std::string>
109 std::string operator()(
const std::string& s) {
112 std::string operator()(
const uint8_t v) {
113 return std::to_string(v);
115 std::string operator()(uint32_t v) {
116 return std::to_string(v);
118 std::string operator()(int32_t v) {
119 return std::to_string(v);
121 std::string operator()(
double v) {
122 return std::to_string(v);
124 std::string operator()(
const ORRational& r) {
125 return std::to_string(r.num) +
"/" + std::to_string(r.denom);
127 std::string operator()(
const ORSRational& r) {
128 return std::to_string(r.num) +
"/" + std::to_string(r.denom);
132 const std::string & MetaValue::getAsString(
bool full)
const
135 if (m_as_str.empty()) {
137 bool multiple = (getCount() > 1);
141 for (
auto value : m_values) {
142 m_as_str += value.apply_visitor(visitor);
147 if (!full && count > 20) {
Formatter for getAsString()
double to_double(const ORRational &r)
Convert an ORRational to a double.
Global namespace for libopenraw.