// $Id$ // // Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) // 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 SocketHandle inline template implementation */ #include "SocketHandle.ih" // Custom includes #include #include #include "../Utils/TypeInfo.hh" #define prefix_ inline ///////////////////////////////cti.p/////////////////////////////////////// template prefix_ senf::SocketHandle::SocketHandle() {} template template prefix_ senf::SocketHandle::SocketHandle(SocketHandle other, typename IsCompatible::type *) : FileHandle(other) {} template template prefix_ typename senf::SocketHandle::template IsCompatible::type const & senf::SocketHandle::operator=(SocketHandle other) { assign(other); return *this; } template prefix_ senf::SocketHandle::SocketHandle(std::auto_ptr protocol, bool isServer) : FileHandle(std::auto_ptr(new SocketBody(protocol,isServer))) {} template prefix_ senf::SocketHandle::SocketHandle(FileHandle other, bool isChecked) : FileHandle(other) { BOOST_ASSERT( isChecked ); BOOST_ASSERT( dynamic_cast(&FileHandle::body()) ); } template prefix_ senf::SocketBody & senf::SocketHandle::body() { BOOST_ASSERT( dynamic_cast(&FileHandle::body()) ); return static_cast(FileHandle::body()); } template prefix_ senf::SocketBody const & senf::SocketHandle::body() const { BOOST_ASSERT( dynamic_cast(&FileHandle::body()) ); return static_cast(FileHandle::body()); } template prefix_ senf::SocketProtocol const & senf::SocketHandle::protocol() const { return body().protocol(); } template prefix_ void senf::SocketHandle::assign(FileHandle other) { FileHandle::operator=(other); } template prefix_ senf::SocketHandle senf::SocketHandle::cast_static(FileHandle handle) { return SocketHandle(handle,true); } template prefix_ senf::SocketHandle senf::SocketHandle::cast_dynamic(FileHandle handle) { // throws bad_cast if the body is not a SocketBody SocketBody & body (dynamic_cast(FileHandle::body(handle))); // throws bad_cast if the policy is not compatible SocketPolicy::checkBaseOf(body.protocol().policy()); return cast_static(handle); } template prefix_ Target senf::static_socket_cast(Source handle) { BOOST_STATIC_ASSERT(( boost::is_convertible::value && boost::is_convertible::value && ( boost::is_convertible::value || boost::is_convertible::value ) )); BOOST_ASSERT( check_socket_cast(handle) ); return Target::cast_static(handle); } template prefix_ Target senf::dynamic_socket_cast(Source handle) { BOOST_STATIC_ASSERT(( boost::is_convertible::value && boost::is_convertible::value && ( boost::is_convertible::value || boost::is_convertible::value ) )); return Target::cast_dynamic(handle); } template prefix_ bool senf::check_socket_cast(Source handle) { BOOST_STATIC_ASSERT(( boost::is_convertible::value && boost::is_convertible::value && ( boost::is_convertible::value || boost::is_convertible::value ) )); // we don't have a non-throwing variant of cast_dynamic // for two reasons: // a) since the handle is passed back by value, we cannot return // something like a null handle // b) it is simpler to implement cast_dynamic throwig bad_cast on // failure than implementing cast_check try { Target::cast_dynamic(handle); } catch (std::bad_cast const &) { return false; } return true; } template prefix_ void senf::SocketHandle::state(SocketStateMap & map, unsigned lod) { // We use typeid here even though the type of *this is static // (SocketHandle is not polymorphic and has no vtable). This will // automatically include the SocketPolicy template parameter in // the type name and therefore show the \e static policy of the // socket handle. map["handle"] = prettyName(typeid(*this)); body().state(map,lod); } template prefix_ std::string senf::SocketHandle::dumpState(unsigned lod) { SocketStateMap map; state(map,lod); return detail::dumpState(map); } /////////////////////////////////////////////////////////////////////////// // senf::detail::ConvertibleString template prefix_ senf::detail::ConvertibleString::ConvertibleString(T const & other) : std::string(boost::lexical_cast(other)) {} ///////////////////////////////cti.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: