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

except_terminal.h

00001 /***************************************************************************
00002  *   Copyright (C) 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_PARSEREXCEPT_TERMINAL_H
00021 #define GRAMMAR_TO_PARSEREXCEPT_TERMINAL_H
00022 
00023 #include "object_parser.h"
00024 #include "choice.h"
00025 
00026 namespace grammar_to_parser {
00027 
00037 template< typename E, typename except_choice >
00038 class basic_except_terminal : public basic_object_parser<E,E>
00039 {
00040 public:
00041         basic_except_terminal() : basic_object_parser<E,E>("ExceptTerminal") {};
00042 
00047     unsigned long parse( const E *buf, const unsigned long buf_length )
00048         {
00049                 prepare_for_parsing();
00050         
00051                 basic_choice<E,except_choice>   except;
00052                 except.parse( buf, buf_length );
00053                 if( !except.is_parsed() && buf_length > 0 )
00054                 {
00055                         std_auto_ptr::operator=( std_auto_ptr(new E(buf[0])) );
00056                         m_parsed_size = 1;
00057                         m_is_parsed = true;
00058                 }
00059                 return m_parsed_size;
00060         }
00061 
00066         std::basic_istream<E>& parse( std::basic_istream<E>& is )
00067         {
00068                 prepare_for_parsing();
00069         
00070                 basic_choice<E,except_choice>   except;
00071                 std::streampos str_pos = is.tellg();
00072                 E input = 0;
00073                 
00074                 is.read( &input, 1 );
00075                 if( is.good() )
00076                 {
00077                         except.parse( &input, 1 );
00078                         if( !except.is_parsed() )
00079                         {
00080                                 std_auto_ptr::operator =( std_auto_ptr(new E(input)) );;
00081                                 m_parsed_size = 1;
00082                                 m_is_parsed = true;
00083                         }
00084                         else
00085                         {
00086                                 is.clear();
00087                                 is.seekg( str_pos );
00088                         }
00089                 }
00090                 return is;
00091         }
00092 
00093         
00097         std::basic_ostream<E>& format( std::basic_ostream<E>& os )
00098         {
00099                 prepare_for_formatting();
00100         
00101                 std::streampos strPos = os.tellp();
00102                 if( (std::streamoff)strPos < 0 ) strPos = 0;
00103         
00104                 E out = get_valid();
00105                 if( os.good() ) 
00106                 {
00107                         os.write( (const E*)&out,sizeof(E) );
00108                         m_formatted_size = sizeof(E);
00109                         m_is_formatted = true;
00110                 }
00111                 else 
00112                 {
00113                         os.clear();
00114                         os.seekp( strPos );
00115                 }
00116                 return os;
00117         }
00118         
00119 };
00120 
00124 template< class except_choice >
00125 class except_terminal : public basic_except_terminal<char,except_choice>
00126 {
00127 };
00128 
00132 template< class except_choice >
00133 class wexcept_terminal : public basic_except_terminal<wchar_t,except_choice>
00134 {
00135 };
00136 
00137 };
00138 
00139 #endif

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