--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// 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 PacketParser non-inline non-template implementation */
+
+#include "Packets.hh"
+#include "PacketParser.ih"
+
+// Custom includes
+
+//#include "PacketParser.mpp"
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+prefix_ void senf::PacketParserBase::resize(size_type oldSize, size_type newSize)
+{
+ safe_data_iterator safe_i (*this);
+ if (oldSize > newSize)
+ data().erase(i()+newSize, i()+oldSize);
+ else if (oldSize < newSize)
+ data().insert(i()+oldSize, newSize-oldSize, 0u);
+ i_ = safe_i;
+}
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+//#include "PacketParser.mpp"
+
+\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:
parsers when access to previous or following packets is
needed e.g. for calculating checksums etc. */
+ void resize(size_type oldSize, size_type newSize); ///< Resize data container
+ /**< This command will erase or insert bytes from/into the
+ data container at the end of the parser (at i() + \a
+ newSize). If \a oldSize is > \a newSize, bytes will be
+ removed, otherwise bytes will be inserted.
+
+ \warning This may invalidate iterators and other
+ parsers. The current parser itself is automatically
+ updated */
+
private:
data_iterator end() const;
#include "SafeIterator.hh"
#include "ArrayParser.hh"
#include "IntParser.hh"
+#include "StringParser.hh"
#include "AuxParser.hh"
#include "ListParser.hh"
#include "ListBParser.hh"
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// 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 StringParser inline non-template implementation */
+
+//#include "StringParser.ih"
+
+// Custom includes
+
+#define prefix_ inline
+///////////////////////////////cci.p///////////////////////////////////////
+
+prefix_ senf::StringParser::StringParser(data_iterator i, state_type s)
+ : PacketParserBase(i, s, init_bytes)
+ {}
+
+prefix_ senf::StringParser::size_type senf::StringParser::bytes()
+ const
+{
+ return parse<UInt16Parser>(0)+2;
+}
+
+prefix_ senf::StringParser::value_type senf::StringParser::value()
+ const
+{
+ validate(bytes());
+ return std::string(i()+2, i()+bytes());
+}
+
+prefix_ void senf::StringParser::value(value_type v)
+{
+ validate(bytes());
+ resize(bytes(), v.size()+2);
+ parse<UInt16Parser>(0) = v.size();
+ std::copy(v.begin(), v.end(), i()+2);
+}
+
+prefix_ senf::StringParser::operator value_type()
+ const
+{
+ return value();
+}
+
+prefix_ senf::StringParser const & senf::StringParser::operator=(value_type other)
+{
+ value(other); return *this;
+}
+
+///////////////////////////////cci.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:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// 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 StringParser public header */
+
+#ifndef HH_SENF_Packets_StringParser_
+#define HH_SENF_Packets_StringParser_ 1
+
+#ifndef HH_SENF_Packets_Packets_
+#error "Don't include 'StringParser.hh' directly, include 'Packets.hh'"
+#endif
+
+// Custom includes
+
+//#include "StringParser.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+ struct StringParser
+ : public PacketParserBase
+ {
+
+ StringParser(data_iterator i, state_type s);
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ typedef std::string value_type;
+ static const size_type init_bytes = 2;
+ size_type bytes() const;
+
+ value_type value() const;
+ void value(value_type v);
+ operator value_type() const;
+ StringParser const & operator=(value_type other);
+ };
+
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+#endif
+#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_StringParser_i_)
+#define HH_SENF_Packets_StringParser_i_
+#include "StringParser.cci"
+//#include "StringParser.ct"
+//#include "StringParser.cti"
+#endif
+
+\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:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// 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 StringParser.test unit tests */
+
+//#include "StringParser.test.hh"
+//#include "StringParser.test.ih"
+
+// Custom includes
+#include "Packets.hh"
+
+#include "../Utils/auto_unit_test.hh"
+#include <boost/test/test_tools.hpp>
+
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+namespace {
+ struct VoidPacket : public senf::PacketTypeBase
+ {};
+}
+
+BOOST_AUTO_UNIT_TEST(stringParser)
+{
+ senf::PacketInterpreterBase::byte data[] = { 0x00, 0x04, 'T', 'E', 'S', 'T' };
+ senf::PacketInterpreterBase::ptr p (senf::PacketInterpreter<VoidPacket>::create(data));
+
+ BOOST_CHECK_EQUAL( p->data().size(), 6u );
+ BOOST_CHECK_EQUAL( senf::StringParser(p->data().begin(), &p->data()).value(), "TEST" );
+
+ senf::StringParser(p->data().begin(), &p->data()).value("Another Test");
+ BOOST_CHECK_EQUAL( p->data().size(), 14u );
+ BOOST_CHECK_EQUAL( p->data()[0], 0u );
+ BOOST_CHECK_EQUAL( p->data()[1], 12u );
+ BOOST_CHECK_EQUAL( senf::StringParser(p->data().begin(), &p->data()).value(), "Another Test" );
+}
+
+///////////////////////////////cc.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: