@@ -203,12 +203,6 @@ class Attributable
203203 std::shared_ptr< A_MAP > m_attributes;
204204}; // Attributable
205205
206-
207- void
208- warnWrongDtype (std::string const & key,
209- Datatype store,
210- Datatype request);
211-
212206// TODO explicitly instanciate Attributable::setAttribute for all T in Datatype
213207template < typename T >
214208inline bool
@@ -244,96 +238,21 @@ Attributable::setAttribute(std::string const& key, char const value[])
244238 return this ->setAttribute (key, std::string (value));
245239}
246240
247- extern template
248- float
249- Attributable::readFloatingpoint (std::string const & key) const ;
250-
251- extern template
252- double
253- Attributable::readFloatingpoint (std::string const & key) const ;
254-
255- extern template
256- long double
257- Attributable::readFloatingpoint (std::string const & key) const ;
258-
259241template < typename T >
260242inline T
261243Attributable::readFloatingpoint (std::string const & key) const
262244{
263245 static_assert (std::is_floating_point< T >::value, " Type of attribute must be floating point" );
264246
265- T t{0 };
266- Attribute a = getAttribute (key);
267- Datatype target_dtype = determineDatatype< T >();
268- if ( a.dtype == target_dtype )
269- t = a.get < T >();
270- else
271- {
272- warnWrongDtype (key, a.dtype , target_dtype);
273- using DT = Datatype;
274- switch ( a.dtype )
275- {
276- case DT::FLOAT:
277- t = static_cast < T >(a.get < float >());
278- break ;
279- case DT::DOUBLE:
280- t = static_cast < T >(a.get < double >());
281- break ;
282- case DT::LONG_DOUBLE:
283- t = static_cast < T >(a.get < long double >());
284- break ;
285- default :
286- throw std::runtime_error (" Unknown floating point datatype." );
287- }
288- }
289- return t;
247+ return getAttribute (key).get < T >();
290248}
291249
292- extern template
293- std::vector< float >
294- Attributable::readVectorFloatingpoint (std::string const & key) const ;
295-
296- extern template
297- std::vector< double >
298- Attributable::readVectorFloatingpoint (std::string const & key) const ;
299-
300- extern template
301- std::vector< long double >
302- Attributable::readVectorFloatingpoint (std::string const & key) const ;
303-
304250template < typename T >
305251inline std::vector< T >
306252Attributable::readVectorFloatingpoint (std::string const & key) const
307253{
308254 static_assert (std::is_floating_point< T >::value, " Type of attribute must be floating point" );
309255
310- std::vector< T > vt{};
311- Attribute a = getAttribute (key);
312- Datatype target_dtype = determineDatatype< std::vector< T > >();
313- if ( a.dtype == target_dtype )
314- vt = a.get < std::vector< T > >();
315- else
316- {
317- warnWrongDtype (key, a.dtype , target_dtype);
318- using DT = Datatype;
319- switch ( a.dtype )
320- {
321- case DT::VEC_FLOAT:
322- for ( auto const & val : a.get < std::vector< float > >() )
323- vt.push_back (static_cast < T >(val));
324- break ;
325- case DT::VEC_DOUBLE:
326- for ( auto const & val : a.get < std::vector< double > >() )
327- vt.push_back (static_cast < T >(val));
328- break ;
329- case DT::VEC_LONG_DOUBLE:
330- for ( auto const & val : a.get < std::vector< long double > >() )
331- vt.push_back (static_cast < T >(val));
332- break ;
333- default :
334- throw std::runtime_error (" Unknown floating point datatype." );
335- }
336- }
337- return vt;
256+ return getAttribute (key).get < std::vector< T > >();
338257}
339258} // namespace openPMD
0 commit comments