From: g0dil Date: Wed, 30 Jan 2008 15:27:01 +0000 (+0000) Subject: Utils: Implement Tags.hh and move 'senf::noinit' and 'senf::nothrow' there X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=66293acca094b2f29e26e70208691db4af274efb;p=senf.git Utils: Implement Tags.hh and move 'senf::noinit' and 'senf::nothrow' there Adjust all senf components to use Utils/Tags.hh (if necessary) git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@648 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Examples/DVBAdapter/ULEdec.cc b/Examples/DVBAdapter/ULEdec.cc index 327943a..abec6e4 100644 --- a/Examples/DVBAdapter/ULEdec.cc +++ b/Examples/DVBAdapter/ULEdec.cc @@ -63,7 +63,7 @@ ULEdec::ULEdec(unsigned short adapter, unsigned short device) void ULEdec::handleEvent(senf::Scheduler::EventId event) { senf::TransportPacket ts_packet ( - senf::TransportPacket::create(188, senf::TransportPacket::noinit)); + senf::TransportPacket::create(188, senf::noinit)); dvrHandle.read( ts_packet.data() ); // Check TS error conditions: sync_byte, transport_error_indicator, scrambling_control. diff --git a/Examples/Sniffer/Sniffer.cc b/Examples/Sniffer/Sniffer.cc index b570004..f228fe7 100644 --- a/Examples/Sniffer/Sniffer.cc +++ b/Examples/Sniffer/Sniffer.cc @@ -48,7 +48,7 @@ int loop_main (int argc, char const * argv[]) while (true) { // forever senf::EthernetPacket packet (senf::EthernetPacket::create( - senf::EthernetPacket::noinit)); + senf::noinit)); sock.read(packet.data(),0); packet.dump(std::cout); senf::hexdump( @@ -85,7 +85,7 @@ private: void dumpPacket(senf::Scheduler::EventId event) { senf::EthernetPacket packet ( - senf::EthernetPacket::create(senf::EthernetPacket::noinit)); + senf::EthernetPacket::create(senf::noinit)); sock.read(packet.data(),0); packet.dump(std::cout); senf::hexdump( diff --git a/PPI/SocketSource.ct b/PPI/SocketSource.ct index 1ee66f3..2d9e881 100644 --- a/PPI/SocketSource.ct +++ b/PPI/SocketSource.ct @@ -36,7 +36,7 @@ template prefix_ Packet senf::ppi::DgramReader::operator()(Handle handle) { - Packet packet (Packet::create(Packet::noinit)); + Packet packet (Packet::create(senf::noinit)); handle.read(packet.data(),0u); return packet; } diff --git a/Packets/Mainpage.dox b/Packets/Mainpage.dox index 1c551fd..56f68c5 100644 --- a/Packets/Mainpage.dox +++ b/Packets/Mainpage.dox @@ -125,7 +125,7 @@ \code senf::PacketSocketHandle sock ("eth0"); - senf::EthernetPacket packet (senf::EthernetPacket::create(senf::Packet::noinit)); + senf::EthernetPacket packet (senf::EthernetPacket::create(senf::noinit)); sock.read(packet.data(),0u); \endcode diff --git a/Packets/Packet.cti b/Packets/Packet.cti index 6331b1c..dd980e6 100644 --- a/Packets/Packet.cti +++ b/Packets/Packet.cti @@ -154,9 +154,9 @@ senf::ConcretePacket::create() template prefix_ senf::ConcretePacket -senf::ConcretePacket::create(NoInit_t) +senf::ConcretePacket::create(senf::NoInit_t) { - return ConcretePacket(interpreter::create(interpreter::noinit)); + return ConcretePacket(interpreter::create(senf::noinit)); } template @@ -168,9 +168,9 @@ senf::ConcretePacket::create(size_type size) template prefix_ senf::ConcretePacket -senf::ConcretePacket::create(size_type size, NoInit_t) +senf::ConcretePacket::create(size_type size, senf::NoInit_t) { - return ConcretePacket(interpreter::create(size,interpreter::noinit)); + return ConcretePacket(interpreter::create(size,senf::noinit)); } template @@ -192,9 +192,9 @@ senf::ConcretePacket::createAfter(Packet packet) template prefix_ senf::ConcretePacket -senf::ConcretePacket::createAfter(Packet packet, NoInit_t) +senf::ConcretePacket::createAfter(Packet packet, senf::NoInit_t) { - return ConcretePacket(interpreter::createAfter(packet.ptr(),interpreter::noinit)); + return ConcretePacket(interpreter::createAfter(packet.ptr(),senf::noinit)); } template @@ -206,9 +206,9 @@ senf::ConcretePacket::createAfter(Packet packet, size_type size) template prefix_ senf::ConcretePacket -senf::ConcretePacket::createAfter(Packet packet, size_type size, NoInit_t) +senf::ConcretePacket::createAfter(Packet packet, size_type size, senf::NoInit_t) { - return ConcretePacket(interpreter::createAfter(packet.ptr(), size, interpreter::noinit)); + return ConcretePacket(interpreter::createAfter(packet.ptr(), size, senf::noinit)); } template @@ -230,9 +230,9 @@ senf::ConcretePacket::createBefore(Packet packet) template prefix_ senf::ConcretePacket -senf::ConcretePacket::createBefore(Packet packet, NoInit_t) +senf::ConcretePacket::createBefore(Packet packet, senf::NoInit_t) { - return ConcretePacket(interpreter::createBefore(packet.ptr(), interpreter::noinit)); + return ConcretePacket(interpreter::createBefore(packet.ptr(), senf::noinit)); } // Create a clone of the current packet diff --git a/Packets/Packet.hh b/Packets/Packet.hh index 996e2c1..371659a 100644 --- a/Packets/Packet.hh +++ b/Packets/Packet.hh @@ -30,6 +30,7 @@ #include #include "../Utils/Exception.hh" +#include "../Utils/Tags.hh" #include "../Utils/safe_bool.hh" #include "PacketInterpreter.hh" @@ -149,9 +150,6 @@ namespace senf { ///< Unsigned type to represent packet size typedef PacketInterpreterBase::factory_t factory_t; ///< Packet factory type (see below) - enum NoInit_t { noinit }; ///< Special argument flag - /**< Used in some ConcretePacket constructors */ - /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ @@ -446,10 +444,10 @@ namespace senf { static ConcretePacket create(); ///< Create default initialized packet /**< The packet will be initialized to it's default empty state. */ - static ConcretePacket create(NoInit_t); ///< Create uninitialized empty packet + static ConcretePacket create(senf::NoInit_t); ///< Create uninitialized empty packet /**< This will create a completely empty and uninitialized packet with size() == 0. - \param[in] noinit This parameter must always have the + \param[in] senf::noinit This parameter must always have the value \c senf::noinit. */ static ConcretePacket create(size_type size); ///< Create default initialized packet /**< This member will create a default initialized packet @@ -460,11 +458,12 @@ namespace senf { \throws TruncatedPacketException if \a size is smaller than the smallest permissible size for this type of packet. */ - static ConcretePacket create(size_type size, NoInit_t); ///< Create uninitialized packet + static ConcretePacket create(size_type size, senf::NoInit_t); + ///< Create uninitialized packet /**< Creates an uninitialized (all-zero) packet of the exact given size. \param[in] size Size of the packet to create in bytes - \param[in] noinit This parameter must always have the + \param[in] senf::noinit This parameter must always have the value \c senf::noinit. */ template static ConcretePacket create(ForwardReadableRange const & range); @@ -485,14 +484,14 @@ namespace senf { state. It will be appended as next header/interpreter after \a packet in that packets interpreter chain. \param[in] packet Packet to append new packet to. */ - static ConcretePacket createAfter(Packet packet, NoInit_t); + static ConcretePacket createAfter(Packet packet, senf::NoInit_t); ///< Create uninitialized empty packet after\a packet /**< This will create a completely empty and uninitialized packet with size() == 0. It will be appended as next header/interpreter after \a packet in that packets interpreter chain. \param[in] packet Packet to append new packet to. - \param[in] noinit This parameter must always have the + \param[in] senf::noinit This parameter must always have the value \c senf::noinit. */ static ConcretePacket createAfter(Packet packet, size_type size); ///< Create default initialized packet after \a packet @@ -507,7 +506,7 @@ namespace senf { \throws TruncatedPacketException if \a size is smaller than the smallest permissible size for this type of packet. */ - static ConcretePacket createAfter(Packet packet, size_type size, NoInit_t); + static ConcretePacket createAfter(Packet packet, size_type size, senf::NoInit_t); ///< Create uninitialized packet after \a packet /**< Creates an uninitialized (all-zero) packet of the exact given size. It will be appended as next @@ -515,7 +514,7 @@ namespace senf { interpreter chain. \param[in] packet Packet to append new packet to. \param[in] size Size of the packet to create in bytes - \param[in] noinit This parameter must always have the + \param[in] senf::noinit This parameter must always have the value \c senf::noinit. */ template static ConcretePacket createAfter(Packet packet, @@ -541,7 +540,7 @@ namespace senf { header/interpreter before \a packet in that packets interpreter chain. \param[in] packet Packet to prepend new packet to. */ - static ConcretePacket createBefore(Packet packet, NoInit_t); + static ConcretePacket createBefore(Packet packet, senf::NoInit_t); ///< Create uninitialized empty packet before \a packet /**< Creates a completely empty and uninitialized packet. It will be prepended as previous header/interpreter before diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index 90d383b..81e1b4b 100644 --- a/Packets/Packet.test.cc +++ b/Packets/Packet.test.cc @@ -195,10 +195,10 @@ BOOST_AUTO_UNIT_TEST(concretePacket) senf::PacketData::byte data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; BOOST_CHECK_EQUAL( FooPacket::create().size(), 4u ); - BOOST_CHECK_EQUAL( FooPacket::create(FooPacket::noinit).size(), 0u ); + BOOST_CHECK_EQUAL( FooPacket::create(senf::noinit).size(), 0u ); BOOST_CHECK_THROW( FooPacket::create(2u), senf::TruncatedPacketException ); BOOST_CHECK_EQUAL( FooPacket::create(10u).size(), 10u ); - BOOST_CHECK_EQUAL( FooPacket::create(2u,FooPacket::noinit).size(), 2u ); + BOOST_CHECK_EQUAL( FooPacket::create(2u,senf::noinit).size(), 2u ); BOOST_CHECK_EQUAL( FooPacket::create(data).size(), 6u ); senf::Packet packet (FooPacket::create()); @@ -206,14 +206,14 @@ BOOST_AUTO_UNIT_TEST(concretePacket) BOOST_CHECK_EQUAL( FooPacket::createAfter(packet).size(), 4u ); BOOST_CHECK_EQUAL( packet.size(), 8u ); - BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,FooPacket::noinit).size(), 0u ); + BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,senf::noinit).size(), 0u ); BOOST_CHECK_EQUAL( packet.size(), 4u ); BOOST_CHECK_THROW( FooPacket::createAfter(packet,2u), senf::TruncatedPacketException ); BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,10u).size(), 10u ); BOOST_CHECK_EQUAL( packet.size(), 14u ); - BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,2u,FooPacket::noinit).size(), 2u ); + BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,2u,senf::noinit).size(), 2u ); BOOST_CHECK_EQUAL( packet.size(), 6u ); BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,data).size(), 6u ); @@ -222,7 +222,7 @@ BOOST_AUTO_UNIT_TEST(concretePacket) BOOST_CHECK_EQUAL( FooPacket::createBefore(packet).size(), 14u ); BOOST_CHECK_EQUAL( packet.size(), 10u ); - BOOST_CHECK_EQUAL( FooPacket::createBefore(packet,FooPacket::noinit).size(), 10u ); + BOOST_CHECK_EQUAL( FooPacket::createBefore(packet,senf::noinit).size(), 10u ); BOOST_CHECK_EQUAL( packet.size(), 10u ); BOOST_CHECK( packet.clone() != packet ); diff --git a/Packets/PacketInterpreter.ct b/Packets/PacketInterpreter.ct index ee4ff1f..72715e7 100644 --- a/Packets/PacketInterpreter.ct +++ b/Packets/PacketInterpreter.ct @@ -63,14 +63,14 @@ senf::PacketInterpreter::create(size_type size) { if (size < initSize()) throw TruncatedPacketException(); - ptr pi (create(size,noinit)); + ptr pi (create(size,senf::noinit)); pi->init(); return pi; } template prefix_ typename senf::PacketInterpreter::ptr -senf::PacketInterpreter::create(size_type size, NoInit_t) +senf::PacketInterpreter::create(size_type size, senf::NoInit_t) { detail::PacketImpl::Guard p (new detail::PacketImpl(size,0)); ptr pi (create(p.p,p.p->begin(),p.p->end(),Append)); @@ -86,7 +86,7 @@ senf::PacketInterpreter::createAfter(PacketInterpreterBase::ptr pack { if (size < initSize()) throw TruncatedPacketException(); - ptr pi (createAfter(packet,size,noinit)); + ptr pi (createAfter(packet,size,senf::noinit)); std::fill(pi->data().begin(), pi->data().end(),0); pi->init(); return pi; @@ -95,7 +95,7 @@ senf::PacketInterpreter::createAfter(PacketInterpreterBase::ptr pack template prefix_ typename senf::PacketInterpreter::ptr senf::PacketInterpreter::createAfter(PacketInterpreterBase::ptr packet, - size_type size, NoInit_t) + size_type size, senf::NoInit_t) { optional_range r (packet->nextPacketRange()); if (!r) @@ -134,7 +134,7 @@ template prefix_ typename senf::PacketInterpreter::ptr senf::PacketInterpreter::createBefore(PacketInterpreterBase::ptr packet) { - ptr pi (createBefore(packet, noinit)); + ptr pi (createBefore(packet, senf::noinit)); pi->data().insert(pi->data().begin(),initHeadSize(),byte(0x00u)); pi->data().insert(pi->data().end(),initSize()-initHeadSize(),byte(0x00u)); pi->init(); @@ -143,7 +143,7 @@ senf::PacketInterpreter::createBefore(PacketInterpreterBase::ptr pac template prefix_ typename senf::PacketInterpreter::ptr -senf::PacketInterpreter::createBefore(PacketInterpreterBase::ptr packet, NoInit_t) +senf::PacketInterpreter::createBefore(PacketInterpreterBase::ptr packet, senf::NoInit_t) { if (packet->prev()) packet->impl().truncateInterpretersBackwards(packet->prev().get()); @@ -222,7 +222,7 @@ prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::Factory::create(ForwardReadableRange const & range) const { - ptr pi (create(boost::size(range),noinit)); + ptr pi (create(boost::size(range),senf::noinit)); std::copy(boost::begin(range), boost::end(range), pi->data().begin()); return pi; } @@ -233,7 +233,7 @@ senf::PacketInterpreterBase::Factory::createAfter(PacketInterpreterBase::ptr pac ForwardReadableRange const & range) const { - ptr pi (createAfter(packet,boost::size(range),noinit)); + ptr pi (createAfter(packet,boost::size(range),senf::noinit)); std::copy(boost::begin(range), boost::end(range), pi->data().begin()); return pi; } @@ -253,10 +253,10 @@ senf::PacketInterpreter::FactoryImpl::create() template prefix_ typename senf::PacketInterpreterBase::ptr -senf::PacketInterpreter::FactoryImpl::create(NoInit_t) +senf::PacketInterpreter::FactoryImpl::create(senf::NoInit_t) const { - return senf::PacketInterpreter::create(noinit); + return senf::PacketInterpreter::create(senf::noinit); } template @@ -269,10 +269,10 @@ senf::PacketInterpreter::FactoryImpl::create(size_type size) template prefix_ typename senf::PacketInterpreterBase::ptr -senf::PacketInterpreter::FactoryImpl::create(size_type size, NoInit_t) +senf::PacketInterpreter::FactoryImpl::create(size_type size, senf::NoInit_t) const { - return senf::PacketInterpreter::create(size, noinit); + return senf::PacketInterpreter::create(size, senf::noinit); } // Create packet as new packet after a given packet @@ -288,10 +288,10 @@ senf::PacketInterpreter::FactoryImpl::createAfter(PacketInterpreterB template prefix_ typename senf::PacketInterpreterBase::ptr senf::PacketInterpreter::FactoryImpl::createAfter(PacketInterpreterBase::ptr packet, - NoInit_t) + senf::NoInit_t) const { - return senf::PacketInterpreter::createAfter(packet,noinit); + return senf::PacketInterpreter::createAfter(packet,senf::noinit); } template @@ -306,10 +306,10 @@ senf::PacketInterpreter::FactoryImpl::createAfter(PacketInterpreterB template prefix_ typename senf::PacketInterpreterBase::ptr senf::PacketInterpreter::FactoryImpl::createAfter(PacketInterpreterBase::ptr packet, - size_type size, NoInit_t) + size_type size, senf::NoInit_t) const { - return senf::PacketInterpreter::createAfter(packet,size,noinit); + return senf::PacketInterpreter::createAfter(packet,size,senf::noinit); } // Create packet as new packet (header) before a given packet @@ -326,10 +326,10 @@ createBefore(PacketInterpreterBase::ptr packet) template prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreter::FactoryImpl:: -createBefore(PacketInterpreterBase::ptr packet, NoInit_t) +createBefore(PacketInterpreterBase::ptr packet, senf::NoInit_t) const { - return senf::PacketInterpreter::createBefore(packet,noinit); + return senf::PacketInterpreter::createBefore(packet,senf::noinit); } // Parse next packet in chain diff --git a/Packets/PacketInterpreter.cti b/Packets/PacketInterpreter.cti index 1896850..b2696f6 100644 --- a/Packets/PacketInterpreter.cti +++ b/Packets/PacketInterpreter.cti @@ -75,9 +75,9 @@ senf::PacketInterpreter::create() template prefix_ typename senf::PacketInterpreter::ptr -senf::PacketInterpreter::create(NoInit_t) +senf::PacketInterpreter::create(senf::NoInit_t) { - return create(0,noinit); + return create(0,senf::noinit); } template @@ -101,9 +101,9 @@ senf::PacketInterpreter::createAfter(PacketInterpreterBase::ptr pack template prefix_ typename senf::PacketInterpreter::ptr -senf::PacketInterpreter::createAfter(PacketInterpreterBase::ptr packet, NoInit_t) +senf::PacketInterpreter::createAfter(PacketInterpreterBase::ptr packet, senf::NoInit_t) { - return createAfter(packet, 0, noinit); + return createAfter(packet, 0, senf::noinit); } // Create clone of current packet diff --git a/Packets/PacketInterpreter.hh b/Packets/PacketInterpreter.hh index 707e4b4..9a1a3fa 100644 --- a/Packets/PacketInterpreter.hh +++ b/Packets/PacketInterpreter.hh @@ -34,6 +34,7 @@ #include #include "../Utils/intrusive_refcount.hh" #include "../Utils/pool_alloc_mixin.hh" +#include "../Utils/Tags.hh" #include "PacketData.hh" #include "../Utils/TypeIdValue.hh" @@ -75,7 +76,6 @@ namespace senf { enum Append_t { Append }; enum Prepend_t { Prepend }; - enum NoInit_t { noinit }; /** \brief Internal: Abstract packet factory @@ -91,19 +91,19 @@ namespace senf { // Create completely new packet virtual ptr create() const = 0; - virtual ptr create(NoInit_t) const = 0; + virtual ptr create(senf::NoInit_t) const = 0; virtual ptr create(size_type size) const = 0; - virtual ptr create(size_type size, NoInit_t) const = 0; + virtual ptr create(size_type size, senf::NoInit_t) const = 0; template ptr create(ForwardReadableRange const & range) const; // Create packet as new packet after a given packet virtual ptr createAfter(PacketInterpreterBase::ptr packet) const = 0; - virtual ptr createAfter(PacketInterpreterBase::ptr packet, NoInit_t) const = 0; + virtual ptr createAfter(PacketInterpreterBase::ptr packet, senf::NoInit_t) const = 0; virtual ptr createAfter(PacketInterpreterBase::ptr packet, size_type size) const = 0; virtual ptr createAfter(PacketInterpreterBase::ptr packet, size_type size, - NoInit_t) const = 0; + senf::NoInit_t) const = 0; template ptr createAfter(PacketInterpreterBase::ptr packet, ForwardReadableRange const & range) const; @@ -111,7 +111,7 @@ namespace senf { // Create packet as new packet (header) const before a given packet virtual ptr createBefore(PacketInterpreterBase::ptr packet) const = 0; - virtual ptr createBefore(PacketInterpreterBase::ptr packet, NoInit_t) const = 0; + virtual ptr createBefore(PacketInterpreterBase::ptr packet, senf::NoInit_t) const = 0; // Parse next packet in chain @@ -256,18 +256,18 @@ namespace senf { // Create completely new packet static ptr create(); - static ptr create(NoInit_t); + static ptr create(senf::NoInit_t); static ptr create(size_type size); - static ptr create(size_type size, NoInit_t); + static ptr create(size_type size, senf::NoInit_t); template static ptr create(ForwardReadableRange const & range); // Create packet as new packet after a given packet static ptr createAfter(PacketInterpreterBase::ptr packet); - static ptr createAfter(PacketInterpreterBase::ptr packet, NoInit_t); + static ptr createAfter(PacketInterpreterBase::ptr packet, senf::NoInit_t); static ptr createAfter(PacketInterpreterBase::ptr packet, size_type size); - static ptr createAfter(PacketInterpreterBase::ptr packet, size_type size, NoInit_t); + static ptr createAfter(PacketInterpreterBase::ptr packet, size_type size, senf::NoInit_t); template static ptr createAfter(PacketInterpreterBase::ptr packet, ForwardReadableRange const & range); @@ -275,7 +275,7 @@ namespace senf { // Create packet as new packet (header) before a given packet static ptr createBefore(PacketInterpreterBase::ptr packet); - static ptr createBefore(PacketInterpreterBase::ptr packet, NoInit_t); + static ptr createBefore(PacketInterpreterBase::ptr packet, senf::NoInit_t); // Create a clone of the current packet @@ -333,27 +333,27 @@ namespace senf { // Create completely new packet virtual PacketInterpreterBase::ptr create() const; - virtual PacketInterpreterBase::ptr create(NoInit_t) const; + virtual PacketInterpreterBase::ptr create(senf::NoInit_t) const; virtual PacketInterpreterBase::ptr create(size_type size) const; - virtual PacketInterpreterBase::ptr create(size_type size,NoInit_t) const; + virtual PacketInterpreterBase::ptr create(size_type size,senf::NoInit_t) const; // Create packet as new packet after a given packet virtual PacketInterpreterBase::ptr createAfter(PacketInterpreterBase::ptr packet) const; virtual PacketInterpreterBase::ptr createAfter(PacketInterpreterBase::ptr packet, - NoInit_t) const; + senf::NoInit_t) const; virtual PacketInterpreterBase::ptr createAfter(PacketInterpreterBase::ptr packet, size_type size) const; virtual PacketInterpreterBase::ptr createAfter(PacketInterpreterBase::ptr packet, - size_type size, NoInit_t) const; + size_type size, senf::NoInit_t) const; // Create packet as new packet (header) before a given packet virtual PacketInterpreterBase::ptr createBefore(PacketInterpreterBase::ptr packet) const; virtual PacketInterpreterBase::ptr createBefore(PacketInterpreterBase::ptr packet, - NoInit_t) + senf::NoInit_t) const; // Parse next packet in chain diff --git a/Packets/PacketInterpreter.test.cc b/Packets/PacketInterpreter.test.cc index eb3a6db..13c9c93 100644 --- a/Packets/PacketInterpreter.test.cc +++ b/Packets/PacketInterpreter.test.cc @@ -129,9 +129,9 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) { BOOST_CHECK_NO_THROW( - senf::PacketInterpreter::create(4u,senf::PacketInterpreterBase::noinit)); + senf::PacketInterpreter::create(4u,senf::noinit)); senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(senf::PacketInterpreterBase::noinit)); + (senf::PacketInterpreter::create(senf::noinit)); BOOST_CHECK_EQUAL( p->data().size(), 0u ); } @@ -162,7 +162,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) (senf::PacketInterpreter::create(12u)); senf::PacketInterpreter::ptr p2 (senf::PacketInterpreter::createAfter( - p,senf::PacketInterpreterBase::noinit)); + p,senf::noinit)); BOOST_CHECK_EQUAL( p2->data().size(), 0u ); BOOST_CHECK_EQUAL( p->data().size(), 8u ); } @@ -178,7 +178,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) BOOST_CHECK_THROW( senf::PacketInterpreter::createAfter(p,4u), senf::TruncatedPacketException ); BOOST_CHECK_NO_THROW( senf::PacketInterpreter::createAfter( - p,4u,senf::PacketInterpreterBase::noinit) ); + p,4u,senf::noinit) ); } { @@ -204,7 +204,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) senf::PacketInterpreter::ptr p3 (senf::PacketInterpreter::createBefore( - p,senf::PacketInterpreterBase::noinit)); + p,senf::noinit)); BOOST_CHECK_EQUAL( p3->data().size(), 10u ); } @@ -225,10 +225,10 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) BOOST_CHECK( factory->create()->is() ); BOOST_CHECK_EQUAL( factory->create()->data().size(), 8u ); - BOOST_CHECK_EQUAL( factory->create(senf::PacketInterpreterBase::noinit)->data().size(), 0u ); + BOOST_CHECK_EQUAL( factory->create(senf::noinit)->data().size(), 0u ); BOOST_CHECK_EQUAL( factory->create(12u)->data().size(), 12u ); BOOST_CHECK_EQUAL( - factory->create(4u, senf::PacketInterpreterBase::noinit)->data().size(), 4u ); + factory->create(4u, senf::noinit)->data().size(), 4u ); BOOST_CHECK_EQUAL( factory->create(data)->data().size(), 6u ); { @@ -245,7 +245,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) BOOST_CHECK( ! p->next()->next() ); BOOST_CHECK_EQUAL( - factory->createAfter(p, senf::PacketInterpreterBase::noinit)->data().size(), 0u ); + factory->createAfter(p, senf::noinit)->data().size(), 0u ); BOOST_CHECK_EQUAL( p->data().size(), 0u ); BOOST_CHECK( ! p->next()->next() ); @@ -254,7 +254,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) BOOST_CHECK( ! p->next()->next() ); BOOST_CHECK_EQUAL( - factory->createAfter(p,4u, senf::PacketInterpreterBase::noinit)->data().size(), 4u ); + factory->createAfter(p,4u, senf::noinit)->data().size(), 4u ); BOOST_CHECK_EQUAL( p->data().size(), 4u ); BOOST_CHECK( ! p->next()->next() ); @@ -273,7 +273,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) BOOST_CHECK_EQUAL( p->prev()->data().size(), 12u ); BOOST_CHECK_EQUAL( - factory->createBefore(p,senf::PacketInterpreterBase::noinit)->data().size(), 4u ); + factory->createBefore(p,senf::noinit)->data().size(), 4u ); BOOST_REQUIRE( p->prev() ); BOOST_CHECK( ! p->prev()->prev() ); BOOST_CHECK_EQUAL( p->prev()->data().size(), 4u ); diff --git a/Socket/ProtocolClientSocketHandle.cti b/Socket/ProtocolClientSocketHandle.cti index 9fe7718..e467fb0 100644 --- a/Socket/ProtocolClientSocketHandle.cti +++ b/Socket/ProtocolClientSocketHandle.cti @@ -37,7 +37,7 @@ template prefix_ senf::ProtocolClientSocketHandle:: -ProtocolClientSocketHandle(UninitializedType) +ProtocolClientSocketHandle(senf::NoInit_t) {} template diff --git a/Socket/ProtocolClientSocketHandle.hh b/Socket/ProtocolClientSocketHandle.hh index ed15510..8a04655 100644 --- a/Socket/ProtocolClientSocketHandle.hh +++ b/Socket/ProtocolClientSocketHandle.hh @@ -30,6 +30,7 @@ // Custom includes #include "ClientSocketHandle.hh" #include "../config.hh" +#include "../Utils/Tags.hh" #include "ProtocolClientSocketHandle.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -66,7 +67,6 @@ namespace senf { // Types typedef SocketProtocol Protocol; ///< The sockets protocol - enum UninitializedType { Uninitialized }; ///< Flag to call 'uninitialized' constructor /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members @@ -95,7 +95,7 @@ namespace senf { \implementation The socket handle will have no \c body allocated. */ - ProtocolClientSocketHandle(UninitializedType); + ProtocolClientSocketHandle(senf::NoInit_t); ///@} /////////////////////////////////////////////////////////////////////////// diff --git a/Socket/ProtocolServerSocketHandle.cti b/Socket/ProtocolServerSocketHandle.cti index c615b32..85ce200 100644 --- a/Socket/ProtocolServerSocketHandle.cti +++ b/Socket/ProtocolServerSocketHandle.cti @@ -37,7 +37,7 @@ template prefix_ senf::ProtocolServerSocketHandle:: -ProtocolServerSocketHandle(UninitializedType) +ProtocolServerSocketHandle(senf::NoInit_t) {} template diff --git a/Socket/ProtocolServerSocketHandle.hh b/Socket/ProtocolServerSocketHandle.hh index 4e010dc..2833f85 100644 --- a/Socket/ProtocolServerSocketHandle.hh +++ b/Socket/ProtocolServerSocketHandle.hh @@ -30,6 +30,7 @@ // Custom includes #include "ServerSocketHandle.hh" #include "../config.hh" +#include "../Utils/Tags.hh" #include "ProtocolServerSocketHandle.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -70,7 +71,6 @@ namespace senf { // Types typedef SocketProtocol Protocol; ///< The socket protocol - enum UninitializedType { Uninitialized }; ///< Flag to call 'uninitialized' constructor /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members @@ -100,7 +100,7 @@ namespace senf { \implementation The socket handle will have no \c body allocated. */ - ProtocolServerSocketHandle(UninitializedType); + ProtocolServerSocketHandle(senf::NoInit_t); ///@} /////////////////////////////////////////////////////////////////////////// diff --git a/Socket/Protocols/INet/INet4Address.cci b/Socket/Protocols/INet/INet4Address.cci index 4fb8774..65cc831 100644 --- a/Socket/Protocols/INet/INet4Address.cci +++ b/Socket/Protocols/INet/INet4Address.cci @@ -36,7 +36,7 @@ prefix_ senf::INet4Address::INet4Address() std::fill(begin(), end(), 0u); } -prefix_ senf::INet4Address::INet4Address(NoInit_t) +prefix_ senf::INet4Address::INet4Address(senf::NoInit_t) {} prefix_ senf::INet4Address senf::INet4Address::from_inaddr(inaddr_type v) diff --git a/Socket/Protocols/INet/INet4Address.ct b/Socket/Protocols/INet/INet4Address.ct index 4d223c0..408355b 100644 --- a/Socket/Protocols/INet/INet4Address.ct +++ b/Socket/Protocols/INet/INet4Address.ct @@ -36,7 +36,7 @@ template prefix_ senf::INet4Address senf::INet4Address::from_data(InputIterator i) { - INet4Address addr (INet4Address::noinit); + INet4Address addr (senf::noinit); iterator j (addr.begin()); iterator const j_end (addr.end()); for (;j!=j_end;++j,++i) diff --git a/Socket/Protocols/INet/INet4Address.hh b/Socket/Protocols/INet/INet4Address.hh index 19ec737..a77903d 100644 --- a/Socket/Protocols/INet/INet4Address.hh +++ b/Socket/Protocols/INet/INet4Address.hh @@ -33,6 +33,7 @@ #include #include #include "../../../Utils/safe_bool.hh" +#include "../../../Utils/Tags.hh" //#include "INet4Address.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -69,14 +70,12 @@ namespace senf { static INet4Address const Loopback; ///< The loopback (127.0.0.1) address static INet4Address const Broadcast; ////< The global broadcast (255.255.255.255) address - enum NoInit_t { noinit }; - /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ INet4Address(); ///< Construct an empty address - explicit INet4Address(NoInit_t); ///< Construct uninitialized (!) address + explicit INet4Address(senf::NoInit_t); ///< Construct uninitialized (!) address explicit INet4Address(address_type value); ///< Construct an address constant diff --git a/Socket/Protocols/INet/INet6Address.cci b/Socket/Protocols/INet/INet6Address.cci index 95e5335..5a788b6 100644 --- a/Socket/Protocols/INet/INet6Address.cci +++ b/Socket/Protocols/INet/INet6Address.cci @@ -32,7 +32,7 @@ #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// -prefix_ senf::INet6Address::INet6Address(NoInit_t) +prefix_ senf::INet6Address::INet6Address(senf::NoInit_t) {} prefix_ senf::INet6Address::INet6Address(boost::uint16_t a0, boost::uint16_t a1, diff --git a/Socket/Protocols/INet/INet6Address.ct b/Socket/Protocols/INet/INet6Address.ct index 360aa9e..83cc008 100644 --- a/Socket/Protocols/INet/INet6Address.ct +++ b/Socket/Protocols/INet/INet6Address.ct @@ -36,7 +36,7 @@ template prefix_ senf::INet6Address senf::INet6Address::from_data(InputIterator i) { - INet6Address addr (INet6Address::noinit); + INet6Address addr (senf::noinit); iterator j (addr.begin()); iterator const j_end (addr.end()); for (;j!=j_end;++j,++i) diff --git a/Socket/Protocols/INet/INet6Address.hh b/Socket/Protocols/INet/INet6Address.hh index a9d0cee..436d5fe 100644 --- a/Socket/Protocols/INet/INet6Address.hh +++ b/Socket/Protocols/INet/INet6Address.hh @@ -33,6 +33,7 @@ #include #include #include "../../../Utils/safe_bool.hh" +#include "../../../Utils/Tags.hh" #include "INet4Address.hh" //#include "INet6Address.mpp" @@ -108,7 +109,6 @@ namespace senf { static INet6Address const AllNodes; ///< The 'all nodes' link-local multicast address static INet6Address const AllRouters; ///< The 'all routers' link-local multicast address - enum NoInit_t { noinit }; enum Resolve_t { ResolveINet6, ResolveINet4 }; /** \brief Possible scope values @@ -134,7 +134,7 @@ namespace senf { ///\name Structors and default members ///@{ - explicit INet6Address(NoInit_t); ///< Construct uninitialized (!) address + explicit INet6Address(senf::NoInit_t); ///< Construct uninitialized (!) address INet6Address(boost::uint16_t a0=0u, boost::uint16_t a1=0u, boost::uint16_t a2=0u, boost::uint16_t a3=0u, boost::uint16_t a4=0u, boost::uint16_t a5=0u, boost::uint16_t a6=0u, boost::uint16_t a7=0u); diff --git a/Socket/Protocols/Raw/MACAddress.cc b/Socket/Protocols/Raw/MACAddress.cc index 361e457..48d2a1b 100644 --- a/Socket/Protocols/Raw/MACAddress.cc +++ b/Socket/Protocols/Raw/MACAddress.cc @@ -72,7 +72,7 @@ namespace { prefix_ senf::MACAddress::MACAddress senf::MACAddress::from_string(std::string const & s) { - MACAddress mac (MACAddress::noinit); + MACAddress mac (senf::noinit); typedef boost::char_separator separator; typedef boost::tokenizer tokenizer; separator sep (":-"); @@ -92,7 +92,7 @@ prefix_ senf::MACAddress senf::MACAddress::from_eui64(boost::uint64_t v) { if ( boost::uint16_t(v>>24) != 0xfffe ) throw SyntaxException(); - MACAddress mac (MACAddress::noinit); + MACAddress mac (senf::noinit); mac[0] = boost::uint8_t( v>>56 ); mac[1] = boost::uint8_t( v>>48 ); mac[2] = boost::uint8_t( v>>40 ); diff --git a/Socket/Protocols/Raw/MACAddress.cci b/Socket/Protocols/Raw/MACAddress.cci index 4db9e85..1879c90 100644 --- a/Socket/Protocols/Raw/MACAddress.cci +++ b/Socket/Protocols/Raw/MACAddress.cci @@ -38,7 +38,7 @@ prefix_ senf::MACAddress::MACAddress() std::fill(begin(),end(),0u); } -prefix_ senf::MACAddress::MACAddress(NoInit_t) +prefix_ senf::MACAddress::MACAddress(senf::NoInit_t) {} prefix_ senf::MACAddress::MACAddress(boost::uint64_t v) diff --git a/Socket/Protocols/Raw/MACAddress.ct b/Socket/Protocols/Raw/MACAddress.ct index 5b62341..2c6ae39 100644 --- a/Socket/Protocols/Raw/MACAddress.ct +++ b/Socket/Protocols/Raw/MACAddress.ct @@ -36,7 +36,7 @@ template prefix_ senf::MACAddress::MACAddress senf::MACAddress::from_data(InputIterator i) { - MACAddress mac (MACAddress::noinit); + MACAddress mac (senf::noinit); iterator j (mac.begin()); iterator const j_end (mac.end()); for (;j!=j_end;++j,++i) diff --git a/Socket/Protocols/Raw/MACAddress.hh b/Socket/Protocols/Raw/MACAddress.hh index 705c6e1..2ddd74d 100644 --- a/Socket/Protocols/Raw/MACAddress.hh +++ b/Socket/Protocols/Raw/MACAddress.hh @@ -33,6 +33,7 @@ #include #include #include "../../../Utils/safe_bool.hh" +#include "../../../Utils/Tags.hh" //#include "MACAddress.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -58,10 +59,8 @@ namespace senf { static MACAddress const Broadcast; ///< The broadcast address static MACAddress const None; ///< The empty (0) address - enum NoInit_t { noinit }; - MACAddress(); ///< Construct zero-initialized address - MACAddress(NoInit_t); ///< Construct uninitialized (!) address + MACAddress(senf::NoInit_t); ///< Construct uninitialized (!) address explicit MACAddress(boost::uint64_t v); ///< Construct MACAddress constants static MACAddress from_string(std::string const & s); diff --git a/Utils/Exception.hh b/Utils/Exception.hh index efb44f4..787a499 100644 --- a/Utils/Exception.hh +++ b/Utils/Exception.hh @@ -180,8 +180,6 @@ namespace senf { */ void throwErrno(std::string const & where, int code); - enum NoThrow_t { nothrow }; - } ///////////////////////////////hh.e//////////////////////////////////////// diff --git a/Utils/Mainpage.dox b/Utils/Mainpage.dox index 5ea64f3..e5639af 100644 --- a/Utils/Mainpage.dox +++ b/Utils/Mainpage.dox @@ -87,6 +87,8 @@ namespace senf { \ref IpChecksumcalculating the 16 bit checksum used in the IP specification + + \ref utils_tagsMiscellaneous type tags \section compatibility Compatibility diff --git a/Utils/Tags.hh b/Utils/Tags.hh new file mode 100644 index 0000000..d534672 --- /dev/null +++ b/Utils/Tags.hh @@ -0,0 +1,100 @@ +// $Id$ +// +// Copyright (C) 2008 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// 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 Tags public header */ + +#ifndef HH_Tags_ +#define HH_Tags_ 1 + +// Custom includes + +//#include "Tags.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +/** \defgroup utils_tags Type tags + + Type tags are used to select variants of a member, function, template or constructor. A Type tag + always has only a single value which is passed wherever a parameter of that tag's type is + needed. + + The argument which expects a type-tag value will always be declared in such a way, that it is + optional. Examples of type tag use are: + + \code + result = object.find(); // This call may throw + result = object.find(senf::nothrow); // This call will not throw + \endcode + + Of course, this only works with objects which explicitly declare, that they take an optional + senf::NoThrow_t type aprameter. + + */ + +namespace senf { + + /** \brief Type tag selecting non-throwing variant of something + + This tag is used to select the non-throwing variant of a member, function, template or + constructor. An argument of this type is always declared in such a way, that it is + optional. + + There is only a single value for this type: \ref senf::nothrow which is the value to pass + wherever an (optional) senf::NoThrow_t parameter is requested. + + \see \ref utils_tags + \ingroup utils_tags + */ + enum NoThrow_t { nothrow }; + + /** \brief Type tag selecting uninitialized variant of something + + This tag is used to select the unititialized variant of a member, function, template or + constructor (mostly a constructor). An argument of this type is always declared in such a + way, that it is optional. + + There is only a single value for this type: \ref senf::noinit which is the value to pass + wherever an (optional) senf::NoInit_t parameter is requested. + + \see \ref utils_tags + \ingroup utils_tags + */ + enum NoInit_t { noinit }; + +} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "Tags.cci" +//#include "Tags.ct" +//#include "Tags.cti" +#endif + + +// 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: diff --git a/Utils/Tags.test.cc b/Utils/Tags.test.cc new file mode 100644 index 0000000..c58dad5 --- /dev/null +++ b/Utils/Tags.test.cc @@ -0,0 +1,52 @@ +// $Id$ +// +// Copyright (C) 2008 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// 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 Tags.test unit tests */ + +//#include "Tags.test.hh" +//#include "Tags.test.ih" + +// Custom includes +#include "Tags.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +// Nothing to test + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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: