Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

STLSupport.ct

Go to the documentation of this file.
00001 // $Id: STLSupport.ct 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2009
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 //#include "VectorSupport.ih"
00027 
00028 // Custom includes
00029 #include <boost/format.hpp>
00030 
00031 #define prefix_
00032 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00033 
00034 #ifndef DOXYGEN
00035 
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 // senf::console::detail::CollectionArgumentTraitsBase<Collection>
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 // senf::console::detail::CollectionArgumentTraits<Collection,Adder>
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 // senf::console::detail::CollectionReturnValueTraits<Collection>
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 // senf::console::detail::MapArgumentTraits<Collection>
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 // senf::console::detail::MapReturnValueTraits<Collection>
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 // senf::console::ArgumentTraits< std::pair<T1,T2> >
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 // senf::console::ReturnValueTraits< std::pair<T1,T2> >
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 // Local Variables:
00202 // mode: c++
00203 // fill-column: 100
00204 // comment-column: 40
00205 // c-file-style: "senf"
00206 // indent-tabs-mode: nil
00207 // ispell-local-dictionary: "american"
00208 // compile-command: "scons -u test"
00209 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research