PropertyParser.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Sat May 21 20:15:51 CEST 2005  PropertyParser.cxx
00003 
00004                         PropertyParser.cxx -  description
00005                            -------------------
00006     begin                : Sat May 21 2005
00007     copyright            : (C) 2005 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 
00039 
00040 #include "PropertyParser.hpp"
00041 #include "parser-debug.hpp"
00042 #include "parse_exception.hpp"
00043 #include "../TaskContext.hpp"
00044 #include "parser-types.hpp"
00045 
00046 #include <Property.hpp>
00047 #include <PropertyBag.hpp>
00048 #include <boost/bind.hpp>
00049 
00050 namespace RTT
00051 {
00052     using boost::bind;
00053     using namespace detail;
00054     using namespace boost;
00055 
00056 
00057     error_status<> PropertyParser::handle_no_property(scanner_t const& scan, parser_error<PropertyErrors, iter_t>&e )
00058     {
00059         //std::cerr<<"Returning accept"<<std::endl;
00060         // ok, got as far as possible, _property contains the furthest we got.
00061         return error_status<>( error_status<>::accept, advance_on_error );
00062     }
00063 
00064     PropertyParser::PropertyParser(CommonParser& cp)
00065         : commonparser(cp), _bag(0), _property(0)
00066     {
00067         BOOST_SPIRIT_DEBUG_RULE( propertylocator );
00068         // find as far as possible a property without throwing an exception
00069         // outside our interface
00070         propertylocator =
00071             !my_guard
00072             ( +(commonparser.notassertingidentifier >> ".")[boost::bind( &PropertyParser::locateproperty, this, _1, _2 ) ])
00073             [ boost::bind(&PropertyParser::handle_no_property, this, _1, _2) ];
00074     }
00075 
00076     void PropertyParser::setPropertyBag( PropertyBag* bg )
00077     {
00078         _bag = bg;
00079         _property = 0;
00080         advance_on_error = 0;
00081     }
00082 
00083     void PropertyParser::reset()
00084     {
00085         _property = 0;
00086         _bag      = 0;
00087         advance_on_error = 0;
00088     }
00089 
00090     void PropertyParser::locateproperty( iter_t begin, iter_t end )
00091     {
00092         std::string name( begin, end );
00093         name.erase( name.length() -1  ); // compensate for extra "."
00094 
00095         //std::cerr<< "PropParser: trying: "<< name;
00096         if ( _bag && _bag->find(name) ) {
00097             //std::cerr<< " found !" <<std::endl;
00098             // guaranteed to be non-null :
00099             PropertyBase* propbase = _bag->find( name );
00100             Property<PropertyBag>* propbag = dynamic_cast<Property<PropertyBag> *>( propbase );
00101             if ( propbag ) {
00102                 //std::cerr<< "PropParser: is a bag." <<std::endl;
00103                 // success
00104                 advance_on_error += end.base() - begin.base();
00105                 _bag = &(propbag->set());
00106                 _property = propbase;
00107             }
00108             else {
00109                 //std::cerr<< "PropParser: not a bag." <<std::endl;
00110                 throw_(begin, bag_not_found );
00111                 // a property was found, but it was not a bag.
00112                 // Do not Consume the input
00113             }
00114             // if _property is not a bag, throw. The next
00115             // locateproperty will throw or if no more 'subprop.' found,
00116         }
00117         else {
00118             //std::cerr<< " not found !" <<std::endl;
00119             // do not consume input.
00120             throw_(begin, bag_not_found );
00121         }
00122     }
00123 
00124     rule_t& PropertyParser::locator()
00125     {
00126         return propertylocator;
00127     }
00128 }
00129 


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:01:57