00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00077
00078
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
00111
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