Orocos Real-Time Toolkit  2.5.0
parse_exception.hpp
00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Jul 15 11:21:23 CEST 2004  parse_exception.hpp
00003 
00004                         parse_exception.hpp -  description
00005                            -------------------
00006     begin                : Thu July 15 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens at 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 #ifndef ORO_PARSE_EXCEPTION_HPP
00038 #define ORO_PARSE_EXCEPTION_HPP
00039 
00040 #include <string>
00041 #include <vector>
00042 #include "rtt-scripting-config.h"
00043 #include "../base/DataSourceBase.hpp"
00044 
00045 #ifdef ORO_PRAGMA_INTERFACE
00046 #pragma interface
00047 #endif
00048 
00049 namespace RTT
00050 {
00051     class parse_exception;
00052 
00058     class RTT_SCRIPTING_EXPORT file_parse_exception
00059     {
00060         parse_exception* mpe;
00061         std::string mfile;
00062         int mline;
00063         int mcolumn;
00064         // make this private to prevent the compiler from adding it...
00065         file_parse_exception& operator=( const file_parse_exception& rhs );
00066     public:
00067         file_parse_exception( const file_parse_exception& rhs );
00068         file_parse_exception( parse_exception* pe, const std::string& file,
00069                               int line, int column )
00070             : mpe( pe ), mfile( file ), mline( line ), mcolumn( column )
00071         {
00072         }
00073         ~file_parse_exception();
00074 
00075         const std::string what() const;
00076     };
00077 
00083     class RTT_SCRIPTING_EXPORT parse_exception
00084     {
00085         // make these private
00086         parse_exception& operator=( const parse_exception& );
00087     protected:
00088         parse_exception() {};
00089     public:
00090         virtual ~parse_exception() {};
00091         virtual const std::string what() const = 0;
00092         virtual parse_exception* copy() const = 0;
00093     };
00094 
00095     namespace scripting {
00096 
00102         class RTT_SCRIPTING_EXPORT semantic_parse_exception
00103             : public parse_exception
00104         {
00105             // make these private
00106             semantic_parse_exception& operator=( const semantic_parse_exception& );
00107         protected:
00108             semantic_parse_exception() {};
00109         };
00110 
00116         class RTT_SCRIPTING_EXPORT fatal_syntactic_parse_exception
00117             : public parse_exception
00118         {
00119             // make these private
00120             fatal_syntactic_parse_exception& operator=( const fatal_syntactic_parse_exception& );
00121         protected:
00122             fatal_syntactic_parse_exception() {};
00123         };
00124 
00131         class RTT_SCRIPTING_EXPORT fatal_semantic_parse_exception
00132             : public parse_exception
00133         {
00134             // make these private
00135             fatal_semantic_parse_exception& operator=( const fatal_syntactic_parse_exception& );
00136         protected:
00137             fatal_semantic_parse_exception() {};
00138         };
00139 
00145         class RTT_SCRIPTING_EXPORT syntactic_parse_exception
00146             : public parse_exception
00147         {
00148             // make these private
00149             syntactic_parse_exception& operator=( const syntactic_parse_exception& );
00150         protected:
00151             syntactic_parse_exception() {};
00152         };
00153 
00154 
00155 
00156         class RTT_SCRIPTING_EXPORT parse_exception_illegal_identifier
00157             : public syntactic_parse_exception
00158         {
00159             std::string mident;
00160         public:
00161             parse_exception_illegal_identifier( const std::string& ident )
00162                 : mident( ident )
00163             {
00164             };
00165 
00166             const std::string what() const
00167             {
00168                 return "The string \"" + mident + "\" cannot be used as an identifer.";
00169             }
00170 
00171             parse_exception_illegal_identifier* copy() const
00172             {
00173                 return new parse_exception_illegal_identifier( *this );
00174             }
00175 
00176             const std::string& identifier() const
00177             {
00178                 return mident;
00179             }
00180         };
00181 
00186         class RTT_SCRIPTING_EXPORT parse_exception_semantic_error
00187             : public semantic_parse_exception
00188         {
00189             std::string mdesc;
00190         public:
00191             parse_exception_semantic_error( const std::string& desc )
00192                 : mdesc( desc )
00193             {
00194             };
00195 
00196             const std::string what() const
00197             {
00198                 return "Semantic error: " + mdesc;
00199             }
00200 
00201             parse_exception_semantic_error* copy() const
00202             {
00203                 return new parse_exception_semantic_error( *this );
00204             }
00205 
00206             const std::string& desc() const
00207             {
00208                 return mdesc;
00209             }
00210         };
00211 
00216         class RTT_SCRIPTING_EXPORT parse_exception_fatal_semantic_error
00217             : public fatal_semantic_parse_exception
00218         {
00219             std::string mdesc;
00220         public:
00221             parse_exception_fatal_semantic_error( const std::string& desc )
00222                 : mdesc( desc )
00223             {
00224             };
00225 
00226             const std::string what() const
00227             {
00228                 return "Fatal Semantic error: " + mdesc;
00229             }
00230 
00231             parse_exception_fatal_semantic_error* copy() const
00232             {
00233                 return new parse_exception_fatal_semantic_error( *this );
00234             }
00235 
00236             const std::string& desc() const
00237             {
00238                 return mdesc;
00239             }
00240         };
00241 
00248         class RTT_SCRIPTING_EXPORT parse_exception_parser_fail
00249             : public parse_exception
00250         {
00251             std::string mreason;
00252         public:
00253             parse_exception_parser_fail(const std::string& reason) : mreason(reason)
00254             {
00255             }
00256 
00257             const std::string what() const
00258             {
00259                 return "Parse Failure Exception: " + mreason;
00260             }
00261 
00262             parse_exception_parser_fail* copy() const
00263             {
00264                 return new parse_exception_parser_fail( *this );
00265             }
00266         };
00267 
00272         class RTT_SCRIPTING_EXPORT parse_exception_syntactic_error
00273             : public syntactic_parse_exception
00274         {
00275             std::string mdesc;
00276         public:
00277             parse_exception_syntactic_error( const std::string& desc )
00278                 : mdesc( desc )
00279             {
00280             };
00281 
00282             const std::string what() const
00283             {
00284                 return "Syntactic error: " + mdesc;
00285             }
00286 
00287             parse_exception_syntactic_error* copy() const
00288             {
00289                 return new parse_exception_syntactic_error( *this );
00290             }
00291 
00292             const std::string& desc() const
00293             {
00294                 return mdesc;
00295             }
00296         };
00297 
00298         class RTT_SCRIPTING_EXPORT parse_exception_no_such_component
00299             : public semantic_parse_exception
00300         {
00301             std::string mname;
00302             std::string mmeth;
00303         public:
00304             parse_exception_no_such_component( const std::string& name, const std::string& meth )
00305                 : mname( name ), mmeth(meth)
00306             {
00307             }
00308 
00309             const std::string what() const
00310             {
00311                 return "Service or Task \"" + mname + "\" has no Peer or Service "+mmeth+" (or "+mname+" was not found at all).";
00312             }
00313 
00314             parse_exception_no_such_component* copy() const
00315             {
00316                 return new parse_exception_no_such_component( *this );
00317             }
00318 
00319             const std::string& componentName() const
00320             {
00321                 return mname;
00322             }
00323         };
00324 
00325         class RTT_SCRIPTING_EXPORT parse_exception_no_such_method_on_component
00326             : public semantic_parse_exception
00327         {
00328             std::string mcomponentname;
00329             std::string mmethodname;
00330         public:
00331             parse_exception_no_such_method_on_component(
00332                                                         const std::string& componentname, const std::string& methodname )
00333                 : mcomponentname( componentname ), mmethodname( methodname )
00334             {
00335             };
00336 
00337             const std::string what() const
00338             {
00339                 return "No method \"" + mmethodname + "\" registered for the object or task \"" + mcomponentname + "\".";
00340             }
00341 
00342             parse_exception_no_such_method_on_component* copy() const
00343             {
00344                 return new parse_exception_no_such_method_on_component( *this );
00345             }
00346 
00347             const std::string& componentName() const
00348             {
00349                 return mcomponentname;
00350             }
00351 
00352             const std::string& methodName() const
00353             {
00354                 return mmethodname;
00355             }
00356         };
00357 
00358         class RTT_SCRIPTING_EXPORT parse_exception_wrong_number_of_arguments
00359             : public fatal_semantic_parse_exception
00360         {
00361             std::string mcomponentname;
00362             std::string mmethodname;
00363             int mexpectednumber;
00364             int mreceivednumber;
00365         public:
00366             parse_exception_wrong_number_of_arguments(
00367                                                       const std::string& componentname, const std::string& methodname,
00368                                                       int expectednumber, int receivednumber )
00369                 : mcomponentname( componentname ), mmethodname( methodname ),
00370                   mexpectednumber( expectednumber ),
00371                   mreceivednumber( receivednumber )
00372             {
00373             };
00374 
00375             const std::string what() const;
00376 
00377             parse_exception_wrong_number_of_arguments* copy() const
00378             {
00379                 return new parse_exception_wrong_number_of_arguments( *this );
00380             }
00381 
00382             const std::string& componentName() const
00383             {
00384                 return mcomponentname;
00385             }
00386 
00387             const std::string& methodName() const
00388             {
00389                 return mmethodname;
00390             }
00391 
00392             int expectedNumber() const
00393             {
00394                 return mexpectednumber;
00395             }
00396 
00397             int receivedNumber() const
00398             {
00399                 return mreceivednumber;
00400             }
00401         };
00402 
00403         class RTT_SCRIPTING_EXPORT parse_exception_wrong_type_of_argument
00404             : public fatal_semantic_parse_exception
00405         {
00406             std::string mcomponentname;
00407             std::string mmethodname;
00408             int margnumber;
00409             std::string mexpected;
00410             std::string mreceived;
00411         public:
00412             parse_exception_wrong_type_of_argument(
00413                                                    const std::string& componentname, const std::string& methodname,
00414                                                    int argnumber, const std::string& expected, const std::string& received )
00415                 : mcomponentname( componentname ), mmethodname( methodname ),
00416                   margnumber( argnumber ), mexpected( expected), mreceived( received )
00417             {
00418             };
00419 
00420             const std::string what() const;
00421 
00422             parse_exception_wrong_type_of_argument* copy() const
00423             {
00424                 return new parse_exception_wrong_type_of_argument( *this );
00425             }
00426 
00427             const std::string& componentName() const
00428             {
00429                 return mcomponentname;
00430             }
00431 
00432             const std::string& methodName() const
00433             {
00434                 return mmethodname;
00435             }
00436 
00437             int argumentNumber() const
00438             {
00439                 return margnumber;
00440             }
00441         };
00442 
00443         class RTT_SCRIPTING_EXPORT parse_exception_undefined_value
00444             : public fatal_semantic_parse_exception
00445         {
00446             std::string mname;
00447         public:
00448             parse_exception_undefined_value( const std::string& name )
00449                 : mname( name )
00450             {
00451             }
00452 
00453             const std::string what() const throw()
00454             {
00455                 return "Use of undefined value: \"" + mname + "\".";
00456             }
00457 
00458             parse_exception_undefined_value* copy() const throw()
00459             {
00460                 return new parse_exception_undefined_value( *this );
00461             }
00462 
00463             const std::string& name() {
00464                 return mname;
00465             }
00466         };
00467 
00468         class RTT_SCRIPTING_EXPORT parse_exception_no_such_constructor
00469             : public fatal_semantic_parse_exception
00470         {
00471             std::string margsig;
00472         public:
00473             parse_exception_no_such_constructor(const std::string& tname,
00474                                                 std::vector<base::DataSourceBase::shared_ptr> args);
00475 
00476             const std::string what() const { return margsig; }
00477 
00478             parse_exception_no_such_constructor* copy() const
00479             {
00480                 return new parse_exception_no_such_constructor( *this );
00481             }
00482         };
00483     }
00484 }
00485 
00486 #endif