DataTypeInfo.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SOFA_DEFAULTTYPE_DATATYPEINFO_H
00028 #define SOFA_DEFAULTTYPE_DATATYPEINFO_H
00029
00030 namespace sofa
00031 {
00032
00033 namespace defaulttype
00034 {
00035
00036 template<class DataType>
00037 class DataTypeInfo
00038 {
00039 public:
00040 static unsigned int size() { return DataType::size(); }
00041
00042 template <typename T>
00043 static void getValue(const DataType &type, unsigned int index, T& value)
00044 {
00045 value = static_cast<T>(type[index]);
00046 }
00047
00048 template<typename T>
00049 static void setValue(DataType &type, unsigned int index, const T& value )
00050 {
00051 type[index] = static_cast<typename DataType::value_type>(value);
00052 }
00053 };
00054
00055 template<>
00056 class DataTypeInfo<double>
00057 {
00058 public:
00059 static unsigned int size() { return 1; }
00060
00061 template <typename T>
00062 static void getValue(const double &type, unsigned int , T& value)
00063 {
00064 value = static_cast<T>(type);
00065 }
00066
00067 template<typename T>
00068 static void setValue(double &type, unsigned int , const T& value )
00069 {
00070 type = static_cast<double>(value);
00071 }
00072 };
00073
00074 template<>
00075 class DataTypeInfo<float>
00076 {
00077 public:
00078 static unsigned int size() { return 1; }
00079 static double getValue(const float &type, unsigned int ) { return type; }
00080
00081 template <typename T>
00082 static void getValue(const float &type, unsigned int , T& value)
00083 {
00084 value = static_cast<T>(type);
00085 }
00086
00087 template<typename T>
00088 static void setValue(float &type, unsigned int , const T& value )
00089 {
00090 type = static_cast<float>(value);
00091 }
00092 };
00093
00094 }
00095
00096 }
00097
00098 #endif // SOFA_DEFAULTTYPE_DATATYPEINFO_H