19 #if __cplusplus >= 201703L 28 enum class byte : unsigned char
43 static const kind_t KIND_BYTE = 1;
44 static const kind_t KIND_INT32 = -4;
45 static const kind_t KIND_INT64 = -8;
46 static const kind_t KIND_REAL32 = 4;
47 static const kind_t KIND_REAL64 = 8;
48 static const kind_t KIND_UINT64 = -16;
50 template <
typename DATATYPE>
60 template <
typename DATATYPE>
62 template <
typename DATATYPE>
63 static kind_t kind(
const DATATYPE& );
65 template <
typename DATATYPE>
66 static std::string str();
67 template <
typename DATATYPE>
68 static std::string str(
const DATATYPE );
70 static kind_t str_to_kind(
const std::string& );
71 static std::string kind_to_str( kind_t );
72 static bool kind_valid( kind_t );
75 static std::string byte_str() {
return "byte"; }
76 static std::string int32_str() {
return "int32"; }
77 static std::string int64_str() {
return "int64"; }
78 static std::string real32_str() {
return "real32"; }
79 static std::string real64_str() {
return "real64"; }
80 static std::string uint64_str() {
return "uint64"; }
82 [[noreturn]]
static void throw_not_recognised( kind_t );
83 [[noreturn]]
static void throw_not_recognised( std::string datatype );
89 std::string str()
const {
return kind_to_str( kind_ ); }
90 kind_t kind()
const {
return kind_; }
91 size_t size()
const {
return ( kind_ == KIND_UINT64 ) ? 8 : std::abs( kind_ ); }
95 friend bool operator==(
DataType dt, kind_t kind );
96 friend bool operator!=(
DataType dt, kind_t kind );
97 friend bool operator==( kind_t kind,
DataType dt );
98 friend bool operator!=( kind_t kind,
DataType dt2 );
105 inline std::string DataType::str<std::byte>() {
109 inline std::string DataType::str<const std::byte>() {
113 inline std::string DataType::str<int>() {
114 static_assert(
sizeof(
int ) == 4,
"" );
118 inline std::string DataType::str<const int>() {
119 static_assert(
sizeof(
int ) == 4,
"" );
123 inline std::string DataType::str<long>() {
124 static_assert(
sizeof(
long ) == 8,
"" );
128 inline std::string DataType::str<const long>() {
129 static_assert(
sizeof(
long ) == 8,
"" );
133 inline std::string DataType::str<long long>() {
134 static_assert(
sizeof(
long long ) == 8,
"" );
138 inline std::string DataType::str<const long long>() {
139 static_assert(
sizeof(
long long ) == 8,
"" );
143 inline std::string DataType::str<float>() {
144 static_assert(
sizeof(
float ) == 4,
"" );
148 inline std::string DataType::str<const float>() {
149 static_assert(
sizeof(
float ) == 4,
"" );
153 inline std::string DataType::str<double>() {
154 static_assert(
sizeof(
double ) == 8,
"" );
158 inline std::string DataType::str<const double>() {
159 static_assert(
sizeof(
double ) == 8,
"" );
163 inline std::string DataType::str<unsigned long>() {
164 static_assert(
sizeof(
unsigned long ) == 8,
"" );
168 inline std::string DataType::str<const unsigned long>() {
169 static_assert(
sizeof(
unsigned long ) == 8,
"" );
174 inline std::string DataType::str<unsigned long long>() {
175 static_assert(
sizeof(
unsigned long long ) == 8,
"" );
179 inline std::string DataType::str<const unsigned long long>() {
180 static_assert(
sizeof(
unsigned long long ) == 8,
"" );
184 inline std::string DataType::str(
const int& ) {
188 inline std::string DataType::str(
const long& ) {
192 inline std::string DataType::str(
const long long& ) {
193 return str<long long>();
196 inline std::string DataType::str(
const unsigned long& ) {
197 return str<unsigned long>();
200 inline std::string DataType::str(
const unsigned long long& ) {
201 return str<unsigned long>();
204 inline std::string DataType::str(
const float& ) {
208 inline std::string DataType::str(
const double& ) {
209 return str<double>();
212 inline DataType::kind_t DataType::kind<std::byte>() {
213 static_assert(
sizeof( std::byte ) == 1,
"" );
217 inline DataType::kind_t DataType::kind<const std::byte>() {
218 static_assert(
sizeof( std::byte ) == 1,
"" );
222 inline DataType::kind_t DataType::kind<int>() {
223 static_assert(
sizeof(
int ) == 4,
"" );
227 inline DataType::kind_t DataType::kind<const int>() {
228 static_assert(
sizeof(
int ) == 4,
"" );
232 inline DataType::kind_t DataType::kind<long>() {
233 static_assert(
sizeof(
long ) == 8,
"" );
237 inline DataType::kind_t DataType::kind<const long>() {
238 static_assert(
sizeof(
long ) == 8,
"" );
242 inline DataType::kind_t DataType::kind<long long>() {
243 static_assert(
sizeof(
long long ) == 8,
"" );
247 inline DataType::kind_t DataType::kind<const long long>() {
248 static_assert(
sizeof(
long long ) == 8,
"" );
252 inline DataType::kind_t DataType::kind<unsigned long>() {
253 static_assert(
sizeof(
unsigned long ) == 8,
"" );
257 inline DataType::kind_t DataType::kind<const unsigned long>() {
258 static_assert(
sizeof(
unsigned long ) == 8,
"" );
262 inline DataType::kind_t DataType::kind<unsigned long long>() {
263 static_assert(
sizeof(
unsigned long long ) == 8,
"" );
267 inline DataType::kind_t DataType::kind<const unsigned long long>() {
268 static_assert(
sizeof(
unsigned long long ) == 8,
"" );
272 inline DataType::kind_t DataType::kind<float>() {
273 static_assert(
sizeof(
float ) == 4,
"" );
277 inline DataType::kind_t DataType::kind<const float>() {
278 static_assert(
sizeof(
float ) == 4,
"" );
282 inline DataType::kind_t DataType::kind<double>() {
283 static_assert(
sizeof(
double ) == 8,
"" );
287 inline DataType::kind_t DataType::kind<const double>() {
288 static_assert(
sizeof(
double ) == 8,
"" );
292 inline DataType::kind_t DataType::kind(
const int& ) {
296 inline DataType::kind_t DataType::kind(
const long& ) {
300 inline DataType::kind_t DataType::kind(
const unsigned long& ) {
301 return kind<unsigned long>();
304 inline DataType::kind_t DataType::kind(
const float& ) {
305 return kind<float>();
308 inline DataType::kind_t DataType::kind(
const double& ) {
309 return kind<double>();
312 inline DataType::kind_t DataType::str_to_kind(
const std::string& datatype ) {
313 if ( datatype ==
"int32" )
315 else if ( datatype ==
"int64" )
317 else if ( datatype ==
"uint64" )
319 else if ( datatype ==
"real32" )
321 else if ( datatype ==
"real64" )
323 else if ( datatype ==
"byte" ) {
327 throw_not_recognised( datatype );
330 inline std::string DataType::kind_to_str( kind_t kind ) {
345 throw_not_recognised( kind );
348 inline bool DataType::kind_valid( kind_t kind ) {
362 inline DataType::DataType(
const DataType& other ) : kind_( other.kind_ ) {}
364 inline DataType::DataType(
const std::string& datatype ) : kind_( str_to_kind( datatype ) ) {}
366 inline DataType::DataType(
long kind ) : kind_( kind ) {}
369 return dt1.kind_ == dt2.kind_;
373 return dt1.kind_ != dt2.kind_;
376 inline bool operator==(
DataType dt, DataType::kind_t kind ) {
377 return dt.kind_ == kind;
380 inline bool operator!=(
DataType dt, DataType::kind_t kind ) {
381 return dt.kind_ != kind;
384 inline bool operator==( DataType::kind_t kind,
DataType dt ) {
385 return dt.kind_ == kind;
388 inline bool operator!=( DataType::kind_t kind,
DataType dt ) {
389 return dt.kind_ != kind;
392 template <
typename DATATYPE>
393 inline DataType DataType::create() {
394 return DataType( DataType::kind<DATATYPE>() );
397 template <
typename DATATYPE>
399 return DataType( DataType::kind<DATATYPE>() );
Definition: DataType.h:22
Definition: DataType.h:40
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33