TypeInfo.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:26 CET 2004  TypeInfo.hpp
00003 
00004                         TypeInfo.hpp -  description
00005                            -------------------
00006     begin                : Mon January 19 2004
00007     copyright            : (C) 2004 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 #ifndef ORO_CORELIB_TYPEINFO_HPP
00039 #define ORO_CORELIB_TYPEINFO_HPP
00040 
00041 #include <vector>
00042 #include <string>
00043 #include "../base/DataSourceBase.hpp"
00044 #include "../base/ChannelElementBase.hpp"
00045 
00046 #ifndef NO_TYPE_INFO_FACTORY_FUNCTIONS
00047 #include "MemberFactory.hpp"
00048 #include "ValueFactory.hpp"
00049 #include "CompositionFactory.hpp"
00050 #ifndef NO_TYPE_INFO_STREAMS
00051 #include "StreamFactory.hpp"
00052 #endif
00053 #endif
00054 
00055 
00056 namespace RTT
00057 { namespace types {
00058     typedef boost::shared_ptr<internal::ConnFactory> ConnFactoryPtr;
00059 
00066     class RTT_API TypeInfo
00067     {
00068     public:
00069         typedef const std::type_info * TypeId;
00070 
00071         TypeInfo(const std::string& name) : mtypenames(1,name) {}
00072 
00073         ~TypeInfo();
00082         const std::string& getTypeName() const { return mtypenames[0]; }
00083 
00087         std::vector<std::string> getTypeNames() const;
00088 
00094         void addAlias(const std::string& alias);
00095 
00102         bool isType(const std::string& name);
00103         
00107         TypeId getTypeId() const { return mtid; }
00108 
00112         const char * getTypeIdName() const { return mtid_name; }
00113 
00119         base::DataSourceBase::shared_ptr construct(const std::vector<base::DataSourceBase::shared_ptr>& args) const;
00120 
00126         base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const;
00127 
00131         void addConstructor(TypeConstructor* tb);
00132 
00142         bool addProtocol(int protocol_id, TypeTransporter* tt);
00143 
00149         TypeTransporter* getProtocol(int protocol_id) const;
00150 
00154         bool hasProtocol(int protocol_id) const;
00155 
00159         std::vector<int> getTransportNames() const;
00160 
00161 #ifndef NO_TYPE_INFO_FACTORY_FUNCTIONS
00162 
00172         base::AttributeBase* buildConstant(std::string name,base::DataSourceBase::shared_ptr source, int sizehint) const
00173         {
00174             return mdsf ? mdsf->buildConstant(name, source, sizehint) : 0;
00175         }
00176 
00177         base::AttributeBase* buildConstant(std::string name,base::DataSourceBase::shared_ptr source) const
00178         {
00179             return mdsf ? mdsf->buildConstant(name, source) : 0;
00180         }
00186         base::AttributeBase* buildVariable(std::string name,int sizehint) const;
00187         base::AttributeBase* buildVariable(std::string name) const
00188         {
00189             return mdsf ? mdsf->buildVariable(name) : 0;
00190         }
00191 
00196         bool resize(base::DataSourceBase::shared_ptr arg, int size) const
00197         {
00198             return mmembf ? mmembf->resize(arg, size) : false;
00199         }
00200 
00205         base::AttributeBase* buildAlias(std::string name, base::DataSourceBase::shared_ptr b ) const
00206         {
00207             return mdsf ? mdsf->buildAlias(name, b) : 0;
00208         }
00209 
00213         base::PropertyBase* buildProperty(const std::string& name, const std::string& desc, base::DataSourceBase::shared_ptr source = 0) const
00214         {
00215             return mdsf ? mdsf->buildProperty(name, desc, source) : 0;
00216         }
00217 
00221         base::AttributeBase* buildAttribute(std::string name, base::DataSourceBase::shared_ptr source = 0 ) const
00222         {
00223             return mdsf ? mdsf->buildAttribute(name, source) : 0;
00224         }
00225 
00229         base::DataSourceBase::shared_ptr buildValue() const
00230         {
00231             return mdsf ? mdsf->buildValue() : base::DataSourceBase::shared_ptr();
00232         }
00233 
00237         base::DataSourceBase::shared_ptr buildReference(void* ptr) const
00238         {
00239             return mdsf ? mdsf->buildReference(ptr) : base::DataSourceBase::shared_ptr();
00240         }
00241 
00247         base::DataSourceBase::shared_ptr buildActionAlias(base::ActionInterface* action, base::DataSourceBase::shared_ptr source) const
00248         {
00249             return mdsf ? mdsf->buildActionAlias(action,source) : base::DataSourceBase::shared_ptr();
00250         }
00251 
00254 #ifndef NO_TYPE_INFO_STREAMS
00255 
00264         std::ostream& write(std::ostream& os, base::DataSourceBase::shared_ptr in ) const
00265         {
00266             if ( mstrf ) {
00267                 return mstrf->write(os,in);
00268             } else {
00269 #ifdef OS_HAVE_STREAMS
00270                 std::string output = std::string("(")+ in->getTypeName() +")";
00271                 os << output;
00272 #endif
00273                 return os;
00274             }
00275         }
00276 
00281         std::istream& read(std::istream& os, base::DataSourceBase::shared_ptr out ) const
00282         {
00283             return mstrf ? mstrf->read(os, out) : os;
00284         }
00285 
00286 
00290         std::string toString( base::DataSourceBase::shared_ptr in ) const
00291         {
00292             return mstrf ? mstrf->toString(in) : std::string();
00293         }
00294 
00298         bool fromString( const std::string& value, base::DataSourceBase::shared_ptr out ) const
00299         {
00300             return mstrf ? mstrf->fromString(value, out) : false;
00301         }
00302 
00307         bool isStreamable() const
00308         {
00309             return mstrf ? mstrf->isStreamable() : false;
00310         }
00312 #endif
00313 
00323         std::vector<std::string> getMemberNames() const
00324         {
00325             return mmembf ? mmembf->getMemberNames() : std::vector<std::string>();
00326         }
00327 
00335         base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string& name) const
00336         {
00337             return mmembf ? mmembf->getMember(item,name) : base::DataSourceBase::shared_ptr();
00338         }
00339 
00349         bool getMember(internal::Reference* ref, base::DataSourceBase::shared_ptr item, const std::string& name) const
00350         {
00351             return mmembf ? mmembf->getMember(ref, item,name) : false;
00352         }
00353 
00361         base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item,
00362                                                    base::DataSourceBase::shared_ptr id) const
00363         {
00364             return mmembf ? mmembf->getMember(item,id) : base::DataSourceBase::shared_ptr();
00365         }
00366 
00385         bool composeType( base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr target) const
00386         {
00387             return mcompf ? mcompf->composeType(source,target) : false;
00388         }
00389 
00401         base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
00402         {
00403             return mcompf ? mcompf->decomposeType(source) : base::DataSourceBase::shared_ptr();
00404         }
00405 
00413         base::DataSourceBase::shared_ptr convertType(base::DataSourceBase::shared_ptr source) const
00414         {
00415             return mcompf ? mcompf->convertType(source) : base::DataSourceBase::shared_ptr();
00416         }
00417 
00426         base::InputPortInterface* inputPort(std::string const& name) const;
00427 
00432         base::OutputPortInterface* outputPort(std::string const& name) const;
00433 
00440         base::ChannelElementBase::shared_ptr buildDataStorage(ConnPolicy const& policy) const;
00441         base::ChannelElementBase::shared_ptr buildChannelOutput(base::InputPortInterface& port) const;
00442         base::ChannelElementBase::shared_ptr buildChannelInput(base::OutputPortInterface& port) const;
00443 
00444 #endif // NO_TYPE_INFO_FACTORY_FUNCTIONS
00445 
00446         void setTypeId(TypeId tid) {
00447             mtid = tid;
00448             mtid_name = tid->name();
00449         }
00450 
00455         void setPortFactory( ConnFactoryPtr cf ) { if (cf) mconnf = cf; }
00456 
00457         ConnFactoryPtr getPortFactory() const { return mconnf; }
00458 
00459         void setMemberFactory( MemberFactoryPtr mf ) { if (mf) mmembf = mf; }
00460 
00461         MemberFactoryPtr getMemberFactory() const { return mmembf; }
00462 
00463         void setValueFactory( ValueFactoryPtr dsf) { if (dsf) mdsf = dsf; }
00464 
00465         ValueFactoryPtr getValueFactory() const { return mdsf; }
00466 
00467         void setCompositionFactory( CompositionFactoryPtr cf) { if(cf) mcompf = cf; }
00468 
00469         CompositionFactoryPtr getCompositionFactory() const { return mcompf; }
00470 
00471         void setStreamFactory( StreamFactoryPtr sf ) { if (sf) mstrf = sf; }
00472 
00473         StreamFactoryPtr getStreamFactory() const { return mstrf; }
00474     protected:
00475         typedef std::vector<TypeConstructor*> Constructors;
00476         typedef std::vector<TypeTransporter*> Transporters;
00477         Constructors constructors;
00478         Transporters transporters;
00479         std::vector<std::string> mtypenames;
00480         const char* mtid_name;
00481         TypeId mtid;
00482         boost::shared_ptr<internal::ConnFactory> mconnf;
00483         boost::shared_ptr<MemberFactory> mmembf;
00484         boost::shared_ptr<ValueFactory> mdsf;
00485         boost::shared_ptr<CompositionFactory> mcompf;
00486         boost::shared_ptr<StreamFactory> mstrf;
00487     };
00488 
00489 }}
00490 
00491 #endif


rtt
Author(s): RTT Developers
autogenerated on Sat Jun 8 2019 18:46:33