00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026
00027
00028
00029 #include <boost/format.hpp>
00030
00031 #define prefix_
00032
00033
00034 #ifndef DOXYGEN
00035
00036
00037
00038
00039 template <class Collection>
00040 prefix_ std::string
00041 senf::console::detail::CollectionArgumentTraitsBase<Collection>::description()
00042 {
00043 return senf::prettyBaseName(typeid(Collection)) + "<"
00044 + ArgumentTraits<typename Collection::value_type>::description() + ">";
00045 }
00046
00047 template <class Collection>
00048 prefix_ std::string
00049 senf::console::detail::CollectionArgumentTraitsBase<Collection>::str(Collection const & value)
00050 {
00051 std::stringstream ss;
00052 senf::console::format(value, ss);
00053 return ss.str();
00054 }
00055
00056
00057
00058
00059 template <class Collection, class Adder>
00060 prefix_ void senf::console::detail::CollectionArgumentTraits<Collection,Adder>::
00061 parse(ParseCommandInfo::TokensRange const & tokens, Collection & out)
00062 {
00063 out.clear();
00064 CheckedArgumentIteratorWrapper arg (tokens);
00065 while (arg) {
00066 typename Collection::value_type v;
00067 senf::console::parse( *(arg++), v );
00068 Adder::add(out,v);
00069 }
00070 }
00071
00072
00073
00074
00075 template <class Collection>
00076 prefix_ void
00077 senf::console::detail::CollectionReturnValueTraits<Collection>::format(Collection const & value,
00078 std::ostream & os)
00079 {
00080 os << "(";
00081 typename type::const_iterator i (value.begin());
00082 typename type::const_iterator const i_end (value.end());
00083 if (i != i_end)
00084 for (;;) {
00085 os << senf::console::str(*i);
00086 if (++i == i_end)
00087 break;
00088 else
00089 os << " ";
00090 }
00091 os << ")";
00092 }
00093
00094
00095
00096
00097 template <class Collection>
00098 prefix_ void senf::console::detail::MapArgumentTraits<Collection>::
00099 parse(ParseCommandInfo::TokensRange const & tokens, Collection & out)
00100 {
00101 out.clear();
00102 CheckedArgumentIteratorWrapper arg (tokens);
00103 while (arg) {
00104 typename Collection::key_type key;
00105 typename Collection::mapped_type data;
00106 senf::console::parse( *(arg++), key );
00107 ParseCommandInfo::TokensRange sep (*(arg++));
00108 if (sep.size() != 1 || sep[0].type() != Token::OtherPunctuation || sep[0].value() != "=")
00109 throw SyntaxErrorException("'=' expected");
00110 senf::console::parse( *(arg++), data );
00111 out.insert(std::make_pair(key,data));
00112 }
00113 }
00114
00115 template <class Collection>
00116 prefix_ std::string senf::console::detail::MapArgumentTraits<Collection>::description()
00117 {
00118 return senf::prettyBaseName(typeid(Collection)) + "<"
00119 + ArgumentTraits<typename Collection::key_type>::description() + ","
00120 + ArgumentTraits<typename Collection::mapped_type>::description() + ">";
00121 }
00122
00123 template <class Collection>
00124 prefix_ std::string
00125 senf::console::detail::MapArgumentTraits<Collection>::str(Collection const & value)
00126 {
00127 std::stringstream ss;
00128 senf::console::format(value, ss);
00129 return ss.str();
00130 }
00131
00132
00133
00134
00135 template <class Collection>
00136 prefix_ void
00137 senf::console::detail::MapReturnValueTraits<Collection>::format(Collection const & value,
00138 std::ostream & os)
00139 {
00140 os << "(";
00141 typename type::const_iterator i (value.begin());
00142 typename type::const_iterator const i_end (value.end());
00143 if (i != i_end)
00144 for (;;) {
00145 os << senf::console::str(i->first)
00146 << "="
00147 << senf::console::str(i->second);
00148 if (++i == i_end)
00149 break;
00150 else
00151 os << " ";
00152 }
00153 os << ")";
00154 }
00155
00156
00157
00158
00159 template <class T1, class T2>
00160 prefix_ void senf::console::ArgumentTraits< std::pair<T1,T2> >::
00161 parse(ParseCommandInfo::TokensRange const & tokens, type & out)
00162 {
00163 CheckedArgumentIteratorWrapper arg (tokens);
00164 senf::console::parse( *(arg++), out.first );
00165 senf::console::parse( *(arg++), out.second );
00166 }
00167
00168 template <class T1, class T2>
00169 prefix_ std::string senf::console::ArgumentTraits< std::pair<T1,T2> >::description()
00170 {
00171 return (boost::format("pair<%s,%s>")
00172 % ArgumentTraits<T1>::description()
00173 % ArgumentTraits<T2>::description()).str();
00174 }
00175
00176 template <class T1, class T2>
00177 prefix_ std::string senf::console::ArgumentTraits< std::pair<T1,T2> >::str(type const & value)
00178 {
00179 std::stringstream ss;
00180 senf::console::format(value, ss);
00181 return ss.str();
00182 }
00183
00184
00185
00186
00187 template <class T1, class T2>
00188 prefix_ void senf::console::ReturnValueTraits< std::pair<T1,T2> >::format(type const & value,
00189 std::ostream & os)
00190 {
00191 os << "(" << senf::console::str(value.first)
00192 << " " << senf::console::str(value.second) << ")";
00193 }
00194
00195 #endif
00196
00197
00198 #undef prefix_
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209