attributetype.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_core_attributetype_hh
22 #define mia_core_attributetype_hh
23 
24 #include <vector>
25 #include <mia/core/defines.hh>
26 #include <miaconfig.h>
27 
28 
30 
32  static const int attr_unknown = 0;
33  static const int attr_bool = 1;
34  static const int attr_uchar = 2;
35  static const int attr_schar = 3;
36  static const int attr_ushort = 4;
37  static const int attr_sshort = 5;
38  static const int attr_uint = 6;
39  static const int attr_sint = 7;
40  static const int attr_ulong = 8;
41  static const int attr_slong = 9;
42  static const int attr_float = 10;
43  static const int attr_double = 11;
44  static const int attr_string = 12;
45 
46  static const int vector_bit = 0x80000000;
47 
48  static int scalar_type(int type) {
49  return type & scalar_mask;
50  };
51 
52  static bool is_vector(int type) {
53  return type & vector_bit;
54  }
55 
56 private:
57  static const int scalar_mask =0x7FFFFFFF;
58 
59 };
60 
61 template <typename T>
62 struct attribute_type : public EAttributeType {
63  static const int value = EAttributeType::attr_unknown;
64 };
65 
66 #define ATTR_TYPEID(T, ID) \
67  template <> \
68  struct attribute_type<T> : public EAttributeType{ \
69  static const int value = ID; \
70  };
71 
72 ATTR_TYPEID(bool, attr_bool);
73 ATTR_TYPEID(uint8_t, attr_uchar);
74 ATTR_TYPEID(int8_t, attr_schar);
75 
76 ATTR_TYPEID(uint16_t, attr_ushort);
77 ATTR_TYPEID(int16_t, attr_sshort);
78 
79 ATTR_TYPEID(uint32_t, attr_uint);
80 ATTR_TYPEID(int32_t, attr_sint);
81 
82 ATTR_TYPEID(uint64_t, attr_ulong);
83 ATTR_TYPEID(int64_t, attr_slong);
84 
85 ATTR_TYPEID(float, attr_float);
86 ATTR_TYPEID(double, attr_double);
87 
88 ATTR_TYPEID(std::string, attr_string);
89 
90 #undef ATTR_TYPEID
91 
92 template <typename T>
93 struct attribute_type<std::vector<T>> : public EAttributeType{
95 };
96 
98 
99 #endif
static const int vector_bit
static const int attr_double
static const int attr_unknown
static const int attr_ushort
static const int attr_uint
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
static const int attr_schar
static const int attr_ulong
static const int attr_slong
static bool is_vector(int type)
static const int attr_float
static const int attr_string
static const int attr_sint
static const int attr_bool
static const int attr_sshort
#define ATTR_TYPEID(T, ID)
static const int attr_uchar
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
static int scalar_type(int type)