Orocos Real-Time Toolkit
2.6.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Mon Jan 19 14:11:21 CET 2004 ProgramGraph.hpp 00003 00004 ProgramGraph.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 PROGRAMGRAPH_HPP 00039 #define PROGRAMGRAPH_HPP 00040 00041 #include "FunctionGraph.hpp" 00042 #include "../base/DataSourceBase.hpp" 00043 00044 #include <utility> // for std::pair 00045 #include <stack> 00046 #include <map> 00047 #include <string> 00048 #include <boost/graph/graph_traits.hpp> 00049 00050 namespace RTT 00051 { namespace scripting { 00052 00053 00059 class RTT_SCRIPTING_API FunctionGraphBuilder 00060 { 00061 public: 00062 00063 typedef EdgeCondition::EdgeProperty EdgeProperty; 00064 typedef VertexNode::VertProperty VertProperty; 00065 00066 typedef boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, VertProperty, EdgeProperty> Graph; 00067 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex; 00068 typedef boost::graph_traits<Graph>::edge_descriptor Edge; 00069 00074 typedef FunctionGraph::Vertex CommandNode ; 00075 00080 typedef FunctionGraph::Edge ConditionEdge ; 00081 00085 FunctionGraphBuilder(); 00086 00087 ~FunctionGraphBuilder(); 00088 00093 void setLineNumber( int ln ); 00094 00095 void setName(const std::string& _name); 00096 00100 FunctionGraphPtr startFunction( const std::string& fname ); 00101 00109 void returnFunction( ConditionInterface* cond, int line ); 00110 00115 FunctionGraphPtr endFunction( int line = 0 ); 00116 00120 FunctionGraphPtr getFunction(); 00121 00122 void startIfStatement( ConditionInterface* cond, int linenumber ); 00123 void endIfBlock(int linenumber); 00124 void endElseBlock(int linenumber); 00125 00126 void startWhileStatement( ConditionInterface* cond, int linenumber ); 00127 void endWhileBlock(int linenumber); 00128 00129 bool inLoop(); 00130 bool breakLoop(); 00131 00137 CommandNode addCommand( ConditionInterface* cond, base::ActionInterface* com ); 00138 00144 void addConditionEdge( ConditionInterface* cond, CommandNode vert ); 00145 00150 void closeConditionEdge( CommandNode vert, ConditionInterface* cond ); 00151 00157 CommandNode moveTo( CommandNode _build, CommandNode _next, int linenr ); 00158 00163 void setCommand( base::ActionInterface* comm ); 00164 00169 base::ActionInterface* getCommand( CommandNode cn ); 00170 00178 void setCommand( CommandNode vert, base::ActionInterface* comm); 00179 00188 CommandNode appendFunction( ConditionInterface* cond, FunctionGraphPtr fn, std::vector<base::DataSourceBase::shared_ptr> fnargs); 00189 00197 CommandNode setFunction( FunctionGraphPtr fn, std::vector<base::DataSourceBase::shared_ptr> fnargs); 00198 00205 CommandNode proceedToNext( int line_nr = 0 ); 00206 00215 CommandNode proceedToNext( ConditionInterface* cond, int line_nr = 0 ); 00216 00220 void connectToNext( CommandNode v, ConditionInterface* cond ); 00221 00225 CommandNode buildNode() const; 00226 00230 size_t buildEdges() const; 00231 00235 CommandNode nextNode() const; 00236 00240 CommandNode build; 00241 00245 CommandNode next; 00246 00247 private: 00248 00249 FunctionGraphPtr func; 00250 00254 Graph* graph; 00255 00264 std::stack<CommandNode> branch_stack; 00265 00270 std::stack<CommandNode> break_stack; 00271 }; 00272 }} 00273 00274 #endif 00275 00276