Orocos Real-Time Toolkit  2.9.0
ConditionParser.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon May 10 19:10:37 CEST 2004 ConditionParser.cxx
3 
4  ConditionParser.cxx - description
5  -------------------
6  begin : Mon May 10 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, *
24  * Suite 330, Boston, MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 
28 #include "parser-debug.hpp"
29 #include "parse_exception.hpp"
30 #ifdef ORO_PRAGMA_INTERFACE
31 #pragma implementation
32 #endif
33 #include "ConditionParser.hpp"
34 
35 #include "ConditionDuration.hpp"
36 #include "ConditionTrue.hpp"
37 #include "ConditionFalse.hpp"
39 #include "ConditionComposite.hpp"
40 
41 #include <boost/bind.hpp>
42 
43 #include "TryCommand.hpp"
44 
45 namespace RTT
46 {
47  using namespace detail;
48  using boost::bind;
49 
50 
51 
53  : ds_bool( 0 ), context( c ), commonparser(cp), expressionparser( c, caller, cp )
54  {
55  BOOST_SPIRIT_DEBUG_RULE( condition );
56 
61  condition =
62  expressionparser.parser() [
63  bind( &ConditionParser::seenexpression, this ) ];
64  }
65 
67  {
68  // not strictly needed because its a smart_ptr
69  ds_bool = 0;
70  }
71 
73  {
74  }
75 
76  void ConditionParser::seenexpression()
77  {
78  // get the datasource parsed by the ExpressionParser..
80  expressionparser.getResult();
81  expressionparser.dropResult();
82 
83  // The reference count is stored in the DataSource itself !
84  // so the ref cnt information is not lost in this cast
85  ds_bool =
86  dynamic_cast<DataSource<bool>*>( mcurdata.get() );
87  if ( ds_bool )
88  {
89  mcurdata = 0;
90  }
91  else
92  {
93  // we only want boolean expressions..
95  "Attempt to use a non-boolean value as a condition." );
96  }
97  }
98 
100  {
101  // wrap the datasource in a ConditionBoolDataSource..
102  return new ConditionBoolDataSource( ds_bool.get() );
103  }
104 
108  std::pair<ActionInterface*,ConditionInterface*> ConditionParser::getParseResultAsCommand()
109  {
110  EvalCommand* ec = new EvalCommand( ds_bool );
111  EvalCommandResult* ecr = new EvalCommandResult( ec->cache() );
112  return std::make_pair( ec, ecr );
113  //return std::pair<ActionInterface*,ConditionInterface*>(0,0);
114  }
115 }
std::pair< base::ActionInterface *, ConditionInterface * > getParseResultAsCommand()
Retrieve the result as a command, condition pair.
virtual result_t get() const =0
Return the data as type T.
ConditionInterface * getParseResult()
Call this to get the parsed condition.
ConditionParser(TaskContext *context, ExecutionEngine *caller, CommonParser &cp)
This interface represents the concept of a condition which can be evaluated and return true or false...
Evaluates a internal::DataSource<bool> in a command.
Definition: TryCommand.hpp:127
parse_exception class that is used for various semantic errors for which it was not worth defining a ...
This class contains some very common parser definitions.
An execution engine serialises (executes one after the other) the execution of all commands...
The result of a command which evaluates a boolean DataSource.
Definition: TryCommand.hpp:157
base::DataSourceBase::shared_ptr getResult()
A Condition which holds a boolean DataSource.
internal::AssignableDataSource< bool >::shared_ptr cache()
Definition: TryCommand.cpp:152
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52