A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
type-id.h
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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef TYPE_ID_H
21 #define TYPE_ID_H
22 
23 #include "attribute.h"
24 #include "attribute-accessor-helper.h"
25 #include "trace-source-accessor.h"
26 #include "attribute-helper.h"
27 #include "callback.h"
28 #include <string>
29 #include <stdint.h>
30 
31 namespace ns3 {
32 
33 class ObjectBase;
34 
44 class TypeId
45 {
46 public:
51  ATTR_GET = 1<<0,
52  ATTR_SET = 1<<1,
53  ATTR_CONSTRUCT = 1<<2,
55  };
57  std::string name;
58  std::string help;
59  uint32_t flags;
60  ns3::Ptr<const ns3::AttributeValue> originalInitialValue;
64  };
66  std::string name;
67  std::string help;
69  };
70 
79  static TypeId LookupByName (std::string name);
86  static bool LookupByNameFailSafe (std::string name, TypeId *tid);
87 
91  static uint32_t GetRegisteredN (void);
96  static TypeId GetRegistered (uint32_t i);
97 
104  explicit TypeId (const char * name);
105 
115  TypeId GetParent (void) const;
116 
117  bool HasParent (void) const;
118 
128  bool IsChildOf (TypeId other) const;
129 
133  std::string GetGroupName (void) const;
134 
138  std::string GetName (void) const;
139 
143  bool HasConstructor (void) const;
144 
148  uint32_t GetAttributeN (void) const;
154  struct TypeId::AttributeInformation GetAttribute(uint32_t i) const;
160  std::string GetAttributeFullName (uint32_t i) const;
161 
167 
172  bool MustHideFromDocumentation (void) const;
173 
174 
178  uint32_t GetTraceSourceN (void) const;
183  struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const;
184 
192  TypeId SetParent (TypeId tid);
199  template <typename T>
200  TypeId SetParent (void);
201 
210  TypeId SetGroupName (std::string groupName);
211 
218  template <typename T>
219  TypeId AddConstructor (void);
220 
232  TypeId AddAttribute (std::string name,
233  std::string help,
234  const AttributeValue &initialValue,
237 
243  bool SetAttributeInitialValue(uint32_t i,
244  Ptr<const AttributeValue> initialValue);
245 
258  TypeId AddAttribute (std::string name,
259  std::string help,
260  uint32_t flags,
261  const AttributeValue &initialValue,
264 
273  TypeId AddTraceSource (std::string name,
274  std::string help,
276 
277  TypeId HideFromDocumentation (void);
278 
285  bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
294 
302  uint16_t GetUid (void) const;
311  void SetUid (uint16_t tid);
312 
313  // construct an invalid TypeId.
314  inline TypeId ();
315  inline TypeId (const TypeId &o);
316  inline TypeId &operator = (const TypeId &o);
317  inline ~TypeId ();
318 
319 private:
320  friend class AttributeList;
321  friend bool operator == (TypeId a, TypeId b);
322  friend bool operator != (TypeId a, TypeId b);
323  friend bool operator < (TypeId a, TypeId b);
324 
325 
326  explicit TypeId (uint16_t tid);
327  void DoAddConstructor (Callback<ObjectBase *> callback);
328 
329  uint16_t m_tid;
330 };
331 
332 std::ostream & operator << (std::ostream &os, TypeId tid);
333 std::istream & operator >> (std::istream &is, TypeId &tid);
334 inline bool operator == (TypeId a, TypeId b);
335 inline bool operator != (TypeId a, TypeId b);
336 bool operator < (TypeId a, TypeId b);
337 
345 
346 } // namespace ns3
347 
348 namespace ns3 {
349 
350 TypeId::TypeId ()
351  : m_tid (0) {
352 }
353 TypeId::TypeId (const TypeId &o)
354  : m_tid (o.m_tid) {
355 }
356 TypeId &TypeId::operator = (const TypeId &o)
357 {
358  m_tid = o.m_tid;
359  return *this;
360 }
361 TypeId::~TypeId ()
362 {
363 }
364 inline bool operator == (TypeId a, TypeId b)
365 {
366  return a.m_tid == b.m_tid;
367 }
368 
369 inline bool operator != (TypeId a, TypeId b)
370 {
371  return a.m_tid != b.m_tid;
372 }
373 
374 
375 /*************************************************************************
376  * The TypeId implementation which depends on templates
377  *************************************************************************/
378 
379 template <typename T>
380 TypeId
382 {
383  return SetParent (T::GetTypeId ());
384 }
385 
386 template <typename T>
387 TypeId
389 {
390  struct Maker {
391  static ObjectBase * Create () {
392  ObjectBase * base = new T ();
393  return base;
394  }
395  };
396  Callback<ObjectBase *> cb = MakeCallback (&Maker::Create);
397  DoAddConstructor (cb);
398  return *this;
399 }
400 
401 } // namespace ns3
402 
403 #endif /* TYPE_ID_H */
uint32_t GetAttributeN(void) const
Definition: type-id.cc:592
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:49
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
TypeId AddConstructor(void)
Definition: type-id.h:388
Callback template class.
Definition: callback.h:369
TypeId SetParent(void)
Definition: type-id.h:381
Hold a value for an Attribute.
Definition: attribute.h:51
TypeId(const char *name)
Definition: type-id.cc:400
TypeId GetParent(void) const
Definition: type-id.cc:485
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Definition: type-id.cc:423
implement the ns-3 type and attribute system
Definition: object-base.h:55
Callback< ObjectBase * > GetConstructor(void) const
Definition: type-id.cc:576
bool HasConstructor(void) const
Definition: type-id.cc:526
bool MustHideFromDocumentation(void) const
Definition: type-id.cc:584
static uint32_t GetRegisteredN(void)
Definition: type-id.cc:436
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Definition: type-id.cc:645
uint32_t GetTraceSourceN(void) const
Definition: type-id.cc:613
static TypeId GetRegistered(uint32_t i)
Definition: type-id.cc:442
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:502
TypeId SetGroupName(std::string groupName)
Definition: type-id.cc:478
#define ATTRIBUTE_HELPER_HEADER(type)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker)
Definition: type-id.cc:541
void SetUid(uint16_t tid)
Definition: type-id.cc:672
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Definition: type-id.cc:449
std::string GetName(void) const
Definition: type-id.cc:518
uint16_t GetUid(void) const
Definition: type-id.cc:666
bool SetAttributeInitialValue(uint32_t i, Ptr< const AttributeValue > initialValue)
Definition: type-id.cc:566
TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor)
Definition: type-id.cc:626
std::string GetAttributeFullName(uint32_t i) const
Definition: type-id.cc:605
bool IsChildOf(TypeId other) const
Definition: type-id.cc:499
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
Definition: type-id.cc:619
std::string GetGroupName(void) const
Definition: type-id.cc:510
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Definition: type-id.cc:599
a unique identifier for an interface.
Definition: type-id.h:44
static TypeId LookupByName(std::string name)
Definition: type-id.cc:415