isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
GDALDataTypeUtil.h
1 #pragma once
2 
3 #include <cstdint>
4 #include <complex>
5 #include <gdal_priv.h>
6 #include <type_traits>
7 
8 // forward declare thrust::complex
9 namespace thrust {
10  template<typename> struct complex;
11 }
12 
13 namespace isce3 { namespace io { namespace gdal { namespace detail {
14 
15 template<GDALDataType DataType>
16 struct GDT {
17  static constexpr GDALDataType datatype = DataType;
18 };
19 
20 template<typename T>
21 struct Type2GDALDataType : public GDT<GDT_Unknown> {};
22 
23 // char is always a single byte
24 template<> struct Type2GDALDataType<char> : public GDT<GDT_Byte> {};
25 template<> struct Type2GDALDataType<signed char> : public GDT<GDT_Byte> {};
26 template<> struct Type2GDALDataType<unsigned char> : public GDT<GDT_Byte> {};
27 
28 // fixed-size integer types
29 template<> struct Type2GDALDataType<std::int16_t> : public GDT<GDT_Int16> {};
30 template<> struct Type2GDALDataType<std::int32_t> : public GDT<GDT_Int32> {};
31 
32 // fixed-size unsigned integer types
33 template<> struct Type2GDALDataType<std::uint16_t> : public GDT<GDT_UInt16> {};
34 template<> struct Type2GDALDataType<std::uint32_t> : public GDT<GDT_UInt32> {};
35 
36 // floating point types
37 template<> struct Type2GDALDataType<float> : public GDT<GDT_Float32> {};
38 template<> struct Type2GDALDataType<double> : public GDT<GDT_Float64> {};
39 
40 // complex floating point types
41 template<> struct Type2GDALDataType<std::complex<float>> : public GDT<GDT_CFloat32> {};
42 template<> struct Type2GDALDataType<std::complex<double>> : public GDT<GDT_CFloat64> {};
43 
44 // thrust::complex floating point types
45 template<> struct Type2GDALDataType<thrust::complex<float>> : public GDT<GDT_CFloat32> {};
46 template<> struct Type2GDALDataType<thrust::complex<double>> : public GDT<GDT_CFloat64> {};
47 
48 constexpr
49 std::size_t getSize(GDALDataType datatype)
50 {
51  switch (datatype) {
52  case GDT_Byte : return sizeof(unsigned char);
53  case GDT_UInt16 : return sizeof(std::uint16_t);
54  case GDT_Int16 : return sizeof(std::int16_t);
55  case GDT_UInt32 : return sizeof(std::uint32_t);
56  case GDT_Int32 : return sizeof(std::int32_t);
57  case GDT_Float32 : return sizeof(float);
58  case GDT_Float64 : return sizeof(double);
59  case GDT_CFloat32 : return sizeof(std::complex<float>);
60  case GDT_CFloat64 : return sizeof(std::complex<double>);
61  default : return 0;
62  }
63 }
64 
65 }}}}
Definition: GDALDataTypeUtil.h:16
Definition: GDALDataTypeUtil.h:10
Definition: GDALDataTypeUtil.h:21

Generated for ISCE3.0 by doxygen 1.8.5.