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

class_name.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 BRACKET_EXPRESSIONCLASS_NAME_H
00021 #define BRACKET_EXPRESSIONCLASS_NAME_H
00022 
00023 namespace bracket_expression {
00024 
00025 template<typename E>
00026 class class_name
00027 {
00028 typedef typename grammar_to_parser::basic_parser<E>::parser_list parser_list;
00029 typedef std::ctype_base ctypebase;
00030 
00031         grammar_to_parser::basic_pattern_parser<E>              m_alnum;
00032         grammar_to_parser::basic_pattern_parser<E>              m_cntrl;
00033         grammar_to_parser::basic_pattern_parser<E>              m_lower;
00034         grammar_to_parser::basic_pattern_parser<E>              m_space;
00035         grammar_to_parser::basic_pattern_parser<E>              m_alpha;
00036         grammar_to_parser::basic_pattern_parser<E>              m_digit;
00037         grammar_to_parser::basic_pattern_parser<E>              m_print;
00038         grammar_to_parser::basic_pattern_parser<E>              m_upper;
00039         grammar_to_parser::basic_pattern_parser<E>              m_blank;
00040         grammar_to_parser::basic_pattern_parser<E>              m_graph;
00041         grammar_to_parser::basic_pattern_parser<E>              m_punct;
00042         grammar_to_parser::basic_pattern_parser<E>              m_xdigit;
00043         
00044         int m_size;     
00045 public:
00046     class_name() : 
00047                 m_alnum( "alnum" ),
00048                 m_cntrl( "cntrl" ),
00049                 m_lower( "lower" ),
00050                 m_space( "space" ),
00051                 m_alpha( "alpha" ),
00052                 m_digit( "digit" ),
00053                 m_print( "print" ),
00054                 m_upper( "upper" ),
00055                 m_blank( "blank" ),
00056                 m_graph( "graph" ),
00057                 m_punct( "punct" ),
00058                 m_xdigit( "xdigit" ),
00059                 m_size(0) {};
00060         
00061         int matched_size() { return m_size; }
00062         
00063         void push_parsers( parser_list &l )
00064         {
00065                 l.push_back(&m_alnum);
00066                 l.push_back(&m_cntrl);
00067                 l.push_back(&m_lower);
00068                 l.push_back(&m_space);
00069                 l.push_back(&m_alpha);
00070                 l.push_back(&m_digit);
00071                 l.push_back(&m_print);
00072                 l.push_back(&m_upper);
00073                 l.push_back(&m_blank);
00074                 l.push_back(&m_graph);
00075                 l.push_back(&m_punct);
00076                 l.push_back(&m_xdigit);
00077         }
00078         
00079         unsigned long compare( const E* buf, const unsigned long buf_length )
00080         {
00081                 std::ctype_base t;
00082                 int ret = 0;
00083                 ctypebase::mask m;
00084                 
00085                 
00086                 if( m_alnum.is_parsed() ) m=ctypebase::alnum;
00087                 if( m_cntrl.is_parsed() ) m=ctypebase::cntrl;
00088                 if( m_lower.is_parsed() ) m=ctypebase::lower;
00089                 if( m_space.is_parsed() ) m=ctypebase::space;
00090                 if( m_alpha.is_parsed() ) m=ctypebase::alpha;
00091                 if( m_digit.is_parsed() ) m=ctypebase::digit;
00092                 if( m_print.is_parsed() ) m=ctypebase::print;
00093                 if( m_upper.is_parsed() ) m=ctypebase::upper;
00094 //              if( m_blank.is_parsed() ) m=ctypebase::blank;
00095                 if( m_graph.is_parsed() ) m=ctypebase::graph;
00096                 if( m_punct.is_parsed() ) m=ctypebase::punct;
00097                 if( m_xdigit.is_parsed() ) m=ctypebase::xdigit;
00098                 
00099                 while( m_size < buf_length )
00100                 {
00101                         if( !std::use_facet< std::ctype<E> >(std::locale()).is( buf, 
00102                                                                                                         buf+m_size+1, &m ) )
00103                         {
00104                                 break;
00105                         }
00106                         m_size++;
00107                 }
00108                 
00109                 if( m_size > 0 )
00110                         return 0;
00111                 else
00112                         return 1;
00113         }
00114         
00115 
00116     ~class_name()
00117         {
00118         }
00119 
00120 };
00121 
00122 };
00123 
00124 #endif

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