DataTypeInfo.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
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 /* index */, T& value) 
00063     { 
00064         value = static_cast<T>(type); 
00065     }
00066     
00067     template<typename T>
00068     static void setValue(double &type, unsigned int /* index */, 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 /* index */) { return type; }
00080 
00081     template <typename T>
00082     static void getValue(const float &type, unsigned int /* index */, T& value) 
00083     { 
00084         value = static_cast<T>(type); 
00085     }
00086     
00087     template<typename T>
00088     static void setValue(float &type, unsigned int /* index */, const T& value ) 
00089     { 
00090         type = static_cast<float>(value); 
00091     }
00092 };
00093 
00094 } // namespace defaulttype
00095 
00096 } // namespace sofa
00097 
00098 #endif  // SOFA_DEFAULTTYPE_DATATYPEINFO_H

Generated on Sun Nov 23 02:29:27 2008 for Sofa by  doxygen 1.5.7.1