23 #include "openPMD/auxiliary/Variant.hpp" 24 #include "openPMD/Datatype.hpp" 33 #include <type_traits> 53 short, int, long, long long,
54 unsigned short, unsigned int, unsigned long, unsigned long long,
55 float, double, long double,
56 std::complex< float >, std::complex< double >, std::complex< long double >,
62 std::vector< long long >,
63 std::vector< unsigned char >,
64 std::vector< unsigned short >,
65 std::vector< unsigned int >,
66 std::vector< unsigned long >,
67 std::vector< unsigned long long >,
69 std::vector< double >,
70 std::vector< long double >,
71 std::vector< std::complex< float > >,
72 std::vector< std::complex< double > >,
73 std::vector< std::complex< long double > >,
74 std::vector< std::string >,
75 std::array< double, 7 >,
91 template<
typename U >
95 template< typename T, typename U, bool isConvertible = std::is_convertible<T, U>::value >
98 template<
typename T,
typename U >
101 template<
typename PV >
104 throw std::runtime_error(
"getCast: no cast possible.");
108 template<
typename T,
typename U >
111 template<
typename PV >
112 U operator()( PV pv )
114 return static_cast< U
>( *pv );
118 template<
typename T,
typename U >
121 static constexpr
bool convertible = std::is_convertible<T, U>::value;
123 template<
typename PV,
typename UU = U >
124 auto operator()( PV pv )
125 ->
typename std::enable_if< convertible, std::vector< UU > >::type
128 u.reserve( pv->size() );
129 std::copy( pv->begin(), pv->end(), std::back_inserter(u) );
133 template<
typename PV,
typename UU = U >
134 auto operator()( PV )
135 ->
typename std::enable_if< !convertible, std::vector< UU > >::type
137 throw std::runtime_error(
"getCast: no vector cast possible.");
147 template<
typename U >
153 if(
auto pvalue_c = variantSrc::get_if< char >( &v ) )
155 else if(
auto pvalue_uc = variantSrc::get_if< unsigned char >( &v ) )
157 else if(
auto pvalue_s = variantSrc::get_if< short >( &v ) )
159 else if(
auto pvalue_i = variantSrc::get_if< int >( &v ) )
161 else if(
auto pvalue_l = variantSrc::get_if< long >( &v ) )
163 else if(
auto pvalue_ll = variantSrc::get_if< long long >( &v ) )
165 else if(
auto pvalue_us = variantSrc::get_if< unsigned short >( &v ) )
167 else if(
auto pvalue_ui = variantSrc::get_if< unsigned int >( &v ) )
169 else if(
auto pvalue_ul = variantSrc::get_if< unsigned long >( &v ) )
171 else if(
auto pvalue_ull = variantSrc::get_if< unsigned long long >( &v ) )
173 else if(
auto pvalue_f = variantSrc::get_if< float >( &v ) )
175 else if(
auto pvalue_d = variantSrc::get_if< double >( &v ) )
177 else if(
auto pvalue_ld = variantSrc::get_if< long double >( &v ) )
179 else if(
auto pvalue_cf = variantSrc::get_if< std::complex< float > >( &v ) )
180 return DoConvert<std::complex< float >, U>{}(pvalue_cf);
181 else if(
auto pvalue_cd = variantSrc::get_if< std::complex< double > >( &v ) )
182 return DoConvert<std::complex< double >, U>{}(pvalue_cd);
183 else if(
auto pvalue_cld = variantSrc::get_if< std::complex< long double > >( &v ) )
184 return DoConvert<std::complex< long double >, U>{}(pvalue_cld);
185 else if(
auto pvalue_str = variantSrc::get_if< std::string >( &v ) )
188 else if(
auto pvalue_vc = variantSrc::get_if< std::vector< char > >( &v ) )
189 return DoConvert<std::vector< char >, U>{}(pvalue_vc);
190 else if(
auto pvalue_vuc = variantSrc::get_if< std::vector< unsigned char > >( &v ) )
191 return DoConvert<std::vector< unsigned char >, U>{}(pvalue_vuc);
192 else if(
auto pvalue_vs = variantSrc::get_if< std::vector< short > >( &v ) )
193 return DoConvert<std::vector< short >, U>{}(pvalue_vs);
194 else if(
auto pvalue_vi = variantSrc::get_if< std::vector< int > >( &v ) )
195 return DoConvert<std::vector< int >, U>{}(pvalue_vi);
196 else if(
auto pvalue_vl = variantSrc::get_if< std::vector< long > >( &v ) )
197 return DoConvert<std::vector< long >, U>{}(pvalue_vl);
198 else if(
auto pvalue_vll = variantSrc::get_if< std::vector< long long > >( &v ) )
199 return DoConvert<std::vector< long long >, U>{}(pvalue_vll);
200 else if(
auto pvalue_vus = variantSrc::get_if< std::vector< unsigned short > >( &v ) )
201 return DoConvert<std::vector< unsigned short >, U>{}(pvalue_vus);
202 else if(
auto pvalue_vui = variantSrc::get_if< std::vector< unsigned int > >( &v ) )
203 return DoConvert<std::vector< unsigned int >, U>{}(pvalue_vui);
204 else if(
auto pvalue_vul = variantSrc::get_if< std::vector< unsigned long > >( &v ) )
205 return DoConvert<std::vector< unsigned long >, U>{}(pvalue_vul);
206 else if(
auto pvalue_vull = variantSrc::get_if< std::vector< unsigned long long > >( &v ) )
207 return DoConvert<std::vector< unsigned long long >, U>{}(pvalue_vull);
208 else if(
auto pvalue_vf = variantSrc::get_if< std::vector< float > >( &v ) )
209 return DoConvert<std::vector< float >, U>{}(pvalue_vf);
210 else if(
auto pvalue_vd = variantSrc::get_if< std::vector< double > >( &v ) )
211 return DoConvert<std::vector< double >, U>{}(pvalue_vd);
212 else if(
auto pvalue_vld = variantSrc::get_if< std::vector< long double > >( &v ) )
213 return DoConvert<std::vector< long double >, U>{}(pvalue_vld);
214 else if(
auto pvalue_vcf = variantSrc::get_if< std::vector< std::complex< float > > >( &v ) )
215 return DoConvert<std::vector< std::complex< float > >, U>{}(pvalue_vcf);
216 else if(
auto pvalue_vcd = variantSrc::get_if< std::vector< std::complex< double > > >( &v ) )
217 return DoConvert<std::vector< std::complex< double > >, U>{}(pvalue_vcd);
218 else if(
auto pvalue_vcld = variantSrc::get_if< std::vector< std::complex< long double > > >( &v ) )
219 return DoConvert<std::vector< std::complex< long double > >, U>{}(pvalue_vcld);
220 else if(
auto pvalue_vstr = variantSrc::get_if< std::vector< std::string > >( &v ) )
221 return DoConvert<std::vector< std::string >, U>{}(pvalue_vstr);
223 else if(
auto pvalue_vad = variantSrc::get_if< std::array< double, 7 > >( &v ) )
224 return DoConvert<std::array< double, 7 >, U>{}(pvalue_vad);
225 else if(
auto pvalue_b = variantSrc::get_if< bool >( &v ) )
228 throw std::runtime_error(
"getCast: unknown Datatype.");
231 template<
typename U >
234 return getCast< U >( Variant::getResource() );
openPMD::auxiliary::Variant< Datatype, char, unsigned char, short, int, long, long long, unsigned short, unsigned int, unsigned long, unsigned long long, float, double, long double, std::complex< float >, std::complex< double >, std::complex< long double >, std::string, std::vector< char >, std::vector< short >, std::vector< int >, std::vector< long >, std::vector< long long >, std::vector< unsigned char >, std::vector< unsigned short >, std::vector< unsigned int >, std::vector< unsigned long >, std::vector< unsigned long long >, std::vector< float >, std::vector< double >, std::vector< long double >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< std::complex< long double > >, std::vector< std::string >, std::array< double, 7 >, bool >::Variant Variant(resource r)
Construct a lightweight wrapper around a generic object that indicates the concrete datatype of the s...
Definition: Variant.hpp:51
U get() const
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.hpp:232
Definition: Attribute.hpp:96
Generic object to store a set of datatypes in without losing type safety.
Definition: Variant.hpp:38
U getCast(Attribute const &a)
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.hpp:149
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:50
Public definitions of openPMD-api.
Definition: Date.cpp:29
resource getResource() const
Retrieve the stored generic object.
Definition: Variant.hpp:72