src/core/callback.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 4205 751691462d36
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
     1 #include "callback.h"
     2 
     3 namespace ns3 {
     4 
     5 CallbackValue::CallbackValue ()
     6   : m_value ()
     7 {}
     8 CallbackValue::CallbackValue (const CallbackBase &base)
     9   : m_value (base)
    10 {}
    11 CallbackValue::~CallbackValue ()
    12 {}
    13 void 
    14 CallbackValue::Set (CallbackBase base)
    15 {
    16   m_value = base;
    17 }
    18 Ptr<AttributeValue> 
    19 CallbackValue::Copy (void) const
    20 {
    21   return Create<CallbackValue> (m_value);
    22 }
    23 std::string 
    24 CallbackValue::SerializeToString (Ptr<const AttributeChecker> checker) const
    25 {
    26   std::ostringstream oss;
    27   oss << PeekPointer (m_value.GetImpl ());
    28   return oss.str ();
    29 }
    30 bool 
    31 CallbackValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
    32 {
    33   return false;
    34 }
    35 
    36 ATTRIBUTE_CHECKER_IMPLEMENT (Callback);
    37 
    38 #if (__GNUC__ >= 3)
    39 
    40 #include <stdlib.h>
    41 #include <cxxabi.h>
    42 #include "log.h"
    43 
    44 std::string
    45 CallbackBase::Demangle(const std::string& mangled)
    46 {
    47     int status;
    48     char* demangled = abi::__cxa_demangle(mangled.c_str(),
    49                                           NULL, NULL, &status);
    50 
    51     std::string ret;
    52     if (status == 0) {
    53         NS_ASSERT(demangled);
    54         ret = demangled;
    55     }
    56     else if (status == -1) {
    57         NS_LOG_UNCOND("Callback demangling failed: Memory allocation failure occured.");
    58         ret = mangled;
    59     }
    60     else if (status == -2) {
    61         NS_LOG_UNCOND("Callback demangling failed: Mangled name is not a valid under the C++ ABI mangling rules.");
    62         ret = mangled;
    63     }
    64     else if (status == -3) {
    65         NS_LOG_UNCOND("Callback demangling failed: One of the arguments is invalid.");
    66         ret = mangled;
    67     }
    68     else {
    69         NS_LOG_UNCOND("Callback demangling failed: status " << status);
    70         ret = mangled;
    71     }
    72 
    73     if (demangled) {
    74         free(demangled);
    75     }
    76     return ret;
    77 }
    78 
    79 #else
    80 
    81 std::string
    82 CallbackBase::Demangle(const std::string& mangled)
    83 {
    84     return mangled;
    85 }
    86 
    87 #endif
    88 
    89 } // namespace ns3