39 #ifndef OME_XML_MODEL_ENUMS_UNITSLENGTHCONVERT_H
40 #define OME_XML_MODEL_ENUMS_UNITSLENGTHCONVERT_H
42 #include <boost/preprocessor.hpp>
46 #include <ome/xml/model/enums/UnitsLength.h>
47 #include <ome/xml/model/primitives/Quantity.h>
60 using namespace ::ome::common::units;
61 using ::ome::xml::model::enums::UnitsLength;
63 #define OME_XML_MODEL_ENUMS_UNITSLENGTH_PROPERTY_LIST \
64 ((YOTTAMETER)(yottameter_quantity)(0)) \
65 ((ZETTAMETER)(zettameter_quantity)(0)) \
66 ((EXAMETER)(exameter_quantity)(0)) \
67 ((PETAMETER)(petameter_quantity)(0)) \
68 ((TERAMETER)(terameter_quantity)(0)) \
69 ((GIGAMETER)(gigameter_quantity)(0)) \
70 ((MEGAMETER)(megameter_quantity)(0)) \
71 ((KILOMETER)(kilometer_quantity)(0)) \
72 ((HECTOMETER)(hectometer_quantity)(0)) \
73 ((DECAMETER)(decameter_quantity)(0)) \
74 ((METER)(meter_quantity)(0)) \
75 ((DECIMETER)(decimeter_quantity)(0)) \
76 ((CENTIMETER)(centimeter_quantity)(0)) \
77 ((MILLIMETER)(millimeter_quantity)(0)) \
78 ((MICROMETER)(micrometer_quantity)(0)) \
79 ((NANOMETER)(nanometer_quantity)(0)) \
80 ((PICOMETER)(picometer_quantity)(0)) \
81 ((FEMTOMETER)(femtometer_quantity)(0)) \
82 ((ATTOMETER)(attometer_quantity)(0)) \
83 ((ZEPTOMETER)(zeptometer_quantity)(0)) \
84 ((YOCTOMETER)(yoctometer_quantity)(0)) \
85 ((ANGSTROM)(angstrom_quantity)(0)) \
86 ((THOU)(thou_quantity)(0)) \
87 ((LINE)(line_quantity)(0)) \
88 ((INCH)(inch_quantity)(0)) \
89 ((FOOT)(foot_quantity)(0)) \
90 ((YARD)(yard_quantity)(0)) \
91 ((MILE)(mile_quantity)(0)) \
92 ((ASTRONOMICALUNIT)(astronomical_unit_quantity)(0)) \
93 ((LIGHTYEAR)(light_year_quantity)(0)) \
94 ((PARSEC)(parsec_quantity)(0)) \
95 ((POINT)(point_quantity)(0)) \
96 ((PIXEL)(pixel_quantity)(1)) \
97 ((REFERENCEFRAME)(reference_frame_quantity)(2))
105 #define OME_XML_MODEL_ENUMS_UNITSLENGTH_UNIT_CASE(maR, maProperty, maType) \
107 struct LengthProperties<UnitsLength::BOOST_PP_SEQ_ELEM(0, maType)> \
109 typedef BOOST_PP_SEQ_ELEM(1, maType) quantity_type; \
110 static const int system = BOOST_PP_SEQ_ELEM(2, maType); \
113 BOOST_PP_SEQ_FOR_EACH(OME_XML_MODEL_ENUMS_UNITSLENGTH_UNIT_CASE, %%, OME_XML_MODEL_ENUMS_UNITSLENGTH_PROPERTY_LIST)
115 #undef OME_XML_MODEL_ENUMS_UNITSLENGTH_UNIT_CASE
116 #undef OME_XML_MODEL_ENUMS_UNITSLENGTH_PROPERTY_LIST
121 template<
int U1,
int U2>
129 template<
typename Q,
int Src,
int Dest>
131 typename boost::enable_if_c<
135 length_convert_src_dest(
typename Q::value_type v,
136 typename Q::unit_type dest)
139 return Q(quantity_cast<typename Q::value_type>(d), dest);
143 template<
typename Q,
int Src,
int Dest>
145 typename boost::disable_if_c<
146 LengthConversion<Src, Dest>::valid,
149 length_convert_src_dest(
typename Q::value_type ,
150 typename Q::unit_type )
152 throw std::logic_error(
"Unit conversion failed: incompatible unit systems");
159 # pragma GCC diagnostic push
160 # pragma GCC diagnostic ignored "-Wswitch-default"
163 #define OME_XML_MODEL_ENUMS_UNITSLENGTH_DEST_UNIT_CASE(maR, maProperty, maType) \
164 case UnitsLength::maType: \
166 maProperty = length_convert_src_dest<Q, Src, UnitsLength::maType>(value, dest); \
170 template<
typename Q,
int Src>
172 length_convert_dest(
typename Q::value_type value,
173 typename Q::unit_type dest)
179 BOOST_PP_SEQ_FOR_EACH(OME_XML_MODEL_ENUMS_UNITSLENGTH_DEST_UNIT_CASE, q, OME_XML_MODEL_ENUMS_UNITSLENGTH_VALUES);
185 #undef OME_XML_MODEL_ENUMS_UNITSLENGTH_DEST_UNIT_CASE
188 # pragma GCC diagnostic pop
197 # pragma GCC diagnostic push
198 # pragma GCC diagnostic ignored "-Wswitch-default"
201 #define OME_XML_MODEL_ENUMS_UNITSLENGTH_SRC_UNIT_CASE(maR, maProperty, maType) \
202 case ome::xml::model::enums::UnitsLength::maType: \
203 maProperty = detail::length_convert_dest<Quantity<ome::xml::model::enums::UnitsLength>, ome::xml::model::enums::UnitsLength::maType>(quantity.getValue(), unit); \
207 template<
typename Value>
220 BOOST_PP_SEQ_FOR_EACH(OME_XML_MODEL_ENUMS_UNITSLENGTH_SRC_UNIT_CASE, q, OME_XML_MODEL_ENUMS_UNITSLENGTH_VALUES);
227 #undef OME_XML_MODEL_ENUMS_UNITSLENGTH_SRC_UNIT_CASE
230 # pragma GCC diagnostic pop
238 #endif // OME_XML_MODEL_ENUMS_UNITSLENGTHCONVERT_H
UnitsElectricPotential enumeration.
Definition: UnitsElectricPotential.h:74
static const bool valid
Is the conversion valid?
Definition: UnitsLengthConvert.h:125
Quantity< Unit, Value > operator()(const Quantity< Unit, Value > &quantity, typename Quantity< Unit, Value >::unit_type unit) const
Convert quantity to another unit.
Test if a given conversion is valid.
Definition: UnitsLengthConvert.h:122
unit_type getUnit() const
Get the unit for this quantity.
Definition: Quantity.h:131
Convert a quantity to a different unit.
Definition: Quantity.h:267
Map a given UnitsLength enum to the corresponding language types.
Definition: UnitsLengthConvert.h:103
A quantity of a defined unit.
Definition: Quantity.h:57
UnitsLength enumeration.
Definition: UnitsLength.h:74