A Discrete-Event Network Simulator
API
object-base.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef OBJECT_BASE_H
20#define OBJECT_BASE_H
21
22#include "callback.h"
23#include "type-id.h"
24
25#include <list>
26#include <string>
27
45#define NS_OBJECT_ENSURE_REGISTERED(type) \
46 static struct Object##type##RegistrationClass \
47 { \
48 Object##type##RegistrationClass() \
49 { \
50 ns3::TypeId tid = type::GetTypeId(); \
51 tid.SetSize(sizeof(type)); \
52 tid.GetParent(); \
53 } \
54 } Object##type##RegistrationVariable
55
75#define NS_OBJECT_TEMPLATE_CLASS_DEFINE(type, param) \
76 template class type<param>; \
77 template <> \
78 std::string DoGetTemplateClassName<type<param>>() \
79 { \
80 return std::string("ns3::") + std::string(#type) + std::string("<") + \
81 std::string(#param) + std::string(">"); \
82 } \
83 static struct Object##type##param##RegistrationClass \
84 { \
85 Object##type##param##RegistrationClass() \
86 { \
87 ns3::TypeId tid = type<param>::GetTypeId(); \
88 tid.SetSize(sizeof(type<param>)); \
89 tid.GetParent(); \
90 } \
91 } Object##type##param##RegistrationVariable
92
113#define NS_OBJECT_TEMPLATE_CLASS_TWO_DEFINE(type, param1, param2) \
114 template class type<param1, param2>; \
115 template <> \
116 std::string DoGetTemplateClassName<type<param1, param2>>() \
117 { \
118 return std::string("ns3::") + std::string(#type) + std::string("<") + \
119 std::string(#param1) + std::string(",") + std::string(#param2) + std::string(">"); \
120 } \
121 static struct Object##type##param1##param2##RegistrationClass \
122 { \
123 Object##type##param1##param2##RegistrationClass() \
124 { \
125 ns3::TypeId tid = type<param1, param2>::GetTypeId(); \
126 tid.SetSize(sizeof(type<param1, param2>)); \
127 tid.GetParent(); \
128 } \
129 } Object##type##param1##param2##RegistrationVariable
130
131namespace ns3
132{
133
142template <typename T>
144
150template <typename T>
151std::string
153{
154 return DoGetTemplateClassName<T>();
155}
156
157class AttributeConstructionList;
158
170{
171 public:
176 static TypeId GetTypeId();
177
181 virtual ~ObjectBase();
182
193 virtual TypeId GetInstanceTypeId() const = 0;
194
209 void SetAttribute(std::string name, const AttributeValue& value);
221 bool SetAttributeFailSafe(std::string name, const AttributeValue& value);
236 void GetAttribute(std::string name, AttributeValue& value) const;
247 bool GetAttributeFailSafe(std::string name, AttributeValue& value) const;
248
259 bool TraceConnect(std::string name, std::string context, const CallbackBase& cb);
269 bool TraceConnectWithoutContext(std::string name, const CallbackBase& cb);
281 bool TraceDisconnect(std::string name, std::string context, const CallbackBase& cb);
292 bool TraceDisconnectWithoutContext(std::string name, const CallbackBase& cb);
293
294 protected:
303 virtual void NotifyConstructionCompleted();
317 void ConstructSelf(const AttributeConstructionList& attributes);
318
319 private:
332 const AttributeValue& value);
333};
334
335} // namespace ns3
336
337#endif /* OBJECT_BASE_H */
Declaration of the various callback functions.
List of Attribute name, value and checker triples used to construct Objects.
Hold a value for an Attribute.
Definition: attribute.h:70
Base class for Callback class.
Definition: callback.h:365
Anchor the ns-3 type and attribute system.
Definition: object-base.h:170
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:369
bool TraceDisconnect(std::string name, std::string context, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected with a context.
Definition: object-base.cc:411
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:397
virtual TypeId GetInstanceTypeId() const =0
Get the most derived TypeId for this Object.
void ConstructSelf(const AttributeConstructionList &attributes)
Complete construction of ObjectBase; invoked by derived classes.
Definition: object-base.cc:162
virtual ~ObjectBase()
Virtual destructor.
Definition: object-base.cc:129
bool GetAttributeFailSafe(std::string name, AttributeValue &value) const
Get the value of an attribute without raising erros.
Definition: object-base.cc:335
virtual void NotifyConstructionCompleted()
Notifier called once the ObjectBase is fully constructed.
Definition: object-base.cc:135
static TypeId GetTypeId()
Get the type ID.
Definition: object-base.cc:122
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
Definition: object-base.cc:281
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:258
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:298
bool TraceConnect(std::string name, std::string context, const CallbackBase &cb)
Connect a TraceSource to a Callback with a context.
Definition: object-base.cc:383
bool DoSet(Ptr< const AttributeAccessor > spec, Ptr< const AttributeChecker > checker, const AttributeValue &value)
Attempt to set the value referenced by the accessor spec to a valid value according to the checker,...
Definition: object-base.cc:243
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:60
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string DoGetTemplateClassName()
Helper function to get the name (as a string) of the type of a template class.
std::string GetTemplateClassName()
Helper function to get the name (as a string) of the type of a template class.
Definition: object-base.h:152
value
Definition: second.py:41
ns3::TypeId declaration; inline and template implementations.