ConditionParser.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon May 10 19:10:37 CEST 2004  ConditionParser.cxx
00003 
00004                         ConditionParser.cxx -  description
00005                            -------------------
00006     begin                : Mon May 10 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 Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place,                                    *
00024  *   Suite 330, Boston, MA  02111-1307  USA                                *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 #include "parser-debug.hpp"
00029 #include "parse_exception.hpp"
00030 #ifdef ORO_PRAGMA_INTERFACE
00031 #pragma implementation
00032 #endif
00033 #include "ConditionParser.hpp"
00034 
00035 #include "ConditionDuration.hpp"
00036 #include "ConditionTrue.hpp"
00037 #include "ConditionFalse.hpp"
00038 #include "ConditionBoolDataSource.hpp"
00039 #include "ConditionComposite.hpp"
00040 
00041 #include <boost/bind.hpp>
00042 
00043 #include "TryCommand.hpp"
00044 
00045 namespace RTT
00046 {
00047     using namespace detail;
00048     using boost::bind;
00049 
00050 
00051 
00052     ConditionParser::ConditionParser( TaskContext* c, ExecutionEngine* caller, CommonParser& cp )
00053         : ds_bool( 0 ), context( c ), commonparser(cp), expressionparser( c, caller, cp )
00054     {
00055         BOOST_SPIRIT_DEBUG_RULE( condition );
00056 
00061         condition =
00062             expressionparser.parser() [
00063                                        bind( &ConditionParser::seenexpression, this ) ];
00064     }
00065 
00066     void ConditionParser::reset()
00067     {
00068         // not strictly needed because its a smart_ptr
00069         ds_bool = 0;
00070     }
00071 
00072     ConditionParser::~ConditionParser()
00073     {
00074     }
00075 
00076     void ConditionParser::seenexpression()
00077     {
00078         // get the datasource parsed by the ExpressionParser..
00079         DataSourceBase::shared_ptr mcurdata =
00080             expressionparser.getResult();
00081         expressionparser.dropResult();
00082 
00083         // The reference count is stored in the DataSource itself !
00084         // so the ref cnt information is not lost in this cast
00085         ds_bool =
00086             dynamic_cast<DataSource<bool>*>( mcurdata.get() );
00087         if ( ds_bool )
00088             {
00089                 mcurdata = 0;
00090             }
00091         else
00092             {
00093                 // we only want boolean expressions..
00094                 throw parse_exception_semantic_error(
00095                                                      "Attempt to use a non-boolean value as a condition." );
00096             }
00097     }
00098 
00099     ConditionInterface* ConditionParser::getParseResult()
00100     {
00101         // wrap the datasource in a ConditionBoolDataSource..
00102         return new ConditionBoolDataSource( ds_bool.get() );
00103     }
00104 
00108     std::pair<ActionInterface*,ConditionInterface*> ConditionParser::getParseResultAsCommand()
00109     {
00110         EvalCommand* ec = new EvalCommand( ds_bool );
00111         EvalCommandResult* ecr = new EvalCommandResult( ec->cache() );
00112         return std::make_pair( ec, ecr );
00113         //return std::pair<ActionInterface*,ConditionInterface*>(0,0);
00114     }
00115 }


rtt
Author(s): RTT Developers
autogenerated on Thu Jan 2 2014 11:35:19