A Discrete-Event Network Simulator
API
type-id.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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef TYPE_ID_H
21 #define TYPE_ID_H
22 
23 #include "attribute.h"
25 #include "trace-source-accessor.h"
26 #include "attribute-helper.h"
27 #include "callback.h"
28 #include "deprecated.h"
29 #include "hash.h"
30 #include <string>
31 #include <stdint.h>
32 
39 namespace ns3 {
40 
41 class ObjectBase;
42 
57 class TypeId
58 {
59 public:
64  ATTR_GET = 1<<0,
65  ATTR_SET = 1<<1,
66  ATTR_CONSTRUCT = 1<<2,
68  };
70  std::string name;
71  std::string help;
72  uint32_t flags;
77  };
79  std::string name;
80  std::string help;
81  std::string callback;
83  };
84 
88  typedef uint32_t hash_t;
89 
98  static TypeId LookupByName (std::string name);
105  static bool LookupByNameFailSafe (std::string name, TypeId *tid);
113  static TypeId LookupByHash (hash_t hash);
120  static bool LookupByHashFailSafe (hash_t hash, TypeId *tid);
121 
125  static uint32_t GetRegisteredN (void);
130  static TypeId GetRegistered (uint32_t i);
131 
138  explicit TypeId (const char * name);
139 
149  TypeId GetParent (void) const;
150 
151  bool HasParent (void) const;
152 
162  bool IsChildOf (TypeId other) const;
163 
167  std::string GetGroupName (void) const;
168 
172  std::string GetName (void) const;
173 
177  hash_t GetHash (void) const;
178 
182  std::size_t GetSize (void) const;
183 
187  bool HasConstructor (void) const;
188 
192  uint32_t GetAttributeN (void) const;
198  struct TypeId::AttributeInformation GetAttribute(uint32_t i) const;
204  std::string GetAttributeFullName (uint32_t i) const;
205 
211 
216  bool MustHideFromDocumentation (void) const;
217 
218 
222  uint32_t GetTraceSourceN (void) const;
227  struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const;
228 
236  TypeId SetParent (TypeId tid);
243  template <typename T>
244  TypeId SetParent (void);
245 
254  TypeId SetGroupName (std::string groupName);
255 
270  TypeId SetSize (std::size_t size);
271 
278  template <typename T>
279  TypeId AddConstructor (void);
280 
292  TypeId AddAttribute (std::string name,
293  std::string help,
294  const AttributeValue &initialValue,
297 
303  bool SetAttributeInitialValue(uint32_t i,
304  Ptr<const AttributeValue> initialValue);
305 
318  TypeId AddAttribute (std::string name,
319  std::string help,
320  uint32_t flags,
321  const AttributeValue &initialValue,
324 
335  TypeId AddTraceSource (std::string name,
336  std::string help,
339 
350  TypeId AddTraceSource (std::string name,
351  std::string help,
353  std::string callback);
354 
356 
363  bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
372 
380  uint16_t GetUid (void) const;
389  void SetUid (uint16_t tid);
390 
391  // construct an invalid TypeId.
392  inline TypeId ();
393  inline TypeId (const TypeId &o);
394  inline TypeId &operator = (const TypeId &o);
395  inline ~TypeId ();
396 
397 private:
398  friend class AttributeList;
399  friend bool operator == (TypeId a, TypeId b);
400  friend bool operator != (TypeId a, TypeId b);
401  friend bool operator < (TypeId a, TypeId b);
402 
403 
404  explicit TypeId (uint16_t tid);
406 
407  uint16_t m_tid;
408 };
409 
410 std::ostream & operator << (std::ostream &os, TypeId tid);
411 std::istream & operator >> (std::istream &is, TypeId &tid);
412 inline bool operator == (TypeId a, TypeId b);
413 inline bool operator != (TypeId a, TypeId b);
414 bool operator < (TypeId a, TypeId b);
415 
417 
418 } // namespace ns3
419 
420 namespace ns3 {
421 
423  : m_tid (0) {
424 }
426  : m_tid (o.m_tid) {
427 }
429 {
430  m_tid = o.m_tid;
431  return *this;
432 }
434 {
435 }
436 inline bool operator == (TypeId a, TypeId b)
437 {
438  return a.m_tid == b.m_tid;
439 }
440 
441 inline bool operator != (TypeId a, TypeId b)
442 {
443  return a.m_tid != b.m_tid;
444 }
445 
446 
447 /*************************************************************************
448  * The TypeId implementation which depends on templates
449  *************************************************************************/
450 
451 template <typename T>
452 TypeId
454 {
455  return SetParent (T::GetTypeId ());
456 }
457 
458 template <typename T>
459 TypeId
461 {
462  struct Maker {
463  static ObjectBase * Create () {
464  ObjectBase * base = new T ();
465  return base;
466  }
467  };
469  DoAddConstructor (cb);
470  return *this;
471 }
472 
473 } // namespace ns3
474 
475 #endif /* TYPE_ID_H */
uint32_t GetAttributeN(void) const
Definition: type-id.cc:780
uint32_t hash_t
Type of hash values.
Definition: type-id.h:88
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor) NS_DEPRECATED
Definition: type-id.cc:814
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
TypeId AddConstructor(void)
Definition: type-id.h:460
Callback template class.
Definition: callback.h:984
TypeId SetParent(void)
Definition: type-id.h:453
static TypeId LookupByHash(hash_t hash)
Definition: type-id.cc:583
Hold a value for an Attribute.
Definition: attribute.h:68
Ptr< const AttributeValue > originalInitialValue
Definition: type-id.h:73
Ptr< const TraceSourceAccessor > accessor
Definition: type-id.h:82
TypeId GetParent(void) const
Definition: type-id.cc:659
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Definition: type-id.cc:571
Anchor the ns-3 type and attribute system.
Definition: object-base.h:68
The attribute can be written at construction-time.
Definition: type-id.h:66
Definition of the NS_DEPRECATED macro.
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
The attribute can be read, and written at any time.
Definition: type-id.h:67
Callback< ObjectBase * > GetConstructor(void) const
Definition: type-id.cc:764
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Definition: type-id.cc:591
bool HasConstructor(void) const
Definition: type-id.cc:714
The attribute can be read.
Definition: type-id.h:64
Declaration of the various callback functions.
bool MustHideFromDocumentation(void) const
Definition: type-id.cc:772
Ptr< const AttributeAccessor > accessor
Definition: type-id.h:75
friend bool operator<(TypeId a, TypeId b)
Definition: type-id.cc:895
friend bool operator==(TypeId a, TypeId b)
Definition: type-id.h:436
static uint32_t GetRegisteredN(void)
Definition: type-id.cc:603
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Definition: type-id.cc:842
Ptr< const AttributeValue > initialValue
Definition: type-id.h:74
uint16_t m_tid
Definition: type-id.h:407
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
bool HasParent(void) const
Definition: type-id.cc:666
uint32_t GetTraceSourceN(void) const
Definition: type-id.cc:801
static TypeId GetRegistered(uint32_t i)
Definition: type-id.cc:609
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1296
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:356
TypeId SetGroupName(std::string groupName)
Definition: type-id.cc:645
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker)
Definition: type-id.cc:729
Ptr< const AttributeChecker > checker
Definition: type-id.h:76
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1278
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetUid(uint16_t tid)
Definition: type-id.cc:869
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Definition: type-id.cc:616
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
The attribute can be written.
Definition: type-id.h:65
AttributeFlag
Flags describing when a given attribute can be read or written.
Definition: type-id.h:63
Ptr< T > Create(void)
Create class instances by constructors with varying numbers of arguments and return them by Ptr...
Definition: ptr.h:514
std::string GetName(void) const
Definition: type-id.cc:692
friend class AttributeList
Definition: type-id.h:398
uint16_t GetUid(void) const
Definition: type-id.cc:863
void DoAddConstructor(Callback< ObjectBase * > callback)
Definition: type-id.cc:722
hash_t GetHash(void) const
Definition: type-id.cc:700
Declaration of Attribute helper macros.
bool SetAttributeInitialValue(uint32_t i, Ptr< const AttributeValue > initialValue)
Definition: type-id.cc:754
#define NS_DEPRECATED
Mark a function as deprecated.
Definition: deprecated.h:23
TypeId & operator=(const TypeId &o)
Definition: type-id.h:428
friend bool operator!=(TypeId a, TypeId b)
Definition: type-id.h:441
std::size_t GetSize(void) const
Definition: type-id.cc:706
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:95
TypeId SetSize(std::size_t size)
Set the size of this type, based on the sizeof operator.
Definition: type-id.cc:652
ns3::MakeAccessorHelper declarations and template implementations.
std::string GetAttributeFullName(uint32_t i) const
Definition: type-id.cc:793
bool IsChildOf(TypeId other) const
Definition: type-id.cc:673
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
Definition: type-id.cc:807
std::string GetGroupName(void) const
Definition: type-id.cc:684
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Definition: type-id.cc:787
a unique identifier for an interface.
Definition: type-id.h:57
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type.
TypeId HideFromDocumentation(void)
Definition: type-id.cc:833
static TypeId LookupByName(std::string name)
Definition: type-id.cc:563