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 VectorSupport non-inline template implementation */
26 //#include "VectorSupport.ih"
29 #include <boost/format.hpp>
32 ///////////////////////////////ct.p////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////
37 // senf::console::detail::CollectionArgumentTraitsBase<Collection>
39 template <class Collection>
41 senf::console::detail::CollectionArgumentTraitsBase<Collection>::description()
43 std::string type (prettyName(typeid(Collection)));
44 std::string::size_type e (type.find('<'));
45 if (e == std::string::npos) e = type.size();
46 std::string::size_type b (type.rfind(':', e));
47 if (b == std::string::npos) b = 0; else ++b;
48 return type.substr(b,e-b) + "<"
49 + ArgumentTraits<typename Collection::value_type>::description() + ">";
52 template <class Collection>
54 senf::console::detail::CollectionArgumentTraitsBase<Collection>::str(Collection const & value)
57 senf::console::format(value, ss);
61 ///////////////////////////////////////////////////////////////////////////
62 // senf::console::detail::CollectionArgumentTraits<Collection,Adder>
64 template <class Collection, class Adder>
65 prefix_ void senf::console::detail::CollectionArgumentTraits<Collection,Adder>::
66 parse(ParseCommandInfo::TokensRange const & tokens, Collection & out)
69 CheckedArgumentIteratorWrapper arg (tokens);
71 typename Collection::value_type v;
72 senf::console::parse( *(arg++), v );
77 ///////////////////////////////////////////////////////////////////////////
78 // senf::console::detail::CollectionReturnValueTraits<Collection>
80 template <class Collection>
82 senf::console::detail::CollectionReturnValueTraits<Collection>::format(Collection const & value,
86 typename type::const_iterator i (value.begin());
87 typename type::const_iterator const i_end (value.end());
90 senf::console::format(*i, os);
99 ///////////////////////////////////////////////////////////////////////////
100 // senf::console::detail::MapArgumentTraits<Collection>
102 template <class Collection>
103 prefix_ void senf::console::detail::MapArgumentTraits<Collection>::
104 parse(ParseCommandInfo::TokensRange const & tokens, Collection & out)
107 CheckedArgumentIteratorWrapper arg (tokens);
109 typename Collection::key_type key;
110 typename Collection::mapped_type data;
111 senf::console::parse( *(arg++), key );
112 ParseCommandInfo::TokensRange sep (*(arg++));
113 if (sep.size() != 1 || sep[0].type() != Token::OtherPunctuation || sep[0].value() != "=")
114 throw SyntaxErrorException("'=' expected");
115 senf::console::parse( *(arg++), data );
116 out.insert(std::make_pair(key,data));
120 template <class Collection>
121 prefix_ std::string senf::console::detail::MapArgumentTraits<Collection>::description()
123 std::string type (prettyName(typeid(Collection)));
124 std::string::size_type e (type.find('<'));
125 if (e == std::string::npos) e = type.size();
126 std::string::size_type b (type.rfind(':', e));
127 if (b == std::string::npos) b = 0; else ++b;
128 return type.substr(b,e-b) + "<"
129 + ArgumentTraits<typename Collection::key_type>::description() + ","
130 + ArgumentTraits<typename Collection::mapped_type>::description() + ">";
133 template <class Collection>
135 senf::console::detail::MapArgumentTraits<Collection>::str(Collection const & value)
137 std::stringstream ss;
138 senf::console::format(value, ss);
142 ///////////////////////////////////////////////////////////////////////////
143 // senf::console::detail::MapReturnValueTraits<Collection>
145 template <class Collection>
147 senf::console::detail::MapReturnValueTraits<Collection>::format(Collection const & value,
151 typename type::const_iterator i (value.begin());
152 typename type::const_iterator const i_end (value.end());
155 senf::console::format(i->first, os);
157 senf::console::format(i->second, os);
166 ///////////////////////////////////////////////////////////////////////////
167 // senf::console::ArgumentTraits< std::pair<T1,T2> >
169 template <class T1, class T2>
170 prefix_ void senf::console::ArgumentTraits< std::pair<T1,T2> >::
171 parse(ParseCommandInfo::TokensRange const & tokens, type & out)
173 CheckedArgumentIteratorWrapper arg (tokens);
174 senf::console::parse( *(arg++), out.first );
175 senf::console::parse( *(arg++), out.second );
178 template <class T1, class T2>
179 prefix_ std::string senf::console::ArgumentTraits< std::pair<T1,T2> >::description()
181 return (boost::format("pair<%s,%s>")
182 % ArgumentTraits<T1>::description()
183 % ArgumentTraits<T2>::description()).str();
186 template <class T1, class T2>
187 prefix_ std::string senf::console::ArgumentTraits< std::pair<T1,T2> >::str(type const & value)
189 std::stringstream ss;
190 senf::console::format(value, ss);
194 ///////////////////////////////////////////////////////////////////////////
195 // senf::console::ReturnValueTraits< std::pair<T1,T2> >
197 template <class T1, class T2>
198 prefix_ void senf::console::ReturnValueTraits< std::pair<T1,T2> >::format(type const & value,
202 senf::console::format(value.first, os);
204 senf::console::format(value.second, os);
210 ///////////////////////////////ct.e////////////////////////////////////////
217 // comment-column: 40
218 // c-file-style: "senf"
219 // indent-tabs-mode: nil
220 // ispell-local-dictionary: "american"
221 // compile-command: "scons -u test"