attributetype.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_core_attributetype_hh
#define mia_core_attributetype_hh
#include <cstdint>
#include <vector>
#include <mia/core/defines.hh>
#include <miaconfig.h>
NS_MIA_BEGIN
struct EAttributeType {
static const int attr_unknown = 0;
static const int attr_bool = 1;
static const int attr_uchar = 2;
static const int attr_schar = 3;
static const int attr_ushort = 4;
static const int attr_sshort = 5;
static const int attr_uint = 6;
static const int attr_sint = 7;
static const int attr_ulong = 8;
static const int attr_slong = 9;
static const int attr_float = 10;
static const int attr_double = 11;
static const int attr_string = 12;
static const int vector_bit = 0x80000000;
static int scalar_type(int type)
{
return type & scalar_mask;
};
static bool is_vector(int type)
{
return type & vector_bit;
}
private:
static const int scalar_mask = 0x7FFFFFFF;
};
template <typename T>
struct attribute_type : public EAttributeType {
static const int value = EAttributeType::attr_unknown;
};
#define ATTR_TYPEID(T, ID) \
template <> \
struct attribute_type<T> : public EAttributeType{ \
static const int value = ID; \
};
ATTR_TYPEID(bool, attr_bool);
ATTR_TYPEID(uint8_t, attr_uchar);
ATTR_TYPEID(int8_t, attr_schar);
ATTR_TYPEID(uint16_t, attr_ushort);
ATTR_TYPEID(int16_t, attr_sshort);
ATTR_TYPEID(uint32_t, attr_uint);
ATTR_TYPEID(int32_t, attr_sint);
ATTR_TYPEID(uint64_t, attr_ulong);
ATTR_TYPEID(int64_t, attr_slong);
ATTR_TYPEID(float, attr_float);
ATTR_TYPEID(double, attr_double);
ATTR_TYPEID(std::string, attr_string);
#undef ATTR_TYPEID
template <typename T>
struct attribute_type<std::vector<T>> : public EAttributeType {
static const int value = attribute_type<T>::value | EAttributeType::vector_bit;
};
NS_MIA_END
#endif
ATTR_TYPEID
#define ATTR_TYPEID(T, ID)
Definition attributetype.hh:69
type
defines.hh
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
std
Definition gsl_iterator.hh:324
EAttributeType
Definition attributetype.hh:32
EAttributeType::attr_ushort
static const int attr_ushort
Definition attributetype.hh:37
EAttributeType::attr_bool
static const int attr_bool
Definition attributetype.hh:34
EAttributeType::attr_unknown
static const int attr_unknown
Definition attributetype.hh:33
EAttributeType::attr_schar
static const int attr_schar
Definition attributetype.hh:36
EAttributeType::is_vector
static bool is_vector(int type)
Definition attributetype.hh:54
EAttributeType::attr_uint
static const int attr_uint
Definition attributetype.hh:39
EAttributeType::scalar_type
static int scalar_type(int type)
Definition attributetype.hh:49
EAttributeType::attr_float
static const int attr_float
Definition attributetype.hh:43
EAttributeType::attr_string
static const int attr_string
Definition attributetype.hh:45
EAttributeType::attr_sint
static const int attr_sint
Definition attributetype.hh:40
EAttributeType::attr_ulong
static const int attr_ulong
Definition attributetype.hh:41
EAttributeType::attr_uchar
static const int attr_uchar
Definition attributetype.hh:35
EAttributeType::vector_bit
static const int vector_bit
Definition attributetype.hh:47
EAttributeType::attr_slong
static const int attr_slong
Definition attributetype.hh:42
EAttributeType::attr_sshort
static const int attr_sshort
Definition attributetype.hh:38
EAttributeType::attr_double
static const int attr_double
Definition attributetype.hh:44
attribute_type< std::vector< T > >::value
static const int value
Definition attributetype.hh:97
attribute_type
Definition attributetype.hh:65
attribute_type::value
static const int value
Definition attributetype.hh:66