FunctionGraphBuilder.hpp

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 "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 {
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 
Generated on Thu Dec 23 13:22:37 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3