Move sourcecode into 'senf/' directory
[senf.git] / senf / Packets / ListBParser.cti
diff --git a/senf/Packets/ListBParser.cti b/senf/Packets/ListBParser.cti
new file mode 100644 (file)
index 0000000..ac603c3
--- /dev/null
@@ -0,0 +1,210 @@
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief ListBParser inline template implementation */
+
+#include "ListBParser.ih"
+
+// Custom includes
+
+#define prefix_ inline
+///////////////////////////////cti.p///////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>
+
+template <class ElementParser, class AuxPolicy>
+prefix_ senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy()
+{}
+
+template <class ElementParser, class AuxPolicy>
+template <class Arg>
+prefix_
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy(Arg const & arg)
+    : AuxPolicy (arg)
+{}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i, state_type s)
+    const
+{
+    return AuxPolicy::aux(i,s) + AuxPolicy::aux_bytes;
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i, state_type s)
+    const
+{
+    parser_type p (*this, i, s);
+    container_type c (p);
+    return std::distance(c.begin(),c.end());
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
+                                                                             state_type s)
+    const
+{
+    AuxPolicy::aux(0,i,s);
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::detail::ListBParser_Policy<ElementParser,BytesParser>
+
+template <class ElementParser, class AuxPolicy>
+prefix_
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+container_policy(parser_policy const & p)
+    : AuxPolicy (p)
+{
+    data_iterator const e (boost::next(parser_type::get(p).i(),parser_type::get(p).bytes()));
+    data_iterator i (AuxPolicy::adjust(parser_type::get(p).i(), parser_type::get(p).state()));
+    for( n_=0; i!=e; 
+         ++n_, std::advance(i,senf::bytes(ElementParser(i,parser_type::get(p).state())))) ;
+    container_size_ = parser_type::get(p).data().size();
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::bytes(data_iterator i,
+                                                                                   state_type s)
+    const
+{
+    return AuxPolicy::aux(i,s) + AuxPolicy::aux_bytes;
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size(data_iterator i,
+                                                                                  state_type s)
+    const
+{
+    return n_;
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+init(data_iterator i, state_type s)
+{
+    n_ = 0;
+    container_size_ = s->size();
+    AuxPolicy::aux(0,i,s);
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+erase(container_type & c, data_iterator p)
+{
+    size_type b (senf::bytes(ElementParser(p,c.state())));
+    AuxPolicy::aux( AuxPolicy::aux(c.i(), c.state())-b, c.i(), c.state());
+    --n_;
+    // The container will be reduced by b bytes directly after this call
+    container_size_ = c.data().size()-b;
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ void
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+insert(container_type & c, data_iterator p)
+{
+    size_type b (senf::bytes(ElementParser(p,c.state())));
+    AuxPolicy::aux( AuxPolicy::aux(c.i(), c.state())+b, c.i(), c.state());
+    ++n_;
+    container_size_ = c.data().size();
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ void
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+update(container_type const & c)
+    const
+{
+    if (container_size_ == c.data().size())
+        return;
+    data_iterator i (AuxPolicy::adjust(c.i(), c.state()));
+    data_iterator j (i);
+    for (size_type n (n_); n; --n, std::advance(j,senf::bytes(ElementParser(j,c.state())))) ;
+    aux( std::distance(i,j), c.i(), c.state() );
+    container_size_ = c.data().size();
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+setBegin(container_type const & c, iterator_data & d)
+    const
+{
+    return AuxPolicy::adjust(c.i(), c.state());
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+setEnd(container_type const & c, iterator_data & d)
+    const
+{
+    return boost::next(AuxPolicy::adjust(c.i(), c.state()),aux(c.i(),c.state()));
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ void
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
+    const
+{}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+next(container_type const & c, iterator_data & d)
+    const
+{
+    return boost::next( container_type::iterator::get(d).i(),
+                        senf::bytes(ElementParser( container_type::iterator::get(d).i(), 
+                                                   c.state() )) );
+}
+
+template <class ElementParser, class AuxPolicy>
+prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
+senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
+raw(container_type const & c, iterator_data const & d)
+    const
+{
+    return container_type::iterator::get(d).i();
+}
+
+///////////////////////////////cti.e///////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End: