From: g0dil Date: Wed, 23 Sep 2009 15:21:42 +0000 (+0000) Subject: Packets: return value_type parser from collection parser push_back_space() and push_f... X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=af5fee58087b479a8a346dc5f94047ec0c5f79cf;p=senf.git Packets: return value_type parser from collection parser push_back_space() and push_front_space() members git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1434 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/ListBParser.test.cc b/senf/Packets/ListBParser.test.cc index 23a14ff..d380738 100644 --- a/senf/Packets/ListBParser.test.cc +++ b/senf/Packets/ListBParser.test.cc @@ -100,9 +100,8 @@ BOOST_AUTO_UNIT_TEST(ListBParser_container) senf::PacketInterpreterBase::ptr pi2 (senf::PacketInterpreter::create( MyListBParser::init_bytes)); MyListBParser::container c2 (MyListBParser(pi2->data().begin(),&pi2->data())); - c2.push_back_space(); { - VectorParser::vec_t::container c2v (c2.front().vec()); + VectorParser::vec_t::container c2v (c2.push_back_space().vec()); c2v.push_back(0x2345u); c2v.push_back(0x3456u); } diff --git a/senf/Packets/ListParser.ct b/senf/Packets/ListParser.ct index 8a5555e..7ce53a3 100644 --- a/senf/Packets/ListParser.ct +++ b/senf/Packets/ListParser.ct @@ -75,7 +75,8 @@ senf::ListParser_Container::back() } template -prefix_ void senf::ListParser_Container::shift(iterator pos, size_type n) +prefix_ typename senf::ListParser_Container::value_type +senf::ListParser_Container::shift(iterator pos, size_type n) { ListPolicy::update(*this); safe_data_iterator sp (data(),pos.raw()); @@ -84,6 +85,7 @@ prefix_ void senf::ListParser_Container::shift(iterator pos, size_ty value_type(sp,state()).init(); ListPolicy::insert(*this,sp); } + return value_type(sp,state()); } template diff --git a/senf/Packets/ListParser.cti b/senf/Packets/ListParser.cti index e8c85a7..0aa24ea 100644 --- a/senf/Packets/ListParser.cti +++ b/senf/Packets/ListParser.cti @@ -92,11 +92,12 @@ prefix_ void senf::ListParser::push_back(Value const & value, size_t } template -prefix_ void senf::ListParser::push_back_space(size_type n) +prefix_ typename senf::ListParser::value_type +senf::ListParser::push_back_space(size_type n) const { container c(*this); - c.push_back_space(n); + return c.push_back_space(n); } template @@ -109,11 +110,12 @@ prefix_ void senf::ListParser::push_front(Value const & value, size_ } template -prefix_ void senf::ListParser::push_front_space(size_type n) +prefix_ typename senf::ListParser::value_type +senf::ListParser::push_front_space(size_type n) const { container c(*this); - c.push_front_space(n); + return c.push_front_space(n); } template @@ -308,9 +310,10 @@ prefix_ void senf::ListParser_Container::push_back(Value const & val } template -prefix_ void senf::ListParser_Container::push_back_space(size_type n) +prefix_ typename senf::ListParser_Container::value_type +senf::ListParser_Container::push_back_space(size_type n) { - shift(end(),n); + return shift(end(),n); } template @@ -322,9 +325,10 @@ prefix_ void senf::ListParser_Container::push_front(Value const & va } template -prefix_ void senf::ListParser_Container::push_front_space(size_type n) +prefix_ typename senf::ListParser_Container::value_type +senf::ListParser_Container::push_front_space(size_type n) { - shift(begin(),n); + return shift(begin(),n); } // Parser interface diff --git a/senf/Packets/ListParser.hh b/senf/Packets/ListParser.hh index 3b26dad..d7c19a1 100644 --- a/senf/Packets/ListParser.hh +++ b/senf/Packets/ListParser.hh @@ -102,9 +102,9 @@ namespace senf { value_type back() const; template void push_back (Value const & value, size_type n=1) const; - void push_back_space (size_type n=1) const; + value_type push_back_space (size_type n=1) const; template void push_front (Value const & value, size_type n=1) const; - void push_front_space (size_type n=1) const; + value_type push_front_space (size_type n=1) const; void resize (size_type n) const; template void resize (size_type n, Value value) const; @@ -183,7 +183,7 @@ namespace senf { ///@{ // All these operations can be quite inefficient depending on the list type - void shift(iterator pos, size_type n=1); + value_type shift(iterator pos, size_type n=1); template void insert(iterator pos, Value const & t); template @@ -201,10 +201,10 @@ namespace senf { void clear(); template void push_back (Value const & value, size_type n=1); - void push_back_space (size_type n=1); + value_type push_back_space (size_type n=1); template void push_front (Value const & value, size_type n=1); - void push_front_space (size_type n=1); - void resize (size_type n); + value_type push_front_space (size_type n=1); + void resize (size_type n); template void resize (size_type n, Value value); ///@} diff --git a/senf/Packets/VectorParser.cti b/senf/Packets/VectorParser.cti index de4a3ac..45faf91 100644 --- a/senf/Packets/VectorParser.cti +++ b/senf/Packets/VectorParser.cti @@ -121,11 +121,12 @@ prefix_ void senf::VectorParser::push_back(Value const } template -prefix_ void senf::VectorParser::push_back_space(size_type n) +prefix_ typename senf::VectorParser::value_type +senf::VectorParser::push_back_space(size_type n) const { container c (*this); - c.push_back_space(n); + return c.push_back_space(n); } template @@ -138,11 +139,12 @@ prefix_ void senf::VectorParser::push_front(Value const } template -prefix_ void senf::VectorParser::push_front_space(size_type n) +prefix_ typename senf::VectorParser::value_type +senf::VectorParser::push_front_space(size_type n) const { container c (*this); - c.push_front_space(n); + return c.push_front_space(n); } template @@ -272,9 +274,10 @@ prefix_ void senf::VectorParser_Container::push_back(Va } template -prefix_ void senf::VectorParser_Container::push_back_space(size_type n) +prefix_ typename senf::VectorParser_Container::value_type +senf::VectorParser_Container::push_back_space(size_type n) { - shift(end(),n); + return *shift(end(),n); } template @@ -286,9 +289,10 @@ prefix_ void senf::VectorParser_Container::push_front(V } template -prefix_ void senf::VectorParser_Container::push_front_space(size_type n) +prefix_ typename senf::VectorParser_Container::value_type +senf::VectorParser_Container::push_front_space(size_type n) { - shift(begin(),n); + return *shift(begin(),n); } // Parser interface diff --git a/senf/Packets/VectorParser.hh b/senf/Packets/VectorParser.hh index ef3fe36..fda789e 100644 --- a/senf/Packets/VectorParser.hh +++ b/senf/Packets/VectorParser.hh @@ -107,10 +107,10 @@ namespace senf { // 'container' wrapper template void push_back (Value const & value, size_type n=1) const; - void push_back_space (size_type n=1) const; + value_type push_back_space (size_type n=1) const; template void push_front (Value const & value, size_type n=1) const; - void push_front_space (size_type n=1) const; - void resize (size_type n) const; + value_type push_front_space (size_type n=1) const; + void resize (size_type n) const; template void resize (size_type n, Value value) const; private: @@ -203,10 +203,10 @@ namespace senf { void clear(); template void push_back (Value const & value, size_type n=1); - void push_back_space (size_type n=1); + value_type push_back_space (size_type n=1); template void push_front (Value const & value, size_type n=1); - void push_front_space (size_type n=1); - void resize (size_type n); + value_type push_front_space (size_type n=1); + void resize (size_type n); template void resize (size_type n, Value value); ///@} diff --git a/senf/Packets/VectorParser.test.cc b/senf/Packets/VectorParser.test.cc index 71f415b..b0d368c 100644 --- a/senf/Packets/VectorParser.test.cc +++ b/senf/Packets/VectorParser.test.cc @@ -82,9 +82,9 @@ BOOST_AUTO_UNIT_TEST(VectorParser) BOOST_CHECK_EQUAL( v.size(), 8u ); BOOST_CHECK_EQUAL( v[7], 0xf0f1u ); - v.push_back_space(); + v.push_back_space() = 37u; BOOST_CHECK_EQUAL( v.size(), 9u ); - BOOST_CHECK_EQUAL( v[8], 0u ); + BOOST_CHECK_EQUAL( v[8], 37u ); v.push_front(0xf3f4u); BOOST_CHECK_EQUAL( v.size(), 10u );