Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

object_parser.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004-2006 by Radko Mihal                                *
00003  *   rmihal@pobox.sk                                                       *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
00019  ***************************************************************************/
00020 #ifndef GRAMMAR_TO_PARSEROBJECT_PARSER_H
00021 #define GRAMMAR_TO_PARSEROBJECT_PARSER_H
00022 
00023 
00024 namespace grammar_to_parser {
00025 
00033 template< typename E, typename A >
00034 class basic_object_parser : public basic_parser<E>, public std::auto_ptr<A>
00035 {
00036 public:
00037 typedef std::auto_ptr<A> std_auto_ptr;
00038 typedef typename basic_parser<E>::symbol_type symbol_type;
00040         basic_object_parser( const char* name, symbol_type type = terminal_type);
00041         
00043         basic_object_parser( const char* name, 
00044                                                 const A &rhs, 
00045                                                 symbol_type type = terminal_type);
00046          
00048         basic_object_parser( const basic_object_parser& rhs );
00049                 
00050     virtual ~basic_object_parser();
00051         
00052         virtual bool is_valid() const { return get() != NULL; }
00053 
00058         virtual A& get_valid()
00059         {
00060                 if( !is_valid() ) 
00061                 {
00062                         std_auto_ptr::operator=( std_auto_ptr(new A()) );
00063                 }
00064                 return std_auto_ptr::operator *();
00065         }
00066         
00068         virtual void invalidate() 
00069         { 
00070                 std_auto_ptr::operator = ( std_auto_ptr(NULL) ); 
00071         }
00072         
00076 //      virtual void trace_on_fly() 
00077 //      {
00078 //              get_valid().get_name();
00079 //      }
00080         
00081 protected:
00083         virtual void prepare_for_parsing()
00084         {
00085                 basic_parser<E>::prepare_for_parsing();
00086                 get_valid();
00087         }
00089         virtual void prepare_for_formatting() 
00090         {
00091                 basic_parser<E>::prepare_for_formatting();
00092                 get_valid();
00093         };
00094 };
00095 
00096 template< typename E, typename A >
00097 basic_object_parser<E,A>::basic_object_parser( const char* name, symbol_type type ) 
00098 : basic_parser<E>(name,type), std::auto_ptr<A>(NULL) 
00099 {
00100 }
00101 
00102 template< typename E, typename A >
00103 basic_object_parser<E,A>::basic_object_parser( const char* name, 
00104                                                                                                 const A &rhs, 
00105                                                                                                 symbol_type type )
00106 : basic_parser<E>(name,type), std::auto_ptr<A>( new A(rhs) ) 
00107 {
00108 }
00109 
00110 // !!!! - the conversion from const to non const - if someone wants a 
00111 // copy of A object, should use previous constructor
00112 template< typename E, typename A >
00113 basic_object_parser<E,A>::basic_object_parser(const basic_object_parser& rhs )
00114 : basic_parser<E>(rhs), std::auto_ptr<A>(const_cast<basic_object_parser&>(rhs).release())
00115 {
00116 }
00117 
00118 template< typename E, typename A >
00119 basic_object_parser<E,A>::~basic_object_parser() 
00120 {
00121 }
00122 
00123 
00124 };
00125 
00126 #endif

Generated on Sun Jul 2 18:39:43 2006 for grammar2parser.kdevelop by  doxygen 1.4.1