LexicalToolKit.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *
00003  * Copyright (C) 2009-2010 Cassio Neri Moreira
00004  *
00005  * This file is part of the KeyValue library.
00006  *
00007  * The KeyValue library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or (at
00010  * your option) any later version.
00011  *
00012  * The KeyValue library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00015  * Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with KeyValue. If not, see <http://www.gnu.org/licenses/>.
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     // The converter's signature
00106     typedef To (*Type_)(const From&);
00107 
00108     // A pointer to LexicalToolKit's member which holds the corresponding
00109     // conversion function pointer.
00110     static Type_ LexicalToolKit::* converter_;
00111 
00112     // A pointer to the LexicalToolKit member which holds the corresponding
00113     // direction flag.
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 }; // class LexicalToolKit
00224 
00225 } // namespace frontend
00226 } // namespace keyvalue
00227 
00228 #endif // KEYVALUE_LEXICAL_TOOL_KIT_H_

Generated on Sat Mar 20 15:08:29 2010 for KeyValue by  doxygen 1.6.1