FunctionGraphBuilder.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 PROGRAMGRAPH_HPP
00039 #define PROGRAMGRAPH_HPP
00040
00041 #include "FunctionGraph.hpp"
00042 #include "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 {
00052
00058 class RTT_API FunctionGraphBuilder
00059 {
00060 public:
00061
00062 typedef EdgeCondition::EdgeProperty EdgeProperty;
00063 typedef VertexNode::VertProperty VertProperty;
00064
00065 typedef boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, VertProperty, EdgeProperty> Graph;
00066 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
00067 typedef boost::graph_traits<Graph>::edge_descriptor Edge;
00068
00073 typedef FunctionGraph::Vertex CommandNode ;
00074
00079 typedef FunctionGraph::Edge ConditionEdge ;
00080
00084 FunctionGraphBuilder();
00085
00086 ~FunctionGraphBuilder();
00087
00092 void setLineNumber( int ln );
00093
00094 void setName(const std::string& _name);
00095
00099 FunctionGraphPtr startFunction( const std::string& fname );
00100
00108 void returnFunction( ConditionInterface* cond, int line );
00109
00114 FunctionGraphPtr endFunction( int line = 0 );
00115
00119 FunctionGraphPtr getFunction();
00120
00121 void startIfStatement( ConditionInterface* cond, int linenumber );
00122 void endIfBlock(int linenumber);
00123 void endElseBlock(int linenumber);
00124
00125 void startWhileStatement( ConditionInterface* cond, int linenumber );
00126 void endWhileBlock(int linenumber);
00127
00128 bool inLoop();
00129 bool breakLoop();
00130
00136 CommandNode addCommand( ConditionInterface* cond, CommandInterface* com );
00137
00143 void addConditionEdge( ConditionInterface* cond, CommandNode vert );
00144
00149 void closeConditionEdge( CommandNode vert, ConditionInterface* cond );
00150
00156 CommandNode moveTo( CommandNode _build, CommandNode _next, int linenr );
00157
00162 void setCommand( CommandInterface* comm );
00163
00168 CommandInterface* getCommand( CommandNode cn );
00169
00177 void setCommand( CommandNode vert, CommandInterface* comm);
00178
00187 CommandNode appendFunction( ConditionInterface* cond, FunctionGraphPtr fn, std::vector<DataSourceBase::shared_ptr> fnargs);
00188
00196 CommandNode setFunction( FunctionGraphPtr fn, std::vector<DataSourceBase::shared_ptr> fnargs);
00197
00204 CommandNode proceedToNext( int line_nr = 0 );
00205
00214 CommandNode proceedToNext( ConditionInterface* cond, int line_nr = 0 );
00215
00219 void connectToNext( CommandNode v, ConditionInterface* cond );
00220
00224 CommandNode buildNode() const;
00225
00229 size_t buildEdges() const;
00230
00234 CommandNode nextNode() const;
00235
00239 CommandNode build;
00240
00244 CommandNode next;
00245
00246 private:
00247
00248 FunctionGraphPtr func;
00249
00253 Graph* graph;
00254
00263 std::stack<CommandNode> branch_stack;
00264
00269 std::stack<CommandNode> break_stack;
00270 };
00271 }
00272
00273 #endif
00274
00275