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 
67 #define NS_OBJECT_TEMPLATE_CLASS_DEFINE(type,param) \
68  template class type<param>; \
69  template <> std::string DoGetTypeParamName<type<param> > () \
70  { \
71  return #param; \
72  } \
73  static struct Object ## type ## param ## RegistrationClass \
74  { \
75  Object ## type ## param ## RegistrationClass () { \
76  ns3::TypeId tid = type<param>::GetTypeId (); \
77  tid.SetSize (sizeof (type<param>)); \
78  tid.GetParent (); \
79  } \
80  } Object ## type ## param ## RegistrationVariable
81 
82 
83 namespace ns3 {
84 
93 template <typename T>
94 std::string DoGetTypeParamName (void);
95 
101 template <typename T>
102 std::string GetTypeParamName (void)
103 {
104  return DoGetTypeParamName<T> ();
105 }
106 
107 class AttributeConstructionList;
108 
120 {
121 public:
126  static TypeId GetTypeId (void);
127 
131  virtual ~ObjectBase ();
132 
143  virtual TypeId GetInstanceTypeId (void) const = 0;
144 
159  void SetAttribute (std::string name, const AttributeValue &value);
171  bool SetAttributeFailSafe (std::string name, const AttributeValue &value);
186  void GetAttribute (std::string name, AttributeValue &value) const;
197  bool GetAttributeFailSafe (std::string name, AttributeValue &value) const;
198 
209  bool TraceConnect (std::string name, std::string context, const CallbackBase &cb);
219  bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb);
231  bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb);
242  bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb);
243 
244 protected:
253  virtual void NotifyConstructionCompleted (void);
267  void ConstructSelf (const AttributeConstructionList &attributes);
268 
269 private:
282  const AttributeValue &value);
283 
284 };
285 
286 } // namespace ns3
287 
288 #endif /* OBJECT_BASE_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual ~ObjectBase()
Virtual destructor.
Definition: object-base.cc:68
Hold a value for an Attribute.
Definition: attribute.h:68
Base class for Callback class.
Definition: callback.h:1104
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
Definition: object-base.cc:205
static TypeId GetTypeId(void)
Get the type ID.
Definition: object-base.cc:61
Anchor the ns-3 type and attribute system.
Definition: object-base.h:119
bool GetAttributeFailSafe(std::string name, AttributeValue &value) const
Get the value of an attribute without raising erros.
Definition: object-base.cc:258
std::string DoGetTypeParamName(void)
Helper function to get the name (as a string) of the type parameter of a template class...
Declaration of the various callback functions.
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:332
List of Attribute name, value and checker triples used to construct Objects.
virtual void NotifyConstructionCompleted(void)
Notifier called once the ObjectBase is fully constructed.
Definition: object-base.cc:74
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:319
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TypeId declaration; inline and template implementations.
void ConstructSelf(const AttributeConstructionList &attributes)
Complete construction of ObjectBase; invoked by derived classes.
Definition: object-base.cc:80
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:170
virtual TypeId GetInstanceTypeId(void) const =0
Get the most derived TypeId for this Object.
bool TraceConnect(std::string name, std::string context, const CallbackBase &cb)
Connect a TraceSource to a Callback with a context.
Definition: object-base.cc:306
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
a unique identifier for an interface.
Definition: type-id.h:58
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:223
std::string GetTypeParamName(void)
Helper function to get the name (as a string) of the type parameter of a template class...
Definition: object-base.h:102