A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
callback.cc
Go to the documentation of this file.
1 #include "callback.h"
2 #include "log.h"
3 
4 NS_LOG_COMPONENT_DEFINE ("Callback");
5 
6 namespace ns3 {
7 
9  : m_value ()
10 {
11  NS_LOG_FUNCTION (this);
12 }
14  : m_value (base)
15 {
16 }
18 {
19  NS_LOG_FUNCTION (this);
20 }
21 void
23 {
24  NS_LOG_FUNCTION (&base);
25 
26  m_value = base;
27 }
29 CallbackValue::Copy (void) const
30 {
31  NS_LOG_FUNCTION (this);
32  return Create<CallbackValue> (m_value);
33 }
34 std::string
36 {
37  NS_LOG_FUNCTION (this << checker);
38  std::ostringstream oss;
39  oss << PeekPointer (m_value.GetImpl ());
40  return oss.str ();
41 }
42 bool
44 {
45  NS_LOG_FUNCTION (this << value << checker);
46  return false;
47 }
48 
51 
52 } // namespace ns3
53 
54 #if (__GNUC__ >= 3)
55 
56 #include <cstdlib>
57 #include <cxxabi.h>
58 #include "log.h"
59 
60 namespace ns3 {
61 
62 std::string
63 CallbackBase::Demangle (const std::string& mangled)
64 {
65  NS_LOG_FUNCTION (mangled);
66 
67  int status;
68  char* demangled = abi::__cxa_demangle (mangled.c_str (),
69  NULL, NULL, &status);
70 
71  std::string ret;
72  if (status == 0) {
73  NS_ASSERT (demangled);
74  ret = demangled;
75  }
76  else if (status == -1) {
77  NS_LOG_UNCOND ("Callback demangling failed: Memory allocation failure occured.");
78  ret = mangled;
79  }
80  else if (status == -2) {
81  NS_LOG_UNCOND ("Callback demangling failed: Mangled name is not a valid under the C++ ABI mangling rules.");
82  ret = mangled;
83  }
84  else if (status == -3) {
85  NS_LOG_UNCOND ("Callback demangling failed: One of the arguments is invalid.");
86  ret = mangled;
87  }
88  else {
89  NS_LOG_UNCOND ("Callback demangling failed: status " << status);
90  ret = mangled;
91  }
92 
93  if (demangled) {
94  std::free (demangled);
95  }
96  return ret;
97 }
98 
99 } // namespace ns3
100 
101 #else
102 
103 std::string
104 ns3::CallbackBase::Demangle (const std::string& mangled)
105 {
106  NS_LOG_FUNCTION (this << mangled);
107  return mangled;
108 }
109 
110 #endif
111 
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
Callback template class.
Definition: callback.h:920
#define NS_ASSERT(condition)
Definition: assert.h:64
Base class for Callback class.
Definition: callback.h:844
virtual ~CallbackValue()
Definition: callback.cc:17
ATTRIBUTE_CHECKER_IMPLEMENT(Callback)
Attribute checker.
CallbackBase m_value
the CallbackBase
Definition: callback.h:1695
NS_LOG_COMPONENT_DEFINE("Callback")
T * PeekPointer(const Ptr< T > &p)
Definition: ptr.h:279
static std::string Demangle(const std::string &mangled)
Definition: callback.cc:104
#define NS_LOG_UNCOND(msg)
Definition: log.h:377
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Deserialize from string (not implemented)
Definition: callback.cc:43
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Serialize to string.
Definition: callback.cc:35
virtual Ptr< AttributeValue > Copy(void) const
Definition: callback.cc:29
void Set(CallbackBase base)
Definition: callback.cc:22
Ptr< CallbackImplBase > GetImpl(void) const
Definition: callback.h:848