A Discrete-Event Network Simulator
API
object-base.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2008 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 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
20#ifndef OBJECT_BASE_H
21#define OBJECT_BASE_H
22
23#include "type-id.h"
24#include "callback.h"
25#include <string>
26#include <list>
27
45#define NS_OBJECT_ENSURE_REGISTERED(type) \
46 static struct Object ## type ## RegistrationClass \
47 { \
48 Object ## type ## RegistrationClass () { \
49 ns3::TypeId tid = type::GetTypeId (); \
50 tid.SetSize (sizeof (type)); \
51 tid.GetParent (); \
52 } \
53 } Object ## type ## RegistrationVariable
54
55
75#define NS_OBJECT_TEMPLATE_CLASS_DEFINE(type,param) \
76 template class type<param>; \
77 template <> std::string DoGetTemplateClassName<type<param> > () \
78 { \
79 return std::string ("ns3::") + std::string (#type) \
80 + std::string ("<") + std::string (#param) + std::string (">"); \
81 } \
82 static struct Object ## type ## param ## RegistrationClass \
83 { \
84 Object ## type ## param ## RegistrationClass () { \
85 ns3::TypeId tid = type<param>::GetTypeId (); \
86 tid.SetSize (sizeof (type<param>)); \
87 tid.GetParent (); \
88 } \
89 } Object ## type ## param ## RegistrationVariable
90
91
112#define NS_OBJECT_TEMPLATE_CLASS_TWO_DEFINE(type,param1,param2) \
113 template class type<param1,param2>; \
114 template <> std::string DoGetTemplateClassName<type<param1,param2> > () \
115 { \
116 return std::string ("ns3::") + std::string (#type) \
117 + std::string ("<") + std::string (#param1) + std::string (",") \
118 + std::string (#param2) + std::string (">"); \
119 } \
120 static struct Object ## type ## param1 ## param2 ## RegistrationClass \
121 { \
122 Object ## type ## param1 ## param2 ## RegistrationClass () { \
123 ns3::TypeId tid = type<param1,param2>::GetTypeId (); \
124 tid.SetSize (sizeof (type<param1,param2>)); \
125 tid.GetParent (); \
126 } \
127 } Object ## type ## param1 ## param2 ## RegistrationVariable
128
129
130namespace ns3 {
131
140template <typename T>
141std::string DoGetTemplateClassName (void);
142
148template <typename T>
149std::string GetTemplateClassName (void)
150{
151 return DoGetTemplateClassName<T> ();
152}
153
154class AttributeConstructionList;
155
167{
168public:
173 static TypeId GetTypeId (void);
174
178 virtual ~ObjectBase ();
179
190 virtual TypeId GetInstanceTypeId (void) const = 0;
191
206 void SetAttribute (std::string name, const AttributeValue &value);
218 bool SetAttributeFailSafe (std::string name, const AttributeValue &value);
233 void GetAttribute (std::string name, AttributeValue &value) const;
244 bool GetAttributeFailSafe (std::string name, AttributeValue &value) const;
245
256 bool TraceConnect (std::string name, std::string context, const CallbackBase &cb);
266 bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb);
278 bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb);
289 bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb);
290
291protected:
300 virtual void NotifyConstructionCompleted (void);
314 void ConstructSelf (const AttributeConstructionList &attributes);
315
316private:
329 const AttributeValue &value);
330
331};
332
333} // namespace ns3
334
335#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:69
Base class for Callback class.
Definition: callback.h:351
Anchor the ns-3 type and attribute system.
Definition: object-base.h:167
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
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:403
static TypeId GetTypeId(void)
Get the type ID.
Definition: object-base.cc:120
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:390
void ConstructSelf(const AttributeConstructionList &attributes)
Complete construction of ObjectBase; invoked by derived classes.
Definition: object-base.cc:159
virtual ~ObjectBase()
Virtual destructor.
Definition: object-base.cc:127
bool GetAttributeFailSafe(std::string name, AttributeValue &value) const
Get the value of an attribute without raising erros.
Definition: object-base.cc:329
virtual void NotifyConstructionCompleted(void)
Notifier called once the ObjectBase is fully constructed.
Definition: object-base.cc:133
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
Definition: object-base.cc:276
virtual TypeId GetInstanceTypeId(void) const =0
Get the most derived TypeId for this Object.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:294
bool TraceConnect(std::string name, std::string context, const CallbackBase &cb)
Connect a TraceSource to a Callback with a context.
Definition: object-base.cc:377
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:241
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 GetTemplateClassName(void)
Helper function to get the name (as a string) of the type of a template class.
Definition: object-base.h:149
std::string DoGetTemplateClassName(void)
Helper function to get the name (as a string) of the type of a template class.
ns3::TypeId declaration; inline and template implementations.