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 <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 {
50 return type & scalar_mask;
51 };
52
53 static bool is_vector(int type)
54 {
55 return type & vector_bit;
56 }
57
58private:
59 static const int scalar_mask = 0x7FFFFFFF;
60
61};
62
63template <typename T>
66};
67
68#define ATTR_TYPEID(T, ID) \
69 template <> \
70 struct attribute_type<T> : public EAttributeType{ \
71 static const int value = ID; \
72 };
73
74ATTR_TYPEID(bool, attr_bool);
75ATTR_TYPEID(uint8_t, attr_uchar);
76ATTR_TYPEID(int8_t, attr_schar);
77
78ATTR_TYPEID(uint16_t, attr_ushort);
79ATTR_TYPEID(int16_t, attr_sshort);
80
81ATTR_TYPEID(uint32_t, attr_uint);
82ATTR_TYPEID(int32_t, attr_sint);
83
84ATTR_TYPEID(uint64_t, attr_ulong);
85ATTR_TYPEID(int64_t, attr_slong);
86
87ATTR_TYPEID(float, attr_float);
88ATTR_TYPEID(double, attr_double);
89
90ATTR_TYPEID(std::string, attr_string);
91
92#undef ATTR_TYPEID
93
94template <typename T>
95struct attribute_type<std::vector<T>> : public EAttributeType {
97};
98
100
101#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