TypeInfoName.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jun 26 13:25:56 CEST 2006  TypeInfoName.hpp
00003 
00004                         TypeInfoName.hpp -  description
00005                            -------------------
00006     begin                : Mon June 26 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@fmtc.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 ORO_TYPEINFO_NAME_HPP
00040 #define ORO_TYPEINFO_NAME_HPP
00041 
00042 #include "Types.hpp"
00043 #include "DataSourceTypeInfo.hpp"
00044 #include "Logger.hpp"
00045 #include "rtt-config.h"
00046 
00047 namespace RTT
00048 {
00052     class RTT_API EmptyTypeInfo
00053         : public TypeInfo
00054     {
00055         const std::string tname;
00056     public:
00057         EmptyTypeInfo(std::string name)
00058             : tname(name)
00059         {
00060         }
00061 
00062         using TypeInfo::buildConstant;
00063         using TypeInfo::buildVariable;
00064 
00065         AttributeBase* buildConstant(std::string name,DataSourceBase::shared_ptr dsb) const
00066         {
00067             Logger::In loc("TypeInfoName");
00068             Logger::log() << Logger::Error << "Can not build Constant of "<<tname<<"."<<Logger::endl;
00069             return 0;
00070         }
00071 
00072         AttributeBase* buildVariable(std::string name) const
00073         {
00074             Logger::In loc("TypeInfoName");
00075             Logger::log() << Logger::Error << "Can not build Variable of "<<tname<<"."<<Logger::endl;
00076             return 0;
00077         }
00078 
00079         AttributeBase* buildAttribute(std::string name, DataSourceBase::shared_ptr in) const
00080         {
00081             Logger::In loc("TypeInfoName");
00082             Logger::log() << Logger::Error << "Can not build Attribute of "<<tname<<"."<<Logger::endl;
00083             return 0;
00084         }
00085 
00086         AttributeBase* buildAlias(std::string name, DataSourceBase::shared_ptr in ) const
00087         {
00088             Logger::In loc("TypeInfoName");
00089             Logger::log() << Logger::Error << "Can not build Alias of "<<tname<<"."<<Logger::endl;
00090             return 0;
00091         }
00092 
00093         virtual const std::string& getTypeName() const { return tname; }
00094 
00095         virtual PropertyBase* buildProperty(const std::string& name, const std::string& desc, DataSourceBase::shared_ptr source = 0) const {
00096             Logger::In loc("TypeInfoName");
00097             Logger::log() << Logger::Error << "Can not build Property of "<<tname<<"."<<Logger::endl;
00098             return 0;
00099         }
00100 
00101         virtual DataSourceBase::shared_ptr buildValue() const {
00102             Logger::In loc("TypeInfoName");
00103             Logger::log() << Logger::Error << "Can not build ValueDataSource of "<<tname<<"."<<Logger::endl;
00104             return 0;
00105         }
00106 
00107         DataSourceBase::shared_ptr construct(const std::vector<DataSourceBase::shared_ptr>& ) const {
00108             Logger::In loc("TypeInfoName");
00109             Logger::log() << Logger::Error << "Can not construct value of "<<tname<<"."<<Logger::endl;
00110             return DataSourceBase::shared_ptr();
00111         }
00112 
00113 
00114         virtual std::ostream& write( std::ostream& os, DataSourceBase::shared_ptr in ) const {
00115             Logger::In loc("TypeInfoName");
00116 #ifdef OS_HAVE_STREAMS
00117                 std::string output = std::string("(")+ in->getTypeName() +")";
00118                 os << output;
00119 #endif
00120             return os;
00121         }
00122 
00123         virtual std::istream& read( std::istream& is, DataSourceBase::shared_ptr out ) const {
00124             Logger::In loc("TypeInfoName");
00125             return is;
00126         }
00127 
00128         virtual bool decomposeType( DataSourceBase::shared_ptr source, PropertyBag& targetbag ) const {
00129             Logger::In loc("TypeInfoName");
00130             Logger::log() << Logger::Error << "Can not decompose "<<tname<<"."<<Logger::endl;
00131             return false;
00132         }
00133 
00134         virtual bool composeType( DataSourceBase::shared_ptr source, DataSourceBase::shared_ptr result) const {
00135             Logger::In loc("TypeInfoName");
00136             Logger::log() << Logger::Error << "Can not compose "<<tname<<"."<<Logger::endl;
00137             return false;
00138         }
00139         
00140         virtual std::string getTypeIdName() const { return ""; }
00141 
00142     };
00143 
00150     template<typename T>
00151     struct RTT_API TypeInfoName
00152         : public EmptyTypeInfo
00153     {
00161         TypeInfoName(std::string name)
00162             : EmptyTypeInfo(name)
00163         {
00164             Logger::In in("TypeInfoName");
00165             // Install the type info object for T.
00166             if ( detail::DataSourceTypeInfo<T>::value_type_info::TypeInfoObject != 0) {
00167                 Logger::log() << Logger::Warning << "Overriding TypeInfo for '"
00168                               << detail::DataSourceTypeInfo<T>::value_type_info::TypeInfoObject->getTypeName()
00169                               << "'." << Logger::endl;
00170             }
00171             detail::DataSourceTypeInfo<T>::value_type_info::TypeInfoObject = this;
00172         }
00173     };
00174 
00175 }
00176 
00177 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3