Orocos Real-Time Toolkit
2.5.0
|
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 "../internal/DataSourceTypeInfo.hpp" 00044 #include "../Logger.hpp" 00045 #include "../rtt-config.h" 00046 00047 namespace RTT 00048 { namespace types { 00049 00053 class RTT_API EmptyTypeInfo 00054 : public TypeInfo 00055 { 00056 protected: 00057 const std::string tname; 00058 public: 00059 EmptyTypeInfo(std::string name) 00060 : tname(name) 00061 { 00062 } 00063 00064 using TypeInfo::buildConstant; 00065 using TypeInfo::buildVariable; 00066 00067 bool installTypeInfoObject() { 00068 return true; 00069 } 00070 00071 base::AttributeBase* buildConstant(std::string name,base::DataSourceBase::shared_ptr dsb) const 00072 { 00073 Logger::In loc("TypeInfoName"); 00074 Logger::log() << Logger::Error << "Can not build Constant of "<<tname<<"."<<Logger::endl; 00075 return 0; 00076 } 00077 00078 base::AttributeBase* buildVariable(std::string name) const 00079 { 00080 Logger::In loc("TypeInfoName"); 00081 Logger::log() << Logger::Error << "Can not build Variable of "<<tname<<"."<<Logger::endl; 00082 return 0; 00083 } 00084 00085 base::AttributeBase* buildAttribute(std::string name, base::DataSourceBase::shared_ptr in) const 00086 { 00087 Logger::In loc("TypeInfoName"); 00088 Logger::log() << Logger::Error << "Can not build Attribute of "<<tname<<"."<<Logger::endl; 00089 return 0; 00090 } 00091 00092 base::AttributeBase* buildAlias(std::string name, base::DataSourceBase::shared_ptr in ) const 00093 { 00094 Logger::In loc("TypeInfoName"); 00095 Logger::log() << Logger::Error << "Can not build Alias of "<<tname<<"."<<Logger::endl; 00096 return 0; 00097 } 00098 00099 base::DataSourceBase::shared_ptr buildActionAlias(base::ActionInterface* act, base::DataSourceBase::shared_ptr in ) const 00100 { 00101 Logger::In loc("TypeInfoName"); 00102 Logger::log() << Logger::Error << "Can not build ActionAlias of "<<tname<<"."<<Logger::endl; 00103 return 0; 00104 } 00105 00106 virtual const std::string& getTypeName() const { return tname; } 00107 00108 virtual base::PropertyBase* buildProperty(const std::string& name, const std::string& desc, base::DataSourceBase::shared_ptr source = 0) const { 00109 Logger::In loc("TypeInfoName"); 00110 Logger::log() << Logger::Error << "Can not build Property of "<<tname<<"."<<Logger::endl; 00111 return 0; 00112 } 00113 00114 virtual base::DataSourceBase::shared_ptr buildValue() const { 00115 Logger::In loc("TypeInfoName"); 00116 Logger::log() << Logger::Error << "Can not build internal::ValueDataSource of "<<tname<<"."<<Logger::endl; 00117 return 0; 00118 } 00119 00120 virtual base::DataSourceBase::shared_ptr buildReference(void*) const { 00121 Logger::In loc("TypeInfoName"); 00122 Logger::log() << Logger::Error << "Can not build internal::ReferenceDataSource of "<<tname<<"."<<Logger::endl; 00123 return 0; 00124 } 00125 00126 00127 base::DataSourceBase::shared_ptr construct(const std::vector<base::DataSourceBase::shared_ptr>& ) const { 00128 Logger::In loc("TypeInfoName"); 00129 Logger::log() << Logger::Error << "Can not construct value of "<<tname<<"."<<Logger::endl; 00130 return base::DataSourceBase::shared_ptr(); 00131 } 00132 00133 virtual base::DataSourceBase::shared_ptr getAssignable(base::DataSourceBase::shared_ptr arg) const { 00134 return base::DataSourceBase::shared_ptr(); 00135 } 00136 00137 virtual std::ostream& write( std::ostream& os, base::DataSourceBase::shared_ptr in ) const { 00138 Logger::In loc("TypeInfoName"); 00139 #ifdef OS_HAVE_STREAMS 00140 std::string output = std::string("(")+ in->getTypeName() +")"; 00141 os << output; 00142 #endif 00143 return os; 00144 } 00145 00146 virtual std::istream& read( std::istream& is, base::DataSourceBase::shared_ptr out ) const { 00147 Logger::In loc("TypeInfoName"); 00148 return is; 00149 } 00150 00151 virtual bool isStreamable() const { return false; } 00152 00153 virtual base::DataSourceBase::shared_ptr decomposeType( base::DataSourceBase::shared_ptr source ) const { 00154 Logger::In loc("TypeInfoName"); 00155 Logger::log() << Logger::Debug << "Can not decompose "<<tname<<"."<<Logger::endl; 00156 return source; 00157 } 00158 00159 virtual bool composeType( base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr result) const { 00160 Logger::In loc("TypeInfoName"); 00161 Logger::log() << Logger::Error << "Can not compose "<<tname<<"."<<Logger::endl; 00162 return false; 00163 } 00164 00165 virtual const char * getTypeIdName() const { return 0; } 00166 virtual TypeInfo::TypeId getTypeId() const { return 0; } 00167 00168 virtual base::InputPortInterface* inputPort(std::string const& name) const 00169 { return 0; } 00170 virtual base::OutputPortInterface* outputPort(std::string const& name) const 00171 { return 0; } 00172 virtual base::ChannelElementBase::shared_ptr buildDataStorage(ConnPolicy const& policy) const 00173 { return base::ChannelElementBase::shared_ptr(); } 00174 virtual base::ChannelElementBase::shared_ptr buildChannelOutput(base::InputPortInterface& port) const 00175 { return base::ChannelElementBase::shared_ptr(); } 00176 virtual base::ChannelElementBase::shared_ptr buildChannelInput(base::OutputPortInterface& port) const 00177 { return base::ChannelElementBase::shared_ptr(); } 00178 00179 }; 00180 00187 template<typename T> 00188 struct TypeInfoName 00189 : public EmptyTypeInfo 00190 { 00198 TypeInfoName(std::string name) 00199 : EmptyTypeInfo(name) 00200 { 00201 } 00202 00203 bool installTypeInfoObject() { 00204 Logger::In in("TypeInfoName"); 00205 TypeInfo* orig = internal::DataSourceTypeInfo<T>::value_type_info::TypeInfoObject; 00206 if ( orig != 0) { 00207 std::string oname = orig->getTypeName(); 00208 if ( oname != tname ) { 00209 log(Info) << "TypeInfo for type '" << tname << "' already exists as '" 00210 << oname 00211 << "': I'll alias the original and install the new instance." << endlog(); 00212 this->migrateProtocols( orig ); 00213 Types()->aliasType( oname, this); // deletes orig ! 00214 } 00215 } else { 00216 // check for type name conflict (ie "string" for "std::string" and "Foo::Bar" 00217 if ( Types()->type(tname) ) { 00218 log(Error) << "You attemted to register type name "<< tname << " which is already " 00219 << "in use for a different C++ type." <<endlog(); 00220 return false; 00221 } 00222 } 00223 // finally install it: 00224 internal::DataSourceTypeInfo<T>::value_type_info::TypeInfoObject = this; 00225 return true; 00226 } 00227 }; 00228 00229 }} 00230 00231 #endif