utils.h

00001 #ifndef XFLTK__CAST_H_
00002 #define XFLTK__CAST_H_
00003 
00004 #include <sstream>
00005 #include <cstring>
00006 #include <algorithm>
00007 
00008 namespace xfltk {
00009 
00010 namespace utils {
00011 
00012 template <typename dst, typename src>
00013 dst cast(const src& arg) {
00014         std::stringstream s;
00015         s << arg;
00016         dst result;
00017         s >> result;
00018         return result;
00019 }
00020 
00021 struct ltstr {
00022   bool operator()(const char* s1, const char* s2) const {
00023     return strcmp(s1, s2) < 0;
00024   }
00025 };
00026 
00027 struct eqstr {
00028         bool operator()(const char* s1, const char* s2) const {
00029                 return strcmp(s1, s2) == 0;
00030         }
00031 };
00032 
00033 template <typename Iterator, typename Value>
00034 Value find_pair(Iterator begin, Value to_find) {
00035         while (*begin != 0) {
00036                 if (eqstr()(*begin, to_find))
00037                         return *(++begin);
00038                 begin += 2;
00039         }
00040         return 0;
00041 }
00042 
00043 char* strcopy(const char* src);
00044 
00045 };      //namespace utils
00046 
00047 };      //namespace xfltk
00048 
00049 #endif /*XFLTK__CAST_H_*/

Generated on Tue Jan 3 14:32:36 2006 for xfltk by  doxygen 1.4.6-NO