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 HEX_DIGIT_H 00021 #define HEX_DIGIT_H 00022 00023 class hex_digit 00024 { 00025 grammar_to_parser::terminal< '0' > m_0; 00026 grammar_to_parser::terminal< '1' > m_1; 00027 grammar_to_parser::terminal< '2' > m_2; 00028 grammar_to_parser::terminal< '3' > m_3; 00029 grammar_to_parser::terminal< '4' > m_4; 00030 grammar_to_parser::terminal< '5' > m_5; 00031 grammar_to_parser::terminal< '6' > m_6; 00032 grammar_to_parser::terminal< '7' > m_7; 00033 grammar_to_parser::terminal< '8' > m_8; 00034 grammar_to_parser::terminal< '9' > m_9; 00035 grammar_to_parser::terminal< 'a' > m_a; 00036 grammar_to_parser::terminal< 'b' > m_b; 00037 grammar_to_parser::terminal< 'c' > m_c; 00038 grammar_to_parser::terminal< 'd' > m_d; 00039 grammar_to_parser::terminal< 'e' > m_e; 00040 grammar_to_parser::terminal< 'f' > m_f; 00041 grammar_to_parser::terminal< 'A' > m_A; 00042 grammar_to_parser::terminal< 'B' > m_B; 00043 grammar_to_parser::terminal< 'C' > m_C; 00044 grammar_to_parser::terminal< 'D' > m_D; 00045 grammar_to_parser::terminal< 'E' > m_E; 00046 grammar_to_parser::terminal< 'F' > m_F; 00047 public: 00048 void push_parsers( grammar_to_parser::parsers &l ) 00049 { 00050 l.push_back( &m_0 ); 00051 l.push_back( &m_1 ); 00052 l.push_back( &m_2 ); 00053 l.push_back( &m_3 ); 00054 l.push_back( &m_4 ); 00055 l.push_back( &m_5 ); 00056 l.push_back( &m_6 ); 00057 l.push_back( &m_7); 00058 l.push_back( &m_8 ); 00059 l.push_back( &m_9 ); 00060 l.push_back( &m_a ); 00061 l.push_back( &m_b ); 00062 l.push_back( &m_c ); 00063 l.push_back( &m_d ); 00064 l.push_back( &m_e ); 00065 l.push_back( &m_f ); 00066 l.push_back( &m_A ); 00067 l.push_back( &m_B ); 00068 l.push_back( &m_C ); 00069 l.push_back( &m_D ); 00070 l.push_back( &m_E ); 00071 l.push_back( &m_F ); 00072 } 00073 unsigned long evaluate() 00074 { 00075 if( m_0.is_parsed() ) return 0; 00076 if( m_1.is_parsed() ) return 1; 00077 if( m_2.is_parsed() ) return 2; 00078 if( m_3.is_parsed() ) return 3; 00079 if( m_4.is_parsed() ) return 4; 00080 if( m_5.is_parsed() ) return 5; 00081 if( m_6.is_parsed() ) return 6; 00082 if( m_7.is_parsed() ) return 7; 00083 if( m_8.is_parsed() ) return 8; 00084 if( m_9.is_parsed() ) return 9; 00085 if( m_A.is_parsed() || m_a.is_parsed() ) return 10; 00086 if( m_B.is_parsed() || m_b.is_parsed() ) return 11; 00087 if( m_C.is_parsed() || m_c.is_parsed() ) return 12; 00088 if( m_D.is_parsed() || m_d.is_parsed() ) return 13; 00089 if( m_E.is_parsed() || m_e.is_parsed() ) return 14; 00090 if( m_F.is_parsed() || m_f.is_parsed() ) return 15; 00091 return 0; 00092 } 00093 unsigned long get_base() 00094 { 00095 return 16; 00096 } 00097 }; 00098 00099 #endif