// $Id$ // // Copyright (C) 2006 // 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 PacketRegistry non-inline template implementation */ #include "PacketRegistry.ih" // Custom includes #include #include #include #include #include #include #define prefix_ ///////////////////////////////ct.p//////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // senf::detail::PacketRegistryImpl::Entry template prefix_ senf::detail::PacketRegistryImpl::Entry::Entry(KeyType const & key_, int priority_) : key (key_), priority (priority_) {} template prefix_ senf::detail::PacketRegistryImpl::Entry::~Entry() {} /////////////////////////////////////////////////////////////////////////// // senf::detail::PacketRegistryImpl::EntryImpl template template prefix_ senf::detail::PacketRegistryImpl::EntryImpl:: EntryImpl(KeyType const & key, int priority) : Entry (key, priority) {} template template prefix_ senf::Packet::factory_t senf::detail::PacketRegistryImpl::EntryImpl::factory() const { return PacketType::factory(); } template template prefix_ std::string senf::detail::PacketRegistryImpl::EntryImpl::name() const { return prettyName(typeid(PacketType)); } template template prefix_ std::type_info const & senf::detail::PacketRegistryImpl::EntryImpl::type() const { return typeid(PacketType); } /////////////////////////////////////////////////////////////////////////// // senf::PacketRegistry template prefix_ typename senf::PacketRegistry::Registry & senf::PacketRegistry::registry() { static Registry registry (prettyName(typeid(Tag))); return registry; } /////////////////////////////////////////////////////////////////////////// // senf::detail::PacketRegistryImpl: template template prefix_ void senf::detail::PacketRegistryImpl::registerPacket(key_t key, int priority) { bool ok (registry_.insert( typename Entry::ptr(new EntryImpl(key,priority))).second); SENF_ASSERT(ok && "Duplicate packet registration"); } template template prefix_ void senf::detail::PacketRegistryImpl::unregisterPacket() { registry_.template get().erase(typeid(PacketType)); } template prefix_ void senf::detail::PacketRegistryImpl::unregisterPacket(key_t key, int priority) { // Why doesn't this work: // registry_.erase(boost::make_tuple(key,priority)); typename Registry::iterator i (registry_.find(boost::make_tuple(key,priority))); if (i != registry_.end()) registry_.erase(i); } template prefix_ typename senf::detail::PacketRegistryImpl::key_t senf::detail::PacketRegistryImpl::key(senf::TypeIdValue const & type) { boost::optional k (key(type,true)); if (! k) throw PacketTypeNotRegisteredException(); return *k; } template prefix_ boost::optional::key_t> senf::detail::PacketRegistryImpl::key(senf::TypeIdValue const & type, bool) { typedef typename Registry::template index::type TypeIndex; TypeIndex const & typeIndex (registry_.template get()); typename TypeIndex::const_iterator i (typeIndex.find(type.id())); if (i == typeIndex.end()) return boost::optional(); return (*i)->key; } template prefix_ typename senf::detail::PacketRegistryImpl::Entry const & senf::detail::PacketRegistryImpl::lookup(key_t key) { Entry const * e (lookup(key, true)); if (!e) throw PacketTypeNotRegisteredException(); return *e; } template prefix_ typename senf::detail::PacketRegistryImpl::Entry const * senf::detail::PacketRegistryImpl::lookup(key_t key, bool) { typedef typename Registry::template index::type KeyIndex; KeyIndex const & keyIndex (registry_.template get()); typename KeyIndex::const_iterator i (keyIndex.lower_bound(key)); if (i == keyIndex.end() || (*i)->key != key) return 0; return i->get(); } template prefix_ bool senf::detail::PacketRegistryImpl::v_empty() const { return registry_.empty(); } template prefix_ void senf::detail::PacketRegistryImpl::v_dump(std::ostream & os) const { typedef typename Registry::template index::type KeyIndex; KeyIndex const & keyIndex (registry_.template get()); for (typename KeyIndex::iterator i (keyIndex.begin()), i_end (keyIndex.end()); i != i_end; ++i) { std::string n ((*i)->name()); senf::detail::DumpKey::dump((*i)->key, os); os << ' ' << std::setw(6) << (*i)->priority << ' ' << n.substr(21,n.size()-22) << '\n'; } } template prefix_ void senf::detail::PacketRegistryImpl::v_clear() { registry_.clear(); } /////////////////////////////////////////////////////////////////////////// // senf::detail::DumpKey template prefix_ void senf::detail::DumpKey::dump(KeyType const & v, std::ostream & os) { os << " " << std::setw(16) << std::left << v << std::setw(0) << std::right; } // senf::detail::DumpKey template prefix_ void senf::detail::DumpKey::dump(KeyType const & v, std::ostream & os) { os << " " << senf::format::dumpint(v); } ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ // fill-column: 100 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // comment-column: 40 // End: