PPI: Missing commit
[senf.git] / Utils / Console / STLSupport.ct
1 // $Id$
2 //
3 // Copyright (C) 2009 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief VectorSupport non-inline template implementation  */
25
26 //#include "VectorSupport.ih"
27
28 // Custom includes
29
30 #define prefix_
31 ///////////////////////////////ct.p////////////////////////////////////////
32
33 #ifndef DOXYGEN
34
35 template <class Sequence>
36 prefix_ void senf::console::SequenceArgumentTraits<Sequence>::
37 parse(ParseCommandInfo::TokensRange const & tokens, type & out)
38 {
39     out.clear();
40     CheckedArgumentIteratorWrapper arg (tokens);
41     while (arg) {
42         out.push_back(typename Sequence::value_type());
43         senf::console::parse( *(arg++), out.back() );
44     }
45 }
46
47 template <class Sequence>
48 prefix_ std::string senf::console::SequenceArgumentTraits<Sequence>::description()
49 {
50     std::string type (prettyName(typeid(Sequence)));
51     std::string::size_type e (type.find('<'));
52     if (e == std::string::npos) e = type.size();
53     std::string::size_type b (type.rfind(':', e));
54     if (b == std::string::npos) b = 0; else ++b;
55     return type.substr(b,e-b) + "<" 
56         + ArgumentTraits<typename Sequence::value_type>::description() + ">";
57 }
58
59 template <class Sequence>
60 prefix_ std::string senf::console::SequenceArgumentTraits<Sequence>::str(type const & value)
61 {
62     std::stringstream ss;
63     senf::console::format(value, ss);
64     return ss.str();
65 }
66
67 template <class Sequence>
68 prefix_ void senf::console::SequenceReturnValueTraits<Sequence>::format(type const & value,
69                                                                         std::ostream & os)
70 {
71     os << "(";
72     typename type::const_iterator i (value.begin());
73     typename type::const_iterator const i_end (value.end());
74     if (i != i_end)
75         for (;;) {
76             senf::console::format(*i, os);
77             if (++i == i_end) 
78                 break;
79             else
80                 os << " ";
81         }
82     os << ")";
83 }
84
85 #endif
86
87 ///////////////////////////////ct.e////////////////////////////////////////
88 #undef prefix_
89
90 \f
91 // Local Variables:
92 // mode: c++
93 // fill-column: 100
94 // comment-column: 40
95 // c-file-style: "senf"
96 // indent-tabs-mode: nil
97 // ispell-local-dictionary: "american"
98 // compile-command: "scons -u test"
99 // End: