DataSource.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:25 CET 2004  DataSource.hpp
00003 
00004                         DataSource.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 CORELIB_DATASOURCE_HPP
00039 #define CORELIB_DATASOURCE_HPP
00040 
00041 #include <map>
00042 #include <string>
00043 #include "rtt-config.h"
00044 #include <boost/call_traits.hpp>
00045 #include <boost/type_traits.hpp>
00046 
00047 #include "DataSourceBase.hpp"
00048 
00049 namespace RTT
00050 {
00051 
00052 #ifndef ORO_EMBEDDED
00053 
00058     struct RTT_EXPORT bad_assignment
00059     {
00060     };
00061 #endif
00062 
00063 
00075   template<typename T>
00076   class DataSource
00077     : public DataSourceBase
00078   {
00079   protected:
00080       virtual ~DataSource();
00081 
00082   public:
00086       typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type value_t;
00087       typedef T result_t;
00088 
00089       typedef typename boost::intrusive_ptr<DataSource<T> > shared_ptr;
00090 
00091       typedef typename boost::intrusive_ptr<const DataSource<T> > const_ptr;
00092 
00096       virtual result_t get() const = 0;
00097 
00101       virtual result_t value() const = 0;
00102 
00103       virtual bool evaluate() const;
00104 
00105       virtual DataSource<T>* clone() const = 0;
00106 
00107       virtual DataSource<T>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const = 0;
00108 
00109       virtual std::string getType() const;
00110 
00114       static  std::string GetType();
00115 
00116       virtual const TypeInfo* getTypeInfo() const;
00117 
00121       static const TypeInfo* GetTypeInfo();
00122 
00127       static  std::string GetTypeName();
00128 
00129       virtual std::string getTypeName() const;
00130 
00135       static DataSource<T>* narrow(DataSourceBase* db);
00136 
00137   };
00138 
00143   template<typename T>
00144   class AssignableDataSource
00145     : public DataSource<T>
00146   {
00147   protected:
00148       ~AssignableDataSource();
00149   public:
00150       typedef typename DataSource<T>::value_t value_t;
00151       typedef typename boost::call_traits<value_t>::param_type param_t;
00152       typedef typename boost::call_traits<value_t>::reference reference_t;
00153       typedef typename boost::call_traits<value_t>::const_reference const_reference_t;
00154 
00155       // For assignment from another datasource, we use the call_traits convention but
00156       // remove the 'const' for the 'small' types. This to avoid requiring a DataSourceAdaptor.
00157       // Big types (classes) are still passed by const&.
00158       typedef typename boost::remove_const<typename boost::call_traits<value_t>::param_type>::type copy_t;
00159 
00163       typedef boost::intrusive_ptr<AssignableDataSource<T> > shared_ptr;
00164       typedef typename boost::intrusive_ptr<const AssignableDataSource<T> > const_ptr;
00165 
00169       virtual void set( param_t t ) = 0;
00170 
00178       virtual reference_t set() = 0;
00179 
00187       virtual const_reference_t rvalue() const = 0;
00188 
00189       virtual bool update( DataSourceBase* other );
00190 
00191       virtual CommandInterface* updateCommand( DataSourceBase* other);
00192 
00193       virtual AssignableDataSource<T>* clone() const = 0;
00194 
00195       virtual AssignableDataSource<T>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const = 0;
00196 
00197       virtual bool updateBlob(int protocol, const void* data);
00198 
00199       virtual void* server(int protocol, void* data );
00200 
00205       static AssignableDataSource<T>* narrow(DataSourceBase* db);
00206 
00207   };
00208 }
00209 
00210 // workaround inclusion dependencies.
00211 #ifndef ORO_CORELIB_DATASOURCES_HPP
00212 #include "DataSource.inl"
00213 #endif
00214 #endif
00215 
Generated on Thu Dec 23 13:22:37 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3