39 #ifndef OME_XML_MODEL_DETAIL_PARSE_H 40 #define OME_XML_MODEL_DETAIL_PARSE_H 43 #include <type_traits> 45 #include <ome/xml/model/OMEModelObject.h> 47 #include <boost/mpl/bool.hpp> 68 const std::string& klass,
69 const std::string& property);
74 : boost::false_type {};
79 : boost::true_type {};
94 const std::string& klass,
95 const std::string& property)
97 std::istringstream is(text);
98 is.imbue(std::locale::classic());
117 const std::string& klass,
118 const std::string& property)
120 std::istringstream is(text);
121 is.imbue(std::locale::classic());
123 if (!(is >> std::boolalpha >> value))
131 # pragma GCC diagnostic push 132 # pragma GCC diagnostic ignored "-Wunused-parameter" 146 parse_value<std::string>(
const std::string& text,
148 const std::string& klass,
149 const std::string& property)
155 # pragma GCC diagnostic pop 168 inline typename std::enable_if<
170 typename std::remove_const<typename boost::remove_reference<T>::type>::type
173 const std::string& klass,
174 const std::string& property)
176 typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type raw_type;
193 inline typename std::enable_if<
195 typename std::remove_const<typename boost::remove_reference<T>::type>::type
198 const std::string& klass,
199 const std::string& property)
201 typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type raw_type;
203 raw_type attr(std::make_shared<typename raw_type::element_type>());
222 template<
class C,
typename T>
226 void (C::* setter)(T value),
227 const std::string& klass,
228 const std::string& property)
230 typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type raw_type;
232 raw_type attr(parse_value<raw_type>(text, klass, property));
234 (
object.*setter)(attr);
248 inline typename std::enable_if<
249 !is_shared_ptr<T>::value,
250 typename std::remove_const<typename boost::remove_reference<T>::type>::type
253 const std::string& unit,
254 const std::string& klass,
255 const std::string& property)
257 typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type raw_type;
259 typename raw_type::element_type::value_type v;
261 typename raw_type::element_type::unit_type u(unit);
277 inline typename std::enable_if<
278 is_shared_ptr<T>::value,
279 typename std::remove_const<typename boost::remove_reference<T>::type>::type
282 const std::string& unit,
283 const std::string& klass,
284 const std::string& property)
286 typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type raw_type;
288 typename raw_type::element_type::value_type v;
290 typename raw_type::element_type::unit_type u(unit);
291 raw_type attr(std::make_shared<typename raw_type::element_type>(v, u));
310 template<
class C,
typename T>
313 const std::string& unit,
315 void (C::* setter)(T value),
316 const std::string& klass,
317 const std::string& property)
319 typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type raw_type;
321 raw_type attr(parse_quantity<raw_type>(text, unit, klass, property));
323 (
object.*setter)(attr);
331 #endif // OME_XML_MODEL_DETAIL_PARSE_H void parse_value< bool >(const std::string &text, bool &value, const std::string &klass, const std::string &property)
Parse a Boolean value.
Definition: Parse.h:115
void parse_value(const std::string &text, T &value, const std::string &klass, const std::string &property)
Parse an arbitrary value.
Definition: Parse.h:92
Open Microscopy Environment C++ implementation.
void set_value(const std::string &text, C &object, void(C::*setter)(T value), const std::string &klass, const std::string &property)
Set an arbitrary value.
Definition: Parse.h:224
void set_quantity(const std::string &text, const std::string &unit, C &object, void(C::*setter)(T value), const std::string &klass, const std::string &property)
Set an arbitrary quantity.
Definition: Parse.h:312
Type trait for shared_ptr.
Definition: Parse.h:73
void parse_value_fail(const std::string &text, const std::string &klass, const std::string &property)
Throw a model exception with an informative message.
Definition: Parse.cpp:54
std::enable_if< !is_shared_ptr< T >::value, typename std::remove_const< typename boost::remove_reference< T >::type >::type >::type parse_quantity(const std::string &text, const std::string &unit, const std::string &klass, const std::string &property)
Parse an arbitrary quantity.
Definition: Parse.h:252