4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Traits internal header */
31 #include <boost/preprocessor/seq/for_each.hpp>
32 #include <boost/preprocessor/stringize.hpp>
33 #include <boost/preprocessor/facilities/empty.hpp>
34 #include <boost/bimap.hpp>
35 #include <boost/assign/list_inserter.hpp>
36 #include "../Utils/singleton.hh"
38 ///////////////////////////////ih.p////////////////////////////////////////
46 typedef boost::bimap<std::string, long> EnumTable;
48 long parseEnum(EnumTable const & table, ParseCommandInfo::TokensRange const & tokens);
49 std::string formatEnum(EnumTable const & table, long value);
51 template <class EnumType>
52 struct EnumTraits : public senf::singleton< EnumTraits<EnumType> >
54 using senf::singleton< EnumTraits<EnumType> >::instance;
58 # define SENF_CONSOLE_REGISTER_ENUM_ELT(r,d,e) \
59 (BOOST_PP_STRINGIZE(e), static_cast<long>(d e))
61 # define SENF_CONSOLE_REGISTER_ENUM_(Prefix, Type, Values) \
62 void senf_console_init_enum_table(Prefix Type) \
64 senf::console::detail::EnumTraits<Prefix Type> & traits ( \
65 senf::console::detail::EnumTraits<Prefix Type>::instance() ); \
66 if (traits.table.empty()) \
67 boost::assign::insert(traits.table) \
68 BOOST_PP_SEQ_FOR_EACH( SENF_CONSOLE_REGISTER_ENUM_ELT, Prefix, Values ); \
70 void senf_console_parse_argument( \
71 senf::console::ParseCommandInfo::TokensRange const & tokens, Prefix Type & out) \
73 senf_console_init_enum_table( Prefix Type() ); \
74 out = static_cast<Prefix Type>( \
75 senf::console::detail::parseEnum( \
76 senf::console::detail::EnumTraits<Prefix Type>::instance().table, tokens)); \
78 void senf_console_format_value(Prefix Type value, std::ostream & os) \
80 senf_console_init_enum_table( Prefix Type() ); \
81 os << senf::console::detail::formatEnum( \
82 senf::console::detail::EnumTraits<Prefix Type>::instance().table, \
83 static_cast<long>(value) ); \
90 ///////////////////////////////ih.e////////////////////////////////////////
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // compile-command: "scons -u test"