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 "../internal/ConnFactory.hpp"
00048 #include "MemberFactory.hpp"
00049 #include "ValueFactory.hpp"
00050 #include "CompositionFactory.hpp"
00051 #ifndef NO_TYPE_INFO_STREAMS
00052 #include "StreamFactory.hpp"
00053 #endif
00054 #endif
00055 
00056 
00057 namespace RTT
00058 { namespace types {
00059         using internal::ConnFactory;
00060         using internal::ConnFactoryPtr;
00061 
00068     class RTT_API TypeInfo
00069     {
00070     public:
00071         typedef const std::type_info * TypeId;
00072 
00073         TypeInfo(const std::string& name) : mtypenames(1,name) {}
00074 
00075         ~TypeInfo();
00084         const std::string& getTypeName() const { return mtypenames[0]; }
00085 
00089         std::vector<std::string> getTypeNames() const;
00090 
00096         void addAlias(const std::string& alias);
00097 
00104         bool isType(const std::string& name);
00105         
00109         TypeId getTypeId() const { return mtid; }
00110 
00114         const char * getTypeIdName() const { return mtid_name; }
00115 
00121         base::DataSourceBase::shared_ptr construct(const std::vector<base::DataSourceBase::shared_ptr>& args) const;
00122 
00128         base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const;
00129 
00133         void addConstructor(TypeConstructor* tb);
00134 
00144         bool addProtocol(int protocol_id, TypeTransporter* tt);
00145 
00151         TypeTransporter* getProtocol(int protocol_id) const;
00152 
00156         bool hasProtocol(int protocol_id) const;
00157 
00161         std::vector<int> getTransportNames() const;
00162 
00163 #ifndef NO_TYPE_INFO_FACTORY_FUNCTIONS
00164 
00174         base::AttributeBase* buildConstant(std::string name,base::DataSourceBase::shared_ptr source, int sizehint) const
00175         {
00176             return mdsf ? mdsf->buildConstant(name, source, sizehint) : 0;
00177         }
00178 
00179         base::AttributeBase* buildConstant(std::string name,base::DataSourceBase::shared_ptr source) const
00180         {
00181             return mdsf ? mdsf->buildConstant(name, source) : 0;
00182         }
00188         base::AttributeBase* buildVariable(std::string name,int sizehint) const;
00189         base::AttributeBase* buildVariable(std::string name) const
00190         {
00191             return mdsf ? mdsf->buildVariable(name) : 0;
00192         }
00193 
00198         bool resize(base::DataSourceBase::shared_ptr arg, int size) const
00199         {
00200             return mmembf ? mmembf->resize(arg, size) : false;
00201         }
00202 
00207         base::AttributeBase* buildAlias(std::string name, base::DataSourceBase::shared_ptr b ) const
00208         {
00209             return mdsf ? mdsf->buildAlias(name, b) : 0;
00210         }
00211 
00215         base::PropertyBase* buildProperty(const std::string& name, const std::string& desc, base::DataSourceBase::shared_ptr source = 0) const
00216         {
00217             return mdsf ? mdsf->buildProperty(name, desc, source) : 0;
00218         }
00219 
00223         base::AttributeBase* buildAttribute(std::string name, base::DataSourceBase::shared_ptr source = 0 ) const
00224         {
00225             return mdsf ? mdsf->buildAttribute(name, source) : 0;
00226         }
00227 
00231         base::DataSourceBase::shared_ptr buildValue() const
00232         {
00233             return mdsf ? mdsf->buildValue() : base::DataSourceBase::shared_ptr();
00234         }
00235 
00239         base::DataSourceBase::shared_ptr buildReference(void* ptr) const
00240         {
00241             return mdsf ? mdsf->buildReference(ptr) : base::DataSourceBase::shared_ptr();
00242         }
00243 
00249         base::DataSourceBase::shared_ptr buildActionAlias(base::ActionInterface* action, base::DataSourceBase::shared_ptr source) const
00250         {
00251             return mdsf ? mdsf->buildActionAlias(action,source) : base::DataSourceBase::shared_ptr();
00252         }
00253 
00256 #ifndef NO_TYPE_INFO_STREAMS
00257 
00266         std::ostream& write(std::ostream& os, base::DataSourceBase::shared_ptr in ) const
00267         {
00268             return mstrf ? mstrf->write(os, in) : os;
00269         }
00270 
00275         std::istream& read(std::istream& os, base::DataSourceBase::shared_ptr out ) const
00276         {
00277             return mstrf ? mstrf->read(os, out) : os;
00278         }
00279 
00280 
00284         std::string toString( base::DataSourceBase::shared_ptr in ) const
00285         {
00286             return mstrf ? mstrf->toString(in) : std::string();
00287         }
00288 
00292         bool fromString( const std::string& value, base::DataSourceBase::shared_ptr out ) const
00293         {
00294             return mstrf ? mstrf->fromString(value, out) : false;
00295         }
00296 
00301         bool isStreamable() const
00302         {
00303             return mstrf ? mstrf->isStreamable() : false;
00304         }
00306 #endif
00307 
00317         std::vector<std::string> getMemberNames() const
00318         {
00319             return mmembf ? mmembf->getMemberNames() : std::vector<std::string>();
00320         }
00321 
00329         base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string& name) const
00330         {
00331             return mmembf ? mmembf->getMember(item,name) : base::DataSourceBase::shared_ptr();
00332         }
00333 
00343         bool getMember(internal::Reference* ref, base::DataSourceBase::shared_ptr item, const std::string& name) const
00344         {
00345             return mmembf ? mmembf->getMember(ref, item,name) : false;
00346         }
00347 
00355         base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item,
00356                                                    base::DataSourceBase::shared_ptr id) const
00357         {
00358             return mmembf ? mmembf->getMember(item,id) : base::DataSourceBase::shared_ptr();
00359         }
00360 
00379         bool composeType( base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr target) const
00380         {
00381             return mcompf ? mcompf->composeType(source,target) : false;
00382         }
00383 
00395         base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
00396         {
00397             return mcompf ? mcompf->decomposeType(source) : base::DataSourceBase::shared_ptr();
00398         }
00399 
00407         base::DataSourceBase::shared_ptr convertType(base::DataSourceBase::shared_ptr source) const
00408         {
00409             return mcompf ? mcompf->convertType(source) : base::DataSourceBase::shared_ptr();
00410         }
00411 
00420         base::InputPortInterface* inputPort(std::string const& name) const
00421         {
00422             return mconnf ? mconnf->inputPort(name) : 0; 
00423         }
00424 
00429         base::OutputPortInterface* outputPort(std::string const& name) const
00430         {
00431             return mconnf ? mconnf->outputPort(name) : 0; 
00432         }
00433 
00440         base::ChannelElementBase::shared_ptr buildDataStorage(ConnPolicy const& policy) const
00441         {
00442             return mconnf ? mconnf->buildDataStorage(policy) : base::ChannelElementBase::shared_ptr();
00443         }
00444         base::ChannelElementBase::shared_ptr buildChannelOutput(base::InputPortInterface& port) const
00445         {
00446             return mconnf ? mconnf->buildChannelOutput(port) : base::ChannelElementBase::shared_ptr();
00447         }
00448         base::ChannelElementBase::shared_ptr buildChannelInput(base::OutputPortInterface& port) const
00449         {
00450             return mconnf ? mconnf->buildChannelInput(port) : base::ChannelElementBase::shared_ptr();
00451         }
00452 
00453 #endif // NO_TYPE_INFO_FACTORY_FUNCTIONS
00454 
00455         void setTypeId(TypeId tid) {
00456             mtid = tid;
00457             mtid_name = tid->name();
00458         }
00459 
00464         void setPortFactory( ConnFactoryPtr cf ) { if (cf) mconnf = cf; }
00465 
00466         ConnFactoryPtr getPortFactory() const { return mconnf; }
00467 
00468         void setMemberFactory( MemberFactoryPtr mf ) { if (mf) mmembf = mf; }
00469 
00470         MemberFactoryPtr getMemberFactory() const { return mmembf; }
00471 
00472         void setValueFactory( ValueFactoryPtr dsf) { if (dsf) mdsf = dsf; }
00473 
00474         ValueFactoryPtr getValueFactory() const { return mdsf; }
00475 
00476         void setCompositionFactory( CompositionFactoryPtr cf) { if(cf) mcompf = cf; }
00477 
00478         CompositionFactoryPtr getCompositionFactory() const { return mcompf; }
00479 
00480         void setStreamFactory( StreamFactoryPtr sf ) { if (sf) mstrf = sf; }
00481 
00482         StreamFactoryPtr getStreamFactory() const { return mstrf; }
00483     protected:
00484         typedef std::vector<TypeConstructor*> Constructors;
00485         typedef std::vector<TypeTransporter*> Transporters;
00486         Constructors constructors;
00487         Transporters transporters;
00488         std::vector<std::string> mtypenames;
00489         const char* mtid_name;
00490         TypeId mtid;
00491         boost::shared_ptr<ConnFactory> mconnf;
00492         boost::shared_ptr<MemberFactory> mmembf;
00493         boost::shared_ptr<ValueFactory> mdsf;
00494         boost::shared_ptr<CompositionFactory> mcompf;
00495         boost::shared_ptr<StreamFactory> mstrf;
00496     };
00497 
00498 }}
00499 
00500 #endif


rtt
Author(s): RTT Developers
autogenerated on Mon Oct 6 2014 03:13:55