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 
44 #define NS_OBJECT_ENSURE_REGISTERED(type) \
45  static struct Object ## type ## RegistrationClass \
46  { \
47  Object ## type ## RegistrationClass () { \
48  ns3::TypeId tid = type::GetTypeId (); \
49  tid.SetSize (sizeof (type)); \
50  tid.GetParent (); \
51  } \
52  } Object ## type ## RegistrationVariable
53 
54 namespace ns3 {
55 
56 class AttributeConstructionList;
57 
69 {
70 public:
74  static TypeId GetTypeId (void);
75 
79  virtual ~ObjectBase ();
80 
91  virtual TypeId GetInstanceTypeId (void) const = 0;
92 
107  void SetAttribute (std::string name, const AttributeValue &value);
119  bool SetAttributeFailSafe (std::string name, const AttributeValue &value);
134  void GetAttribute (std::string name, AttributeValue &value) const;
145  bool GetAttributeFailSafe (std::string name, AttributeValue &value) const;
146 
157  bool TraceConnect (std::string name, std::string context, const CallbackBase &cb);
167  bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb);
179  bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb);
190  bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb);
191 
192 protected:
201  virtual void NotifyConstructionCompleted (void);
215  void ConstructSelf (const AttributeConstructionList &attributes);
216 
217 private:
230  const AttributeValue &value);
231 
232 };
233 
234 } // namespace ns3
235 
236 #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:211
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:68
bool GetAttributeFailSafe(std::string name, AttributeValue &value) const
Get the value of an attribute without raising erros.
Definition: object-base.cc:264
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:338
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:325
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:299
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
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:229
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:176
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:312
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
a unique identifier for an interface.
Definition: type-id.h:58