A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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#include "warnings.h"
25
26#include <list>
27#include <string>
28
46#define NS_OBJECT_ENSURE_REGISTERED(type) \
47 static struct Object##type##RegistrationClass \
48 { \
49 Object##type##RegistrationClass() \
50 { \
51 NS_WARNING_PUSH_DEPRECATED; \
52 ns3::TypeId tid = type::GetTypeId(); \
53 tid.SetSize(sizeof(type)); \
54 tid.GetParent(); \
55 NS_WARNING_POP; \
56 } \
57 } Object##type##RegistrationVariable
58
78#define NS_OBJECT_TEMPLATE_CLASS_DEFINE(type, param) \
79 template class type<param>; \
80 template <> \
81 std::string DoGetTemplateClassName<type<param>>() \
82 { \
83 return std::string("ns3::") + std::string(#type) + std::string("<") + \
84 std::string(#param) + std::string(">"); \
85 } \
86 static struct Object##type##param##RegistrationClass \
87 { \
88 Object##type##param##RegistrationClass() \
89 { \
90 ns3::TypeId tid = type<param>::GetTypeId(); \
91 tid.SetSize(sizeof(type<param>)); \
92 tid.GetParent(); \
93 } \
94 } Object##type##param##RegistrationVariable
95
116#define NS_OBJECT_TEMPLATE_CLASS_TWO_DEFINE(type, param1, param2) \
117 template class type<param1, param2>; \
118 template <> \
119 std::string DoGetTemplateClassName<type<param1, param2>>() \
120 { \
121 return std::string("ns3::") + std::string(#type) + std::string("<") + \
122 std::string(#param1) + std::string(",") + std::string(#param2) + std::string(">"); \
123 } \
124 static struct Object##type##param1##param2##RegistrationClass \
125 { \
126 Object##type##param1##param2##RegistrationClass() \
127 { \
128 ns3::TypeId tid = type<param1, param2>::GetTypeId(); \
129 tid.SetSize(sizeof(type<param1, param2>)); \
130 tid.GetParent(); \
131 } \
132 } Object##type##param1##param2##RegistrationVariable
133
134namespace ns3
135{
136
145template <typename T>
147
153template <typename T>
154std::string
156{
157 return DoGetTemplateClassName<T>();
158}
159
160class AttributeConstructionList;
161
173{
174 public:
179 static TypeId GetTypeId();
180
184 virtual ~ObjectBase();
185
196 virtual TypeId GetInstanceTypeId() const = 0;
197
212 void SetAttribute(std::string name, const AttributeValue& value);
224 bool SetAttributeFailSafe(std::string name, const AttributeValue& value);
239 void GetAttribute(std::string name, AttributeValue& value) const;
250 bool GetAttributeFailSafe(std::string name, AttributeValue& value) const;
251
262 bool TraceConnect(std::string name, std::string context, const CallbackBase& cb);
272 bool TraceConnectWithoutContext(std::string name, const CallbackBase& cb);
284 bool TraceDisconnect(std::string name, std::string context, const CallbackBase& cb);
295 bool TraceDisconnectWithoutContext(std::string name, const CallbackBase& cb);
296
297 protected:
306 virtual void NotifyConstructionCompleted();
320 void ConstructSelf(const AttributeConstructionList& attributes);
321
322 private:
335 const AttributeValue& value);
336};
337
338// The following explicit template instantiation declarations prevent all the translation
339// units including this header file to implicitly instantiate the callbacks class and
340// function templates having ObjectBase as template type parameter that are required to be
341// instantiated more often (accorging to the ClangBuildAnalyzer tool).
342// These classes and functions are explicitly instantiated in object-base.cc
344extern template Callback<ObjectBase*>::Callback();
345extern template class CallbackImpl<ObjectBase*>;
346
347} // namespace ns3
348
349#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:360
Callback template class.
Definition: callback.h:438
friend class Callback
Definition: callback.h:440
CallbackImpl class with varying numbers of argument types.
Definition: callback.h:242
Anchor the ns-3 type and attribute system.
Definition: object-base.h:173
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:315
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:357
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:343
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:85
virtual ~ObjectBase()
Virtual destructor.
Definition: object-base.cc:73
bool GetAttributeFailSafe(std::string name, AttributeValue &value) const
Get the value of an attribute without raising errors.
Definition: object-base.cc:281
virtual void NotifyConstructionCompleted()
Notifier called once the ObjectBase is fully constructed.
Definition: object-base.cc:79
static TypeId GetTypeId()
Get the type ID.
Definition: object-base.cc:66
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
Definition: object-base.cc:227
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:204
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:244
bool TraceConnect(std::string name, std::string context, const CallbackBase &cb)
Connect a TraceSource to a Callback with a context.
Definition: object-base.cc:329
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:189
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:59
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:155
template Callback< ObjectBase * > MakeCallback< ObjectBase * >(ObjectBase *(*)())
ns3::TypeId declaration; inline and template implementations.