A Discrete-Event Network Simulator
API
callback.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "callback.h"
22 #include "log.h"
23 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("Callback");
33 
35  : m_value ()
36 {
37  NS_LOG_FUNCTION (this);
38 }
40  : m_value (base)
41 {
42 }
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 void
49 {
50  NS_LOG_FUNCTION (&base);
51 
52  m_value = base;
53 }
55 CallbackValue::Copy (void) const
56 {
57  NS_LOG_FUNCTION (this);
58  return Create<CallbackValue> (m_value);
59 }
60 std::string
62 {
63  NS_LOG_FUNCTION (this << checker);
64  std::ostringstream oss;
65  oss << PeekPointer (m_value.GetImpl ());
66  return oss.str ();
67 }
68 bool
70 {
71  NS_LOG_FUNCTION (this << value << checker);
72  return false;
73 }
74 
76 
77 } // namespace ns3
78 
79 #if (__GNUC__ >= 3)
80 
81 #include <cstdlib>
82 #include <cxxabi.h>
83 #include "log.h"
84 
85 namespace ns3 {
86 
87 std::string
88 CallbackImplBase::Demangle (const std::string& mangled)
89 {
90  NS_LOG_FUNCTION (mangled);
91 
92  int status;
93  char* demangled = abi::__cxa_demangle (mangled.c_str (),
94  NULL, NULL, &status);
95 
96  std::string ret;
97  if (status == 0) {
98  NS_ASSERT (demangled);
99  ret = demangled;
100  }
101  else if (status == -1) {
102  NS_LOG_UNCOND ("Callback demangling failed: Memory allocation failure occurred.");
103  ret = mangled;
104  }
105  else if (status == -2) {
106  NS_LOG_UNCOND ("Callback demangling failed: Mangled name is not a valid under the C++ ABI mangling rules.");
107  ret = mangled;
108  }
109  else if (status == -3) {
110  NS_LOG_UNCOND ("Callback demangling failed: One of the arguments is invalid.");
111  ret = mangled;
112  }
113  else {
114  NS_LOG_UNCOND ("Callback demangling failed: status " << status);
115  ret = mangled;
116  }
117 
118  if (demangled) {
119  std::free (demangled);
120  }
121  return ret;
122 }
123 
124 } // namespace ns3
125 
126 #else
127 
128 std::string
129 ns3::CallbackImplBase::Demangle (const std::string& mangled)
130 {
131  NS_LOG_FUNCTION (this << mangled);
132  return mangled;
133 }
134 
135 #endif
136 
CallbackValue()
Constructor.
Definition: callback.cc:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Callback template class.
Definition: callback.h:1176
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Serialize to string.
Definition: callback.cc:61
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:564
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Base class for Callback class.
Definition: callback.h:1104
virtual ~CallbackValue()
Destructor.
Definition: callback.cc:43
CallbackBase m_value
the CallbackBase
Definition: callback.h:1919
Declaration of the various callback functions.
virtual Ptr< AttributeValue > Copy(void) const
Definition: callback.cc:55
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#define ATTRIBUTE_CHECKER_IMPLEMENT(type)
Define the MaketypeChecker function for class type.
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Deserialize from string (not implemented)
Definition: callback.cc:69
Ptr< CallbackImplBase > GetImpl(void) const
Definition: callback.h:1108
Debug message logging.
static std::string Demangle(const std::string &mangled)
Definition: callback.cc:129
void Set(CallbackBase base)
Definition: callback.cc:48