00001 // $Id: Utility.hh 1781 2011-04-11 12:10:19Z tho $ 00002 // 00003 // Copyright (C) 2009 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #ifndef HH_SENF_Utils_Console_Utility_ 00027 #define HH_SENF_Utils_Console_Utility_ 1 00028 00029 // Custom includes 00030 #include "Parse.hh" 00031 00032 //#include "Utility.mpp" 00033 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00034 00041 namespace senf { 00042 namespace console { 00043 00063 template <class CharT> 00064 struct CharAsString 00065 { 00066 CharAsString(); 00067 CharAsString(CharT value_); 00068 operator CharT () const; 00069 CharT value; 00070 }; 00071 00072 #ifndef DOXYGEN 00073 00074 template <class CharT> 00075 struct ArgumentTraits< CharAsString<CharT> > 00076 { 00077 typedef CharAsString<CharT> type; 00078 static bool const singleToken = true; 00079 00080 static void parse(ParseCommandInfo::TokensRange const & tokens, CharAsString<CharT> & out); 00081 static std::string description(); 00082 static std::string str(CharAsString<CharT> value); 00083 }; 00084 00085 template <class CharT> 00086 struct ReturnValueTraits< CharAsString<CharT> > 00087 { 00088 typedef CharAsString<CharT> type; 00089 00090 static void format(CharAsString<CharT> value, std::ostream & os); 00091 }; 00092 00093 #endif 00094 00102 template <class T> 00103 struct ValueRange 00104 { 00105 T low; 00106 T high; 00107 }; 00108 00109 #ifndef DOXYGEN 00110 00111 template <class T> 00112 struct ArgumentTraits< ValueRange<T> > 00113 { 00114 typedef ValueRange<T> type; 00115 static bool const singleToken = true; 00116 00117 static void parse(ParseCommandInfo::TokensRange const & tokens, type & out); 00118 static std::string description(); 00119 static std::string str(type const & value); 00120 }; 00121 00122 template <class T> 00123 struct ReturnValueTraits< ValueRange<T> > 00124 { 00125 typedef ValueRange<T> type; 00126 00127 static void format(type const & value, std::ostream & os); 00128 }; 00129 00130 #endif 00131 00174 template <class Enum> 00175 struct FlagCollection 00176 { 00177 operator unsigned long() const { return value; } 00178 FlagCollection() : value (0) {} 00179 FlagCollection(unsigned long value_) : value (value_) {} 00180 FlagCollection(Enum value_) : value (value_) {} 00181 unsigned long value; 00182 }; 00183 00184 #ifndef DOXYGEN 00185 00186 template <class Enum> 00187 struct ArgumentTraits< FlagCollection<Enum> > 00188 { 00189 typedef FlagCollection<Enum> type; 00190 static bool const singleToken = false; 00191 static void parse(ParseCommandInfo::TokensRange const & tokens, type & out); 00192 static std::string description(); 00193 static std::string str(type const & value); 00194 }; 00195 00196 template <class Enum> 00197 struct ReturnValueTraits< FlagCollection<Enum> > 00198 { 00199 typedef FlagCollection<Enum> type; 00200 static void format(type const & value, std::ostream & os); 00201 }; 00202 00203 #endif 00204 00205 }} 00206 00207 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00208 //#include "Utility.cci" 00209 #include "Utility.ct" 00210 #include "Utility.cti" 00211 #endif 00212 00213 00214 // Local Variables: 00215 // mode: c++ 00216 // fill-column: 100 00217 // comment-column: 40 00218 // c-file-style: "senf" 00219 // indent-tabs-mode: nil 00220 // ispell-local-dictionary: "american" 00221 // compile-command: "scons -u test" 00222 // End: