// $Id$ // // Copyright (C) 2006 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \file \brief PacketRegistry non-inline template implementation */ #include "PacketRegistry.ih" // Custom includes #include #include #include #include #include #define prefix_ //-///////////////////////////////////////////////////////////////////////////////////////////////// //-///////////////////////////////////////////////////////////////////////////////////////////////// // 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::detail::PacketRegistryImpl: template template prefix_ void senf::detail::PacketRegistryImpl::registerPacket(key_t key, int priority) { SENF_ASSERT_EXPRESSION( registry_.insert( typename Entry::ptr(new EntryImpl(key,priority))).second, "Duplicate packet registration"); } template template prefix_ void senf::detail::PacketRegistryImpl::unregisterPacket() { registryByType_.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) { typename RegistryByType::const_iterator i (registryByType_.find(type.id())); if (i == registryByType_.end()) return boost::optional(); return (*i)->key; } template prefix_ typename senf::detail::PacketRegistryImpl::Entry const & senf::detail::PacketRegistryImpl::lookup(key_t key) const { 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) const { typename RegistryByKey::const_iterator i (registryByKey_.lower_bound(key)); if (i == registryByKey_.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 { for (typename RegistryByKey::const_iterator i (registryByKey_.begin()), i_end (registryByKey_.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); } //-///////////////////////////////////////////////////////////////////////////////////////////////// #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: