Go to the documentation of this file.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 PROGRAMGRAPH_HPP
00039 #define PROGRAMGRAPH_HPP
00040
00041 #include "FunctionGraph.hpp"
00042 #include "../base/DataSourceBase.hpp"
00043
00044 #include <utility>
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