Orocos Real-Time Toolkit  2.6.0
DataSourceTypeInfo.hpp
00001 /***************************************************************************
00002   tag: Peter Soetens  Sat May 7 12:56:52 CEST 2005  DataSourceTypeInfo.hpp
00003 
00004                         DataSourceTypeInfo.hpp -  description
00005                            -------------------
00006     begin                : Sat May 07 2005
00007     copyright            : (C) 2005 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 #ifndef DATASOURCE_TYPE_INFO_HPP
00040 #define DATASOURCE_TYPE_INFO_HPP
00041 
00042 #include <string>
00043 #include <typeinfo>
00044 #include "../types/carray.hpp"
00045 #include "../rtt-config.h"
00046 #include "../types/rtt-types-fwd.hpp"
00047 
00048 namespace RTT
00049 {
00050 
00051     namespace internal {
00052 
00053         struct RTT_API UnknownType {};
00054 
00055         template< class T>
00056         struct DataSourceTypeInfo;
00057 
00063         template<>
00064         struct RTT_API DataSourceTypeInfo<UnknownType> {
00065             typedef UnknownType value_type;
00066             typedef DataSourceTypeInfo<UnknownType> value_type_info;
00067 
00068             static types::TypeInfo* TypeInfoObject;
00069 
00070             static const std::string noqual;
00071             static const std::string cqual;
00072             static const std::string refqual;
00073             static const std::string crefqual;
00074             static const std::string ptrqual;
00075             static const std::string cptrqual;
00076             static const std::string& getType();
00077             static const std::string& getTypeName();
00078             static const std::string& getQualifier();
00079             // we drop the const qualifier in this specialisation, since it is
00080             // not registered in the type repository (which returns a non const in type() )
00081             static types::TypeInfo* getTypeInfo();
00082         };
00083 
00088         template< class T>
00089         struct DataSourceTypeInfo<const T&> {
00090             typedef T value_type;
00091             typedef DataSourceTypeInfo<T> value_type_info;
00092             static std::string getType()  { return getTypeName() + getQualifier(); }
00093             static const std::string& getTypeName()  { return DataSourceTypeInfo< T >::getTypeName(); }
00094             static const std::string& getQualifier() { return DataSourceTypeInfo<UnknownType>::crefqual; }
00095             static const types::TypeInfo* getTypeInfo() { return DataSourceTypeInfo< T >::getTypeInfo(); }
00096         };
00097 
00098         template< class T>
00099         struct DataSourceTypeInfo<T&> {
00100             typedef T value_type;
00101             typedef DataSourceTypeInfo<T> value_type_info;
00102             static std::string getType()  { return getTypeName() + getQualifier(); }
00103             static const std::string& getTypeName()  { return DataSourceTypeInfo< T >::getTypeName(); }
00104             static const std::string& getQualifier() { return DataSourceTypeInfo<UnknownType>::refqual; }
00105             static const types::TypeInfo* getTypeInfo() { return DataSourceTypeInfo< T >::getTypeInfo(); }
00106         };
00107 
00108         template< class T>
00109         struct DataSourceTypeInfo<const T> {
00110             typedef T value_type;
00111             typedef DataSourceTypeInfo<T> value_type_info;
00112             static std::string getType()  { return getTypeName() + getQualifier(); }
00113             static const std::string& getTypeName()  { return DataSourceTypeInfo< T >::getTypeName(); }
00114             static const std::string& getQualifier() { return DataSourceTypeInfo<UnknownType>::cqual; }
00115             static const types::TypeInfo* getTypeInfo() { return DataSourceTypeInfo< T >::getTypeInfo(); }
00116         };
00117 
00118         template< class T>
00119         struct DataSourceTypeInfo<T*> {
00120             typedef T value_type;
00121             typedef DataSourceTypeInfo<T> value_type_info;
00122             static std::string getType()  { return getTypeName() + getQualifier(); }
00123             static const std::string& getTypeName()  { return DataSourceTypeInfo< T >::getTypeName(); }
00124             static const std::string& getQualifier() { return DataSourceTypeInfo<UnknownType>::ptrqual; }
00125             static const types::TypeInfo* getTypeInfo();
00126             static types::TypeInfo* TypeInfoObject;
00127         };
00128 
00129         template< class T>
00130         struct DataSourceTypeInfo<const T*> {
00131             typedef T value_type;
00132             typedef DataSourceTypeInfo<T> value_type_info;
00133             static std::string getType()  { return getTypeName() + getQualifier(); }
00134             static const std::string& getTypeName()  { return DataSourceTypeInfo< T >::getTypeName(); }
00135             static const std::string& getQualifier() { return DataSourceTypeInfo<UnknownType>::cptrqual; }
00136             static const types::TypeInfo* getTypeInfo() { return DataSourceTypeInfo< T >::getTypeInfo(); }
00137         };
00138 
00147         template< class T>
00148         struct DataSourceTypeInfo<types::carray<T> > {
00149             typedef types::carray<T> value_type;
00150             typedef DataSourceTypeInfo<value_type> value_type_info;
00151             static std::string getType()  { return getTypeName() + "[N]"; }
00152             static const std::string& getTypeName()  { return DataSourceTypeInfo< T >::getTypeInfo()->getTypeName(); }
00153             static const std::string& getQualifier() { return DataSourceTypeInfo<UnknownType>::noqual; }
00154             static const types::TypeInfo* getTypeInfo();
00155             static types::TypeInfo* TypeInfoObject;
00156         };
00157 
00164         template< class T>
00165         struct DataSourceTypeInfo {
00166             typedef T value_type;
00167             typedef DataSourceTypeInfo<T> value_type_info;
00168 
00173             static types::TypeInfo* TypeInfoObject;
00174 
00178             static const std::string& getType();
00179 
00183             static const std::string& getTypeName();
00184 
00188             static const std::string& getQualifier();
00189 
00193             static const types::TypeInfo* getTypeInfo();
00194         };
00195 
00199         template<>
00200         struct RTT_API DataSourceTypeInfo<void> {
00201             static const std::string tname;
00202         public:
00203             typedef void value_type;
00204             typedef DataSourceTypeInfo<void> value_type_info;
00205 
00210             static types::TypeInfo* TypeInfoObject;
00211 
00215             static const std::string& getType();
00216 
00220             static const std::string& getTypeName();
00221 
00225             static const std::string& getQualifier();
00226 
00230             static const types::TypeInfo* getTypeInfo();
00231         };
00232     }
00233 
00234 }
00235 
00236 #endif
00237 
00238 #include "DataSourceTypeInfo.inl"