DataSource.hpp
Go to the documentation of this file.
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 <exception>
00044 #include "../rtt-config.h"
00045 #include <boost/call_traits.hpp>
00046 #include <boost/static_assert.hpp>
00047 #include <boost/type_traits/add_reference.hpp>
00048 #include <boost/type_traits/add_const.hpp>
00049 
00050 #include "../base/DataSourceBase.hpp"
00051 
00052 namespace RTT
00053 { namespace internal {
00054 
00055 
00056 #ifndef ORO_EMBEDDED
00057 
00062     struct RTT_API bad_assignment : public std::exception
00063     {
00064         virtual ~bad_assignment() throw();
00065         virtual const char* what() const throw();
00066     };
00067 #endif
00068 
00069   namespace details
00070   {
00071      template<typename X>
00072      struct HasConst
00073      { static const int value = 0; };
00074      template<typename X>
00075      struct HasConst<X const>
00076      { static const int value = 1; };
00077 
00078      template<typename X>
00079      struct GetConstRef
00080      { typedef typename boost::add_reference<typename boost::add_const<X>::type>::type type; };
00081      template<>
00082      struct GetConstRef<void>
00083      { typedef void type; };
00084   }
00085 
00093   template<typename T>
00094   class DataSource
00095     : public base::DataSourceBase
00096   {
00097   protected:
00098       virtual ~DataSource();
00099 
00100   public:
00101 
00105       typedef T value_t;
00106       typedef T result_t;
00107       typedef typename details::GetConstRef<T>::type const_reference_t;
00108 
00113       BOOST_STATIC_ASSERT( !details::HasConst<T>::value );
00114 
00115       typedef typename boost::intrusive_ptr<DataSource<T> > shared_ptr;
00116 
00117       typedef typename boost::intrusive_ptr<const DataSource<T> > const_ptr;
00118 
00122       virtual result_t get() const = 0;
00123 
00129       virtual result_t value() const = 0;
00130 
00137       virtual const_reference_t rvalue() const = 0;
00138 
00141       void const* getRawConstPointer() { return &rvalue(); }
00142 
00143       virtual bool evaluate() const;
00144 
00145       virtual DataSource<T>* clone() const = 0;
00146 
00147       virtual DataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const = 0;
00148 
00149       virtual std::string getType() const;
00150 
00154       static  std::string GetType();
00155 
00156       virtual const types::TypeInfo* getTypeInfo() const;
00157 
00161       static const types::TypeInfo* GetTypeInfo();
00162 
00167       static  std::string GetTypeName();
00168 
00169       virtual std::string getTypeName() const;
00170 
00175       static DataSource<T>* narrow(base::DataSourceBase* db);
00176 
00177   };
00178 
00183   template<typename T>
00184   class AssignableDataSource
00185     : public DataSource<T>
00186   {
00187   protected:
00188       ~AssignableDataSource();
00189   public:
00190       typedef typename DataSource<T>::value_t value_t;
00191       typedef typename DataSource<T>::const_reference_t const_reference_t;
00192       typedef typename boost::call_traits<value_t>::param_type param_t;
00193       typedef typename boost::call_traits<value_t>::reference reference_t;
00194 
00198       typedef boost::intrusive_ptr<AssignableDataSource<T> > shared_ptr;
00199       typedef typename boost::intrusive_ptr<const AssignableDataSource<T> > const_ptr;
00200 
00204       virtual void set( param_t t ) = 0;
00205 
00210       virtual reference_t set() = 0;
00211 
00214       void* getRawPointer() { return &set(); }
00215 
00216       virtual bool isAssignable() const { return true; }
00217 
00218       virtual bool update( base::DataSourceBase* other );
00219 
00220       virtual base::ActionInterface* updateAction( base::DataSourceBase* other);
00221 
00222       virtual AssignableDataSource<T>* clone() const = 0;
00223 
00224       virtual AssignableDataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const = 0;
00225 
00230       static AssignableDataSource<T>* narrow(base::DataSourceBase* db);
00231 
00232   };
00233 }}
00234 
00235 // workaround inclusion dependencies.
00236 #ifndef ORO_CORELIB_DATASOURCES_HPP
00237 #include "DataSource.inl"
00238 #endif
00239 #endif
00240 


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