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
30namespace ns3 {
31
32NS_LOG_COMPONENT_DEFINE ("Callback");
33
35 : m_value ()
36{
37 NS_LOG_FUNCTION (this);
38}
40 : m_value (base)
41{}
43{
44 NS_LOG_FUNCTION (this);
45}
46void
48{
49 NS_LOG_FUNCTION (&base);
50
51 m_value = base;
52}
55{
56 NS_LOG_FUNCTION (this);
57 return Create<CallbackValue> (m_value);
58}
59std::string
61{
62 NS_LOG_FUNCTION (this << checker);
63 std::ostringstream oss;
64 oss << PeekPointer (m_value.GetImpl ());
65 return oss.str ();
66}
67bool
69{
70 NS_LOG_FUNCTION (this << value << checker);
71 return false;
72}
73
75
76} // namespace ns3
77
78#if (__GNUC__ >= 3)
79
80#include <cstdlib>
81#include <cxxabi.h>
82#include "log.h"
83
84namespace ns3 {
85
86std::string
87CallbackImplBase::Demangle (const std::string& mangled)
88{
89 NS_LOG_FUNCTION (mangled);
90
91 int status;
92 char* demangled = abi::__cxa_demangle (mangled.c_str (),
93 NULL, NULL, &status);
94
95 std::string ret;
96 if (status == 0)
97 {
98 NS_ASSERT (demangled);
99 ret = demangled;
100 }
101 else if (status == -1)
102 {
103 NS_LOG_UNCOND ("Callback demangling failed: Memory allocation failure occurred.");
104 ret = mangled;
105 }
106 else if (status == -2)
107 {
108 NS_LOG_UNCOND ("Callback demangling failed: Mangled name is not a valid under the C++ ABI mangling rules.");
109 ret = mangled;
110 }
111 else if (status == -3)
112 {
113 NS_LOG_UNCOND ("Callback demangling failed: One of the arguments is invalid.");
114 ret = mangled;
115 }
116 else
117 {
118 NS_LOG_UNCOND ("Callback demangling failed: status " << status);
119 ret = mangled;
120 }
121
122 if (demangled)
123 {
124 std::free (demangled);
125 }
126 return ret;
127}
128
129} // namespace ns3
130
131#else
132
133std::string
134ns3::CallbackImplBase::Demangle (const std::string& mangled)
135{
136 NS_LOG_FUNCTION (this << mangled);
137 return mangled;
138}
139
140#endif
141
Declaration of the various callback functions.
Base class for Callback class.
Definition: callback.h:1196
Ptr< CallbackImplBase > GetImpl(void) const
Definition: callback.h:1201
Callback template class.
Definition: callback.h:1279
static std::string Demangle(const std::string &mangled)
Definition: callback.cc:134
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Serialize to string.
Definition: callback.cc:60
void Set(CallbackBase base)
Definition: callback.cc:47
CallbackValue()
Constructor.
Definition: callback.cc:34
virtual Ptr< AttributeValue > Copy(void) const
Definition: callback.cc:54
virtual ~CallbackValue()
Destructor.
Definition: callback.cc:42
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Deserialize from string (not implemented)
Definition: callback.cc:68
CallbackBase m_value
The stored Callback instance.
Definition: callback.h:1979
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
#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
#define ATTRIBUTE_CHECKER_IMPLEMENT(type)
Define the MaketypeChecker function for class type.
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:415