Utils/Termlib: Extend the completion API
[senf.git] / Socket / SocketHandle.cti
index f059c56..310dfdd 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
@@ -27,9 +27,8 @@
 #include "SocketHandle.ih"
 
 // Custom includes
-#include "../Utils/senfassert.hh"
 #include <typeinfo>
-#include <boost/lexical_cast.hpp>
+#include "../Utils/senfassert.hh"
 #include "../Utils/TypeInfo.hh"
 
 #define prefix_ inline
@@ -69,7 +68,7 @@ prefix_ senf::SocketHandle<SPolicy>::SocketHandle(FileHandle other, bool isCheck
     : FileHandle(other)
 {
     SENF_ASSERT( isChecked );
-    SENF_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) );
+    SENF_ASSERT( ! valid() || dynamic_cast<SocketBody *>(&FileHandle::body()) );
 }
 
 template <class SPolicy>
@@ -88,7 +87,7 @@ prefix_ senf::SocketBody const & senf::SocketHandle<SPolicy>::body()
 }
 
 template <class SPolicy>
-prefix_ senf::SocketProtocol const & senf::SocketHandle<SPolicy>::protocol()
+prefix_ senf::SocketProtocol & senf::SocketHandle<SPolicy>::protocol()
     const
 {
     return body().protocol();
@@ -113,7 +112,7 @@ senf::SocketHandle<SPolicy>::cast_dynamic(FileHandle handle)
 {
     // throws bad_cast if the body is not a SocketBody
     SocketBody & body (dynamic_cast<SocketBody&>(FileHandle::body(handle)));
-    // throws bad_cast if the policy is not compatible
+    // throws bad_cast if the policy is not compatible (already wrapped ...)
     SPolicy::checkBaseOf(body.protocol().policy());
     return cast_static(handle);
 }
@@ -133,22 +132,25 @@ prefix_ Target senf::static_socket_cast(Source handle)
 template <class Target, class Source>
 prefix_ Target senf::dynamic_socket_cast(Source handle)
 {
-    BOOST_STATIC_ASSERT((
-        boost::is_convertible<Source*,FileHandle*>::value &&
-        boost::is_convertible<Target*,FileHandle*>::value &&
-        ( boost::is_convertible<Source,Target>::value ||
-          boost::is_convertible<Target,Source>::value ) ));
-    return Target::cast_dynamic(handle);
+//     BOOST_STATIC_ASSERT((
+//         boost::is_convertible<Source*,FileHandle*>::value &&
+//         boost::is_convertible<Target*,FileHandle*>::value &&
+//         ( boost::is_convertible<Source,Target>::value ||
+//           boost::is_convertible<Target,Source>::value ) ));
+    try {
+        return Target::cast_dynamic(handle);
+    }
+    SENF_WRAP_EXC(std::bad_cast)
 }
 
 template <class Target, class Source>
 prefix_ bool senf::check_socket_cast(Source handle)
 {
-    BOOST_STATIC_ASSERT((
-        boost::is_convertible<Source*,FileHandle*>::value &&
-        boost::is_convertible<Target*,FileHandle*>::value &&
-        ( boost::is_convertible<Source,Target>::value ||
-          boost::is_convertible<Target,Source>::value ) ));
+//     BOOST_STATIC_ASSERT((
+//         boost::is_convertible<Source*,FileHandle*>::value &&
+//         boost::is_convertible<Target*,FileHandle*>::value &&
+//         ( boost::is_convertible<Source,Target>::value ||
+//           boost::is_convertible<Target,Source>::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
@@ -184,6 +186,17 @@ prefix_ std::string senf::SocketHandle<SPolicy>::dumpState(unsigned lod)
     return detail::dumpState(map);
 }
 
+template <class SPolicy>
+template <class Facet>
+prefix_ Facet & senf::SocketHandle<SPolicy>::facet()
+
+{
+    try {
+        return dynamic_cast<Facet &>(protocol());
+    }
+    SENF_WRAP_EXC(std::bad_cast)
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::ProtocolSocketBody<SProtocol>