Orocos Real-Time Toolkit  2.6.0
FunctionGraph.hpp
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:21 CET 2004  FunctionGraph.hpp
00003 
00004                         FunctionGraph.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 FUNCTION_GRAPH_HPP
00039 #define FUNCTION_GRAPH_HPP
00040 
00041 #include "VertexNode.hpp"
00042 #include "EdgeCondition.hpp"
00043 #include "CommandNOP.hpp"
00044 #include "rtt-scripting-config.h"
00045 #include "../base/AttributeBase.hpp"
00046 #include "ProgramInterface.hpp"
00047 
00048 namespace RTT
00049 { namespace scripting {
00050 
00051     typedef boost::shared_ptr<FunctionGraph> FunctionGraphPtr;
00052     typedef boost::weak_ptr<FunctionGraph> FunctionGraphWPtr;
00053 
00059     class RTT_SCRIPTING_API FunctionGraph
00060         :public ProgramInterface
00061     {
00062     public:
00063         typedef EdgeCondition::EdgeProperty EdgeProperty;
00064         typedef VertexNode::VertProperty    VertProperty;
00065 
00066         typedef boost::adjacency_list<boost::vecS,
00067                                       boost::listS,
00068                                       boost::directedS,
00069                                       VertProperty,
00070                                       EdgeProperty> Graph;
00071         typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
00072         typedef boost::graph_traits<Graph>::edge_descriptor Edge;
00073 
00074     private:
00078         Vertex current;
00079 
00083         Vertex previous;
00084 
00085     protected:
00089         Graph program;
00090 
00091         Vertex startv;
00092         Vertex exitv;
00093 
00097         std::string myName;
00098 
00102         std::string _text;
00103 
00107         std::vector<base::AttributeBase*> args;
00108 
00109         base::AttributeBase* retn;
00110 
00111         bool pausing;
00112         bool mstep;
00113         bool munload_on_stop;
00114 
00115         bool executeUntil();
00116         bool executeStep();
00117 
00118         ServicePtr context;
00119     public:
00129         FunctionGraph( const std::string& name, bool unload_on_stop );
00130 
00134         FunctionGraph( const FunctionGraph& orig );
00135 
00136         ~FunctionGraph();
00137 
00142         void setProgramService(ServicePtr myservice);
00143 
00148         void setUnloadOnStop(bool unload_on_stop);
00149 
00156         virtual bool needsStart() const { return !munload_on_stop; }
00157 
00161         void finish();
00162 
00163         virtual bool start();
00164 
00165         virtual bool execute();
00166 
00167         virtual void loading();
00168 
00169         virtual void unloading();
00170 
00171         virtual bool stop();
00172 
00173         virtual bool pause();
00174 
00175         virtual bool step();
00176 
00177         virtual bool stepDone() const;
00178 
00182         virtual void reset();
00183 
00184         virtual int  getLineNumber() const;
00185 
00186         virtual const std::string& getName() const;
00187 
00188         virtual FunctionGraph* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& replacementdss ) const;
00189 
00190         virtual FunctionGraph* clone() const;
00191 
00196         void setName(const std::string& _name);
00197 
00201         void setText( const std::string& t);
00202 
00203         std::string getText() const;
00204 
00205         void debugPrintout() const;
00206 
00207         Vertex startNode() const
00208         {
00209             return startv;
00210         }
00211 
00212         Vertex currentNode() const
00213         {
00214             return current;
00215         }
00216 
00217         Vertex previousNode() const
00218         {
00219             return previous;
00220         }
00221 
00222         Vertex exitNode() const
00223         {
00224             return exitv;
00225         }
00226 
00227         const Graph& getGraph() const
00228         {
00229             return program;
00230         }
00231 
00232         Graph& getGraph()
00233         {
00234             return program;
00235         }
00236 
00240         std::vector<base::AttributeBase*> getArguments() const {
00241             return args;
00242         }
00243 
00244         base::AttributeBase* getResult() const {
00245             return retn;
00246         }
00247 
00248         void addArgument( base::AttributeBase* a) {
00249             args.push_back(a);
00250         }
00251 
00255         void setResult( base::AttributeBase* r) { retn = r; }
00256 
00260         void clearArguments();
00261     };
00262 
00263 
00264 }}
00265 
00266 #endif