PropertyCommands.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Sat May 7 12:56:52 CEST 2005  PropertyCommands.hpp
00003 
00004                         PropertyCommands.hpp -  description
00005                            -------------------
00006     begin                : Sat May 07 2005
00007     copyright            : (C) 2005 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_PROPERTY_HPP
00039 // #error "Do not include this file directly, but only through Property.hpp"
00040 #else
00041 
00042 #ifndef ORO_CORELIB_PROPERTY_COMMANDS
00043 #define ORO_CORELIB_PROPERTY_COMMANDS
00044 
00045 #include "CommandInterface.hpp"
00046 #include "DataSource.hpp"
00047 
00048 
00049 namespace RTT
00050 {
00051 
00052     namespace detail {
00053 
00058         template<class T>
00059         class UpdatePropertyCommand
00060             : public CommandInterface
00061         {
00062             Property<T>* target;
00063             const Property<T>* source;
00064         public:
00065             UpdatePropertyCommand( Property<T>* tgt, const Property<T>* src)
00066                 : target(tgt), source(src) {}
00067 
00068             void readArguments() {
00069             }
00070 
00071             bool execute()
00072             {
00073                 return target->update( *source );
00074             }
00075 
00076             virtual UpdatePropertyCommand<T>* clone() const {
00077                 return new UpdatePropertyCommand<T>(target, source);
00078             }
00079         };
00080 
00085         template<class T>
00086         class CopyPropertyCommand
00087             : public CommandInterface
00088         {
00089             Property<T>* target;
00090             const Property<T>* source;
00091         public:
00092             CopyPropertyCommand( Property<T>* tgt, const Property<T>* src)
00093                 : target(tgt), source(src) {}
00094 
00095             void readArguments() {
00096             }
00097 
00098             bool execute()
00099             {
00100                 return target->copy( *source );
00101             }
00102 
00103             virtual CopyPropertyCommand<T>* clone() const {
00104                 return new CopyPropertyCommand<T>(target, source);
00105             }
00106         };
00107 
00112         template<class T>
00113         class RefreshPropertyCommand
00114             : public CommandInterface
00115         {
00116             Property<T>* target;
00117             const Property<T>* source;
00118         public:
00119             RefreshPropertyCommand( Property<T>* tgt, const Property<T>* src)
00120                 : target(tgt), source(src) {}
00121 
00122             void readArguments() {
00123                 source->get();
00124             }
00125 
00126             bool execute()
00127             {
00128                 return target->refresh( *source );
00129             }
00130 
00131             virtual RefreshPropertyCommand<T>* clone() const {
00132                 return new RefreshPropertyCommand<T>(target, source);
00133             }
00134         };
00135 
00140         template<class T>
00141         class RefreshPropertyFromDSCommand
00142             : public CommandInterface
00143         {
00144             Property<T>* target;
00145             typename DataSource<T>::shared_ptr source;
00146         public:
00147             RefreshPropertyFromDSCommand( Property<T>* tgt, DataSource<T>* src)
00148                 : target(tgt), source(src) {}
00149 
00150             void readArguments() {
00151                 source->evaluate();
00152             }
00153 
00154             bool execute()
00155             {
00156                 return target->refresh( *source );
00157             }
00158 
00159             virtual RefreshPropertyFromDSCommand<T>* clone() const {
00160                 return new RefreshPropertyFromDSCommand<T>(target, source.get() );
00161             }
00162 
00163             virtual RefreshPropertyFromDSCommand<T>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00164                 return new RefreshPropertyFromDSCommand<T>( target, source->copy(alreadyCloned) );
00165             }
00166         };
00167 
00168     }
00169 
00170 }
00171 
00172 #endif
00173 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3