element_parser.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2005 M.J. Zaki <zaki@cs.rpi.edu> Rensselaer Polytechnic Institute
00003  *  Written by parimi@cs.rpi.edu
00004  *  Updated by chaojv@cs.rpi.edu, alhasan@cs.rpi.edu, salems@cs.rpi.edu
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  */
00023 #ifndef _ELEMENT_PARSER
00024 #define _ELEMENT_PARSER
00025 #include<sstream>
00026 #include "helper_funs.h"
00027 
00034 template<typename P>
00035 class element_parser {};
00036 
00041 template<>
00042 class element_parser<int>
00043 {
00044 
00045  public:
00046 
00047   typedef int OBJ_T; 
00048   typedef int HASH_TYPE; // Input type for the hash function.
00049   typedef eqint COMP_FUNC; // Comparison function.
00050 
00056   static inline OBJ_T parse_element(char* word) { 
00057     return atoi(word);
00058   }
00059 
00060   static const OBJ_T& convert(const int& i) {
00061  
00062     return i;
00063   }
00064 
00065   static bool notEq(const int& i1, const int& i2) {
00066     return !(i1 == i2);
00067   }
00068 
00069   static const HASH_TYPE& conv_hash_type(const OBJ_T& s) {
00070     return s;
00071   }
00072 
00073 
00074 };//end clas element_parser<int>
00075 
00079 template<>
00080 class element_parser<std::string>
00081 {
00082 
00083  public:
00084 
00085   typedef std::string OBJ_T; 
00086   typedef const char* HASH_TYPE; // Input type for the hash function.
00087   typedef eqstr COMP_FUNC; // Comparison function.
00088 
00094   static inline OBJ_T parse_element(const char* word) { 
00095     return std::string(word);
00096   }
00097 
00098   static OBJ_T convert(const char* s) {
00099     return parse_element(s);
00100   }
00101 
00102   static OBJ_T convert(const int i) {
00103     std::ostringstream t_ss;
00104     t_ss << i;
00105  
00106     return t_ss.str();
00107   }
00108 
00109   static bool notEq(const std::string s1, const std::string s2) {
00110     return !(s1 == s2);
00111   }
00112 
00113   static HASH_TYPE conv_hash_type(const OBJ_T& s) {
00114     return s.c_str();
00115   }
00116 
00117 };//end clas element_parser<std::string>
00118 
00119 #endif

Generated on Wed Jul 26 14:01:08 2006 for DMTL by  doxygen 1.4.7