My Project
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 <cstdint>
25#include <vector>
26#include <mia/core/defines.hh>
27#include <miaconfig.h>
28
29
31
33 static const int attr_unknown = 0;
34 static const int attr_bool = 1;
35 static const int attr_uchar = 2;
36 static const int attr_schar = 3;
37 static const int attr_ushort = 4;
38 static const int attr_sshort = 5;
39 static const int attr_uint = 6;
40 static const int attr_sint = 7;
41 static const int attr_ulong = 8;
42 static const int attr_slong = 9;
43 static const int attr_float = 10;
44 static const int attr_double = 11;
45 static const int attr_string = 12;
46
47 static const int vector_bit = 0x80000000;
48
49 static int scalar_type(int type)
50 {
51 return type & scalar_mask;
52 };
53
54 static bool is_vector(int type)
55 {
56 return type & vector_bit;
57 }
58
59private:
60 static const int scalar_mask = 0x7FFFFFFF;
61
62};
63
64template <typename T>
67};
68
69#define ATTR_TYPEID(T, ID) \
70 template <> \
71 struct attribute_type<T> : public EAttributeType{ \
72 static const int value = ID; \
73 };
74
75ATTR_TYPEID(bool, attr_bool);
76ATTR_TYPEID(uint8_t, attr_uchar);
77ATTR_TYPEID(int8_t, attr_schar);
78
79ATTR_TYPEID(uint16_t, attr_ushort);
80ATTR_TYPEID(int16_t, attr_sshort);
81
82ATTR_TYPEID(uint32_t, attr_uint);
83ATTR_TYPEID(int32_t, attr_sint);
84
85ATTR_TYPEID(uint64_t, attr_ulong);
86ATTR_TYPEID(int64_t, attr_slong);
87
88ATTR_TYPEID(float, attr_float);
89ATTR_TYPEID(double, attr_double);
90
91ATTR_TYPEID(std::string, attr_string);
92
93#undef ATTR_TYPEID
94
95template <typename T>
96struct attribute_type<std::vector<T>> : public EAttributeType {
98};
99
101
102#endif
#define ATTR_TYPEID(T, ID)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
static const int attr_ushort
static const int attr_bool
static const int attr_unknown
static const int attr_schar
static bool is_vector(int type)
static const int attr_uint
static int scalar_type(int type)
static const int attr_float
static const int attr_string
static const int attr_sint
static const int attr_ulong
static const int attr_uchar
static const int vector_bit
static const int attr_slong
static const int attr_sshort
static const int attr_double
static const int value