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 return senf::prettyBaseName(typeid(Collection)) + "<"
44 + ArgumentTraits<typename Collection::value_type>::description() + ">";
47 template <class Collection>
49 senf::console::detail::CollectionArgumentTraitsBase<Collection>::str(Collection const & value)
52 senf::console::format(value, ss);
56 ///////////////////////////////////////////////////////////////////////////
57 // senf::console::detail::CollectionArgumentTraits<Collection,Adder>
59 template <class Collection, class Adder>
60 prefix_ void senf::console::detail::CollectionArgumentTraits<Collection,Adder>::
61 parse(ParseCommandInfo::TokensRange const & tokens, Collection & out)
64 CheckedArgumentIteratorWrapper arg (tokens);
66 typename Collection::value_type v;
67 senf::console::parse( *(arg++), v );
72 ///////////////////////////////////////////////////////////////////////////
73 // senf::console::detail::CollectionReturnValueTraits<Collection>
75 template <class Collection>
77 senf::console::detail::CollectionReturnValueTraits<Collection>::format(Collection const & value,
81 typename type::const_iterator i (value.begin());
82 typename type::const_iterator const i_end (value.end());
85 os << senf::console::str(*i);
94 ///////////////////////////////////////////////////////////////////////////
95 // senf::console::detail::MapArgumentTraits<Collection>
97 template <class Collection>
98 prefix_ void senf::console::detail::MapArgumentTraits<Collection>::
99 parse(ParseCommandInfo::TokensRange const & tokens, Collection & out)
102 CheckedArgumentIteratorWrapper arg (tokens);
104 typename Collection::key_type key;
105 typename Collection::mapped_type data;
106 senf::console::parse( *(arg++), key );
107 ParseCommandInfo::TokensRange sep (*(arg++));
108 if (sep.size() != 1 || sep[0].type() != Token::OtherPunctuation || sep[0].value() != "=")
109 throw SyntaxErrorException("'=' expected");
110 senf::console::parse( *(arg++), data );
111 out.insert(std::make_pair(key,data));
115 template <class Collection>
116 prefix_ std::string senf::console::detail::MapArgumentTraits<Collection>::description()
118 return senf::prettyBaseName(typeid(Collection)) + "<"
119 + ArgumentTraits<typename Collection::key_type>::description() + ","
120 + ArgumentTraits<typename Collection::mapped_type>::description() + ">";
123 template <class Collection>
125 senf::console::detail::MapArgumentTraits<Collection>::str(Collection const & value)
127 std::stringstream ss;
128 senf::console::format(value, ss);
132 ///////////////////////////////////////////////////////////////////////////
133 // senf::console::detail::MapReturnValueTraits<Collection>
135 template <class Collection>
137 senf::console::detail::MapReturnValueTraits<Collection>::format(Collection const & value,
141 typename type::const_iterator i (value.begin());
142 typename type::const_iterator const i_end (value.end());
145 os << senf::console::str(i->first)
147 << senf::console::str(i->second);
156 ///////////////////////////////////////////////////////////////////////////
157 // senf::console::ArgumentTraits< std::pair<T1,T2> >
159 template <class T1, class T2>
160 prefix_ void senf::console::ArgumentTraits< std::pair<T1,T2> >::
161 parse(ParseCommandInfo::TokensRange const & tokens, type & out)
163 CheckedArgumentIteratorWrapper arg (tokens);
164 senf::console::parse( *(arg++), out.first );
165 senf::console::parse( *(arg++), out.second );
168 template <class T1, class T2>
169 prefix_ std::string senf::console::ArgumentTraits< std::pair<T1,T2> >::description()
171 return (boost::format("pair<%s,%s>")
172 % ArgumentTraits<T1>::description()
173 % ArgumentTraits<T2>::description()).str();
176 template <class T1, class T2>
177 prefix_ std::string senf::console::ArgumentTraits< std::pair<T1,T2> >::str(type const & value)
179 std::stringstream ss;
180 senf::console::format(value, ss);
184 ///////////////////////////////////////////////////////////////////////////
185 // senf::console::ReturnValueTraits< std::pair<T1,T2> >
187 template <class T1, class T2>
188 prefix_ void senf::console::ReturnValueTraits< std::pair<T1,T2> >::format(type const & value,
191 os << "(" << senf::console::str(value.first)
192 << " " << senf::console::str(value.second) << ")";
197 ///////////////////////////////ct.e////////////////////////////////////////
204 // comment-column: 40
205 // c-file-style: "senf"
206 // indent-tabs-mode: nil
207 // ispell-local-dictionary: "american"
208 // compile-command: "scons -u test"