LexicalToolKit.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #ifndef KEYVALUE_LEXICAL_TOOL_KIT_H_
00029 #define KEYVALUE_LEXICAL_TOOL_KIT_H_
00030
00031 #include <boost/utility.hpp>
00032
00033 #include "keyvalue/extern/String.h"
00034 #include "keyvalue/extern/Ptime.h"
00035 #include "keyvalue/sys/exception/Exception.h"
00036 #include "keyvalue/util/Lexical.h"
00037
00038 namespace keyvalue {
00039 namespace frontend {
00040
00071 class LexicalToolKit : private boost::noncopyable {
00072
00073 public:
00074
00080 LexicalToolKit();
00081
00087 enum IO { none = 0x0, input = 0x1, output = 0x2, both = 0x3};
00088
00102 template <typename From, typename To>
00103 struct Helper {
00104
00105
00106 typedef To (*Type_)(const From&);
00107
00108
00109
00110 static Type_ LexicalToolKit::* converter_;
00111
00112
00113
00114 static IO LexicalToolKit::* io_;
00115 };
00116
00137 template <typename From, typename To>
00138 void
00139 set(IO io, typename Helper<From, To>::Type_ converter = util::Lexical);
00140
00156 template <typename From, typename To>
00157 bool
00158 isEnabled(IO io) const;
00159
00166 class Failure : public RuntimeError {
00167 };
00168
00193 template <typename To, typename From>
00194 To
00195 convert(From input) const;
00196
00197 private:
00198
00207 #define KV_LEXICAL_TOOL_KIT_PAIR(From, To) \
00208 Helper<From, To>::Type_ From##2##To##_; \
00209 IO From##2##To##_io_;
00210
00211 #include "keyvalue/frontend/LexicalToolKitPairs.h"
00212 #undef KV_LEXICAL_TOOL_KIT_PAIR
00213
00221 char endInitList;
00222
00223 };
00224
00225 }
00226 }
00227
00228 #endif // KEYVALUE_LEXICAL_TOOL_KIT_H_