4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief VectorSupport non-inline template implementation */
31 //#include "VectorSupport.ih"
34 #include <boost/format.hpp>
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 // senf::console::detail::CollectionArgumentTraitsBase<Collection>
44 template <class Collection>
46 senf::console::detail::CollectionArgumentTraitsBase<Collection>::description()
48 return senf::prettyBaseName(typeid(Collection)) + "<"
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 os << senf::console::str(*i);
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 return senf::prettyBaseName(typeid(Collection)) + "<"
124 + ArgumentTraits<typename Collection::key_type>::description() + ","
125 + ArgumentTraits<typename Collection::mapped_type>::description() + ">";
128 template <class Collection>
130 senf::console::detail::MapArgumentTraits<Collection>::str(Collection const & value)
132 std::stringstream ss;
133 senf::console::format(value, ss);
137 //-/////////////////////////////////////////////////////////////////////////////////////////////////
138 // senf::console::detail::MapReturnValueTraits<Collection>
140 template <class Collection>
142 senf::console::detail::MapReturnValueTraits<Collection>::format(Collection const & value,
146 typename type::const_iterator i (value.begin());
147 typename type::const_iterator const i_end (value.end());
150 os << senf::console::str(i->first)
152 << senf::console::str(i->second);
161 //-/////////////////////////////////////////////////////////////////////////////////////////////////
162 // senf::console::ArgumentTraits< std::pair<T1,T2> >
164 template <class T1, class T2>
165 prefix_ void senf::console::ArgumentTraits< std::pair<T1,T2> >::
166 parse(ParseCommandInfo::TokensRange const & tokens, type & out)
168 CheckedArgumentIteratorWrapper arg (tokens);
169 senf::console::parse( *(arg++), out.first );
170 senf::console::parse( *(arg++), out.second );
173 template <class T1, class T2>
174 prefix_ std::string senf::console::ArgumentTraits< std::pair<T1,T2> >::description()
176 return (boost::format("pair<%s,%s>")
177 % ArgumentTraits<T1>::description()
178 % ArgumentTraits<T2>::description()).str();
181 template <class T1, class T2>
182 prefix_ std::string senf::console::ArgumentTraits< std::pair<T1,T2> >::str(type const & value)
184 std::stringstream ss;
185 senf::console::format(value, ss);
189 //-/////////////////////////////////////////////////////////////////////////////////////////////////
190 // senf::console::ReturnValueTraits< std::pair<T1,T2> >
192 template <class T1, class T2>
193 prefix_ void senf::console::ReturnValueTraits< std::pair<T1,T2> >::format(type const & value,
196 os << "(" << senf::console::str(value.first)
197 << " " << senf::console::str(value.second) << ")";
202 //-/////////////////////////////////////////////////////////////////////////////////////////////////
209 // comment-column: 40
210 // c-file-style: "senf"
211 // indent-tabs-mode: nil
212 // ispell-local-dictionary: "american"
213 // compile-command: "scons -u test"