PropertyCommands.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef ORO_PROPERTY_HPP
00039
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