TryCommand.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Tue Dec 21 22:43:08 CET 2004  TryCommand.hpp
00003 
00004                         TryCommand.hpp -  description
00005                            -------------------
00006     begin                : Tue December 21 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 
00039 #ifndef ORO_TRY_COMMAND_HPP
00040 #define ORO_TRY_COMMAND_HPP
00041 
00042 #include "CommandInterface.hpp"
00043 #include "ConditionInterface.hpp"
00044 #include "Logger.hpp"
00045 #include "DataSource.hpp"
00046 
00047 namespace RTT
00048 {
00049 
00050 
00051 
00057     class RTT_API TryCommand :
00058         public CommandInterface
00059     {
00060         // we must use a DataSource for correct
00061         // copy sementics ...
00062         AssignableDataSource<bool>::shared_ptr _result;
00063         CommandInterface* c;
00064     public:
00068         TryCommand( CommandInterface* command,
00069                     AssignableDataSource<bool>::shared_ptr storage=0);
00070 
00071         ~TryCommand();
00072 
00073         bool execute();
00074         void reset();
00075 
00076         bool valid() const;
00077 
00078         void readArguments();
00079 
00080         CommandInterface* theCommand() const;
00081 
00082         AssignableDataSource<bool>::shared_ptr result();
00083 
00084         TryCommand* clone() const;
00085 
00086         TryCommand* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const;
00087     };
00088 
00094     class RTT_API TryCommandResult :
00095         public ConditionInterface
00096     {
00097         DataSource<bool>::shared_ptr c;
00098         bool _invert;
00099     public:
00107         TryCommandResult( DataSource<bool>::shared_ptr ec, bool invert);
00108 
00109         ~TryCommandResult();
00110 
00111         bool evaluate();
00112 
00113         ConditionInterface* clone() const;
00114 
00115         ConditionInterface* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const;
00116     };
00117 
00125     class RTT_API EvalCommand :
00126         public CommandInterface
00127     {
00128         // the result
00129         AssignableDataSource<bool>::shared_ptr _cache;
00130         // the data to evaluate in the command.
00131         DataSource<bool>::shared_ptr _ds;
00132     public:
00133         EvalCommand( DataSource<bool>::shared_ptr ds, AssignableDataSource<bool>::shared_ptr cache=0);
00134 
00135         ~EvalCommand();
00136 
00137         void readArguments();
00138 
00139         bool execute();
00140 
00141         void reset();
00142 
00143         AssignableDataSource<bool>::shared_ptr cache();
00144 
00145         CommandInterface* clone() const;
00146 
00147         CommandInterface* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const;
00148     };
00149 
00155     class RTT_API EvalCommandResult :
00156         public ConditionInterface
00157     {
00158         DataSource<bool>::shared_ptr c;
00159     public:
00160         EvalCommandResult( DataSource<bool>::shared_ptr ec);
00161 
00162         ~EvalCommandResult();
00163 
00164         bool evaluate();
00165 
00166         ConditionInterface* clone() const;
00167 
00168         ConditionInterface* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const;
00169     };
00170 }
00171 
00172 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3