Types.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:26 CET 2004  Types.hpp
00003 
00004                         Types.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_TYPES_HPP
00039 #define ORO_CORELIB_TYPES_HPP
00040 
00041 #include <map>
00042 #include <vector>
00043 #include <string>
00044 #include "DataSourceBase.hpp"
00045 #include <boost/shared_ptr.hpp>
00046 #include "AttributeBase.hpp"
00047 #include "Logger.hpp"
00048 
00057 namespace RTT
00058 {
00059 
00060     class PropertyBase;
00061     class PropertyBag;
00062     class AttributeBase;
00063     class TransportPlugin;
00064 
00065     namespace detail {
00066         class TypeTransporter;
00067     }
00068 
00072     struct RTT_API TypeBuilder
00073     {
00074         virtual ~TypeBuilder();
00079         virtual DataSourceBase::shared_ptr build(const std::vector<DataSourceBase::shared_ptr>& args) const = 0;
00080 
00084         virtual DataSourceBase::shared_ptr convert(DataSourceBase::shared_ptr arg) const
00085         {
00086             return DataSourceBase::shared_ptr();
00087         }
00088     };
00089 
00094     class RTT_API TypeInfo
00095     {
00096     protected:
00097         typedef std::vector<TypeBuilder*> Constructors;
00098         typedef std::vector<detail::TypeTransporter*> Transporters;
00099         Constructors constructors;
00100         Transporters transporters;
00101     public:
00102         virtual ~TypeInfo();
00106         virtual const std::string& getTypeName() const = 0;
00107 
00118         virtual AttributeBase* buildConstant(std::string name,DataSourceBase::shared_ptr, int sizehint) const;
00119         virtual AttributeBase* buildConstant(std::string name,DataSourceBase::shared_ptr) const = 0;
00125         virtual AttributeBase* buildVariable(std::string name,int sizehint) const;
00126         virtual AttributeBase* buildVariable(std::string name) const = 0;
00127 
00133         virtual DataSourceBase::shared_ptr construct(const std::vector<DataSourceBase::shared_ptr>& args) const;
00134 
00140         virtual DataSourceBase::shared_ptr convert(DataSourceBase::shared_ptr arg) const;
00141 
00145         virtual void addConstructor(TypeBuilder* tb);
00146 
00151         virtual AttributeBase* buildAlias(std::string name, DataSourceBase::shared_ptr b ) const = 0;
00152 
00156         virtual PropertyBase* buildProperty(const std::string& name, const std::string& desc, DataSourceBase::shared_ptr source = 0) const = 0;
00157 
00161         virtual AttributeBase* buildAttribute(std::string name, DataSourceBase::shared_ptr source = 0 ) const = 0;
00162 
00166         virtual DataSourceBase::shared_ptr buildValue() const = 0;
00178         virtual std::ostream& write(std::ostream& os, DataSourceBase::shared_ptr in ) const = 0;
00179 
00184         virtual std::istream& read(std::istream& os, DataSourceBase::shared_ptr out ) const = 0;
00185 
00189         virtual std::string toString( DataSourceBase::shared_ptr in ) const;
00190 
00194         virtual bool fromString( const std::string& value, DataSourceBase::shared_ptr out ) const;
00207         virtual bool decomposeType( DataSourceBase::shared_ptr source, PropertyBag& targetbag ) const = 0;
00208 
00214         virtual bool composeType( DataSourceBase::shared_ptr source, DataSourceBase::shared_ptr target) const = 0;
00228         bool addProtocol(int protocol_id, detail::TypeTransporter* tt);
00229 
00230         detail::TypeTransporter* getProtocol(int protocol_id) const;
00231 
00235         std::vector<int> getTransportNames() const;
00236         
00241          virtual std::string getTypeIdName() const = 0;
00242     };
00243 
00248     class RTT_API TypeInfoRepository
00249     {
00250         TypeInfoRepository();
00251         typedef std::map<std::string, TypeInfo*> map_t;
00252         map_t data;
00253 
00254         typedef std::vector<TransportPlugin*> Transports;
00255         Transports transports;
00256     public:
00257         ~TypeInfoRepository();
00258         typedef boost::shared_ptr<TypeInfoRepository> shared_ptr;
00259         static shared_ptr Instance();
00263         TypeInfo* type( const std::string& name ) const;
00264 
00268         bool addType( TypeInfo* );
00269 
00273         std::vector<std::string> getTypes() const;
00274 
00278         TypeInfo* getTypeById(std::string type_id_name) const;
00279 
00283         template<class T>
00284         TypeInfo* getTypeInfo() const {
00285             return getTypeById( typeid(T).name() );
00286         }
00287 
00292         void registerTransport( TransportPlugin* tr );
00293 
00298         void logTypeInfo() const;
00299 
00300     };
00301 
00306     RTT_API TypeInfoRepository::shared_ptr types();
00307 }
00308 
00309 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3