ome-xml 5.2.3

UnitsPressureConvert.h
1 /*
2 * #%L
3 * OME-XML C++ library for working with OME-XML metadata structures.
4 * %%
5 * Copyright © 2016 Open Microscopy Environment:
6 * - Massachusetts Institute of Technology
7 * - National Institutes of Health
8 * - University of Dundee
9 * - Board of Regents of the University of Wisconsin-Madison
10 * - Glencoe Software, Inc.
11 * %%
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * The views and conclusions contained in the software and documentation are
34 * those of the authors and should not be interpreted as representing official
35 * policies, either expressed or implied, of any organization.
36 * #L%
37 */
38
39 #ifndef OME_XML_MODEL_ENUMS_UNITSPRESSURECONVERT_H
40 #define OME_XML_MODEL_ENUMS_UNITSPRESSURECONVERT_H
41
42 #include <boost/preprocessor.hpp>
43
44 #include <ome/common/units/pressure.h>
45
46 #include <ome/xml/model/enums/UnitsPressure.h>
47 #include <ome/xml/model/primitives/Quantity.h>
48
49 #ifdef _MSC_VER
50 #pragma push_macro("PASCAL")
51 #undef PASCAL
52 #endif
53
54 namespace ome
55 {
56 namespace xml
57 {
58 namespace model
59 {
60 namespace primitives
61 {
62 namespace detail
63 {
64
65 using namespace ::ome::common::units;
66 using ::ome::xml::model::enums::UnitsPressure;
67
68 #define OME_XML_MODEL_ENUMS_UNITSPRESSURE_PROPERTY_LIST \
69 ((YOTTAPASCAL)(yottapascal_quantity)) \
70 ((ZETTAPASCAL)(zettapascal_quantity)) \
71 ((EXAPASCAL)(exapascal_quantity)) \
72 ((PETAPASCAL)(petapascal_quantity)) \
73 ((TERAPASCAL)(terapascal_quantity)) \
74 ((GIGAPASCAL)(gigapascal_quantity)) \
75 ((MEGAPASCAL)(megapascal_quantity)) \
76 ((KILOPASCAL)(kilopascal_quantity)) \
77 ((HECTOPASCAL)(hectopascal_quantity)) \
78 ((DECAPASCAL)(decapascal_quantity)) \
79 ((PASCAL)(pascal_quantity)) \
80 ((DECIPASCAL)(decipascal_quantity)) \
81 ((CENTIPASCAL)(centipascal_quantity)) \
82 ((MILLIPASCAL)(millipascal_quantity)) \
83 ((MICROPASCAL)(micropascal_quantity)) \
84 ((NANOPASCAL)(nanopascal_quantity)) \
85 ((PICOPASCAL)(picopascal_quantity)) \
86 ((FEMTOPASCAL)(femtopascal_quantity)) \
87 ((ATTOPASCAL)(attopascal_quantity)) \
88 ((ZEPTOPASCAL)(zeptopascal_quantity)) \
89 ((YOCTOPASCAL)(yoctopascal_quantity)) \
90 ((BAR)(bar_quantity)) \
91 ((MEGABAR)(megabar_quantity)) \
92 ((KILOBAR)(kilobar_quantity)) \
93 ((DECIBAR)(decibar_quantity)) \
94 ((CENTIBAR)(centibar_quantity)) \
95 ((MILLIBAR)(millibar_quantity)) \
96 ((ATMOSPHERE)(atmosphere_quantity)) \
97 ((PSI)(psi_quantity)) \
98 ((TORR)(torr_quantity)) \
99 ((MILLITORR)(millitorr_quantity)) \
100 ((MMHG)(mmHg_quantity))
101
105 template<int>
106 struct PressureProperties;
107
108 #define OME_XML_MODEL_ENUMS_UNITSPRESSURE_UNIT_CASE(maR, maProperty, maType) \
109 template<> \
110 struct PressureProperties<UnitsPressure::BOOST_PP_SEQ_ELEM(0, maType)> \
111 { \
112 typedef BOOST_PP_SEQ_ELEM(1, maType) quantity_type; \
113 };
114
115 BOOST_PP_SEQ_FOR_EACH(OME_XML_MODEL_ENUMS_UNITSPRESSURE_UNIT_CASE, %%, OME_XML_MODEL_ENUMS_UNITSPRESSURE_PROPERTY_LIST)
116
117 #undef OME_XML_MODEL_ENUMS_UNITSPRESSURE_UNIT_CASE
118 #undef OME_XML_MODEL_ENUMS_UNITSPRESSURE_PROPERTY_LIST
119
120 // Convert two units
121 template<typename Q, int Src, int Dest>
122 Q
123 pressure_convert_src_dest(typename Q::value_type v,
124 typename Q::unit_type dest)
125 {
126 typename PressureProperties<Dest>::quantity_type d(PressureProperties<Src>::quantity_type::from_value(v));
127 return Q(quantity_cast<typename Q::value_type>(d), dest);
128 }
129
130 // No switch default to avoid -Wunreachable-code errors.
131 // However, this then makes -Wswitch-default complain. Disable
132 // temporarily.
133 #ifdef __GNUC__
134 # pragma GCC diagnostic push
135 # pragma GCC diagnostic ignored "-Wswitch-default"
136 #endif
137
138 #define OME_XML_MODEL_ENUMS_UNITSPRESSURE_DEST_UNIT_CASE(maR, maProperty, maType) \
139 case UnitsPressure::maType: \
140 { \
141 maProperty = pressure_convert_src_dest<Q, Src, UnitsPressure::maType>(value, dest); \
142 } \
143 break;
144
145 template<typename Q, int Src>
146 Q
147 pressure_convert_dest(typename Q::value_type value,
148 typename Q::unit_type dest)
149 {
150 Q q;
151
152 switch(dest)
153 {
154 BOOST_PP_SEQ_FOR_EACH(OME_XML_MODEL_ENUMS_UNITSPRESSURE_DEST_UNIT_CASE, q, OME_XML_MODEL_ENUMS_UNITSPRESSURE_VALUES);
155 }
156
157 return q;
158 }
159
160 #undef OME_XML_MODEL_ENUMS_UNITSPRESSURE_DEST_UNIT_CASE
161
162 #ifdef __GNUC__
163 # pragma GCC diagnostic pop
164 #endif
165
166 }
167
168 // No switch default to avoid -Wunreachable-code errors.
169 // However, this then makes -Wswitch-default complain. Disable
170 // temporarily.
171 #ifdef __GNUC__
172 # pragma GCC diagnostic push
173 # pragma GCC diagnostic ignored "-Wswitch-default"
174 #endif
175
176 #define OME_XML_MODEL_ENUMS_UNITSPRESSURE_SRC_UNIT_CASE(maR, maProperty, maType) \
177 case ome::xml::model::enums::UnitsPressure::maType: \
178 maProperty = detail::pressure_convert_dest<Quantity<ome::xml::model::enums::UnitsPressure>, ome::xml::model::enums::UnitsPressure::maType>(quantity.getValue(), unit); \
179 break;
180
182 template<typename Value>
183 struct QuantityConverter<ome::xml::model::enums::UnitsPressure, Value>
184 {
186 inline
187 Quantity<ome::xml::model::enums::UnitsPressure, Value>
188 operator() (const Quantity<ome::xml::model::enums::UnitsPressure, Value>& quantity,
189 typename Quantity<ome::xml::model::enums::UnitsPressure, Value>::unit_type unit) const
190 {
191 Quantity<ome::xml::model::enums::UnitsPressure, Value> q;
192
193 switch(quantity.getUnit())
194 {
195 BOOST_PP_SEQ_FOR_EACH(OME_XML_MODEL_ENUMS_UNITSPRESSURE_SRC_UNIT_CASE, q, OME_XML_MODEL_ENUMS_UNITSPRESSURE_VALUES);
196 }
197
198 return q;
199 }
200 };
201
202 #undef OME_XML_MODEL_ENUMS_UNITSPRESSURE_SRC_UNIT_CASE
203
204 #ifdef __GNUC__
205 # pragma GCC diagnostic pop
206 #endif
207
208 }
209 }
210 }
211 }
212
213 #ifdef _MSC_VER
214 #pragma pop_macro("PASCAL")
215 #endif
216
217 #endif // OME_XML_MODEL_ENUMS_UNITSPRESSURECONVERT_H
218
219 /*
220 * Local Variables:
221 * mode:C++
222 * End:
223 */
ome::xml::model::enums::UnitsPressure
UnitsPressure enumeration.
Definition: UnitsPressure.h:79
ome::xml::model::enums::UnitsElectricPotential
UnitsElectricPotential enumeration.
Definition: UnitsElectricPotential.h:74
pressure.h
ome
Open Microscopy Environment C++ implementation.
ome::xml::model::primitives::QuantityConverter
Convert a quantity to a different unit.
Definition: Quantity.h:267
ome::xml::model::primitives::detail::PressureProperties
Map a given UnitsPressure enum to the corresponding language types.
Definition: UnitsPressureConvert.h:106
ome::xml::model::primitives::Quantity
A quantity of a defined unit.
Definition: Quantity.h:57
ome::common::units
ome::xml::model::primitives::Quantity::getUnit
unit_type getUnit() const
Get the unit for this quantity.
Definition: Quantity.h:131