A Discrete-Event Network Simulator
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
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
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>
39 namespace ns3 {
41 class ObjectBase;
58 class TypeId
59 {
60 public:
63  ATTR_GET = 1<<0,
64  ATTR_SET = 1<<1,
65  ATTR_CONSTRUCT = 1<<2,
67  };
70  {
74  };
78  std::string name;
80  std::string help;
82  uint32_t flags;
94  std::string supportMsg;
95  };
99  std::string name;
101  std::string help;
103  std::string callback;
109  std::string supportMsg;
110  };
113  typedef uint32_t hash_t;
124  static TypeId LookupByName (std::string name);
133  static bool LookupByNameFailSafe (std::string name, TypeId *tid);
143  static TypeId LookupByHash (hash_t hash);
152  static bool LookupByHashFailSafe (hash_t hash, TypeId *tid);
159  static uint32_t GetRegisteredN (void);
166  static TypeId GetRegistered (uint32_t i);
176  explicit TypeId (const char * name);
189  TypeId GetParent (void) const;
196  bool HasParent (void) const;
208  bool IsChildOf (TypeId other) const;
215  std::string GetGroupName (void) const;
222  std::string GetName (void) const;
229  hash_t GetHash (void) const;
236  std::size_t GetSize (void) const;
243  bool HasConstructor (void) const;
250  uint32_t GetAttributeN (void) const;
257  struct TypeId::AttributeInformation GetAttribute(uint32_t i) const;
264  std::string GetAttributeFullName (uint32_t i) const;
279  bool MustHideFromDocumentation (void) const;
287  uint32_t GetTraceSourceN (void) const;
294  struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const;
305  TypeId SetParent (TypeId tid);
315  template <typename T>
316  TypeId SetParent (void);
328  TypeId SetGroupName (std::string groupName);
344  TypeId SetSize (std::size_t size);
353  template <typename T>
354  TypeId AddConstructor (void);
378  TypeId AddAttribute (std::string name,
379  std::string help,
380  const AttributeValue &initialValue,
383  SupportLevel supportLevel = SUPPORTED,
384  const std::string &supportMsg = "");
393  bool SetAttributeInitialValue(uint32_t i,
394  Ptr<const AttributeValue> initialValue);
418  TypeId AddAttribute (std::string name,
419  std::string help,
420  uint32_t flags,
421  const AttributeValue &initialValue,
424  SupportLevel supportLevel = SUPPORTED,
425  const std::string &supportMsg = "");
439  TypeId AddTraceSource (std::string name,
440  std::string help,
465  TypeId AddTraceSource (std::string name,
466  std::string help,
468  std::string callback,
469  SupportLevel supportLevel = SUPPORTED,
470  const std::string &supportMsg = "");
487  bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
520  uint16_t GetUid (void) const;
533  void SetUid (uint16_t uid);
536  inline TypeId ();
541  inline TypeId (const TypeId &o);
547  inline TypeId &operator = (const TypeId &o);
549  inline ~TypeId ();
551 private:
557  friend inline bool operator == (TypeId a, TypeId b);
558  friend inline bool operator != (TypeId a, TypeId b);
559  friend bool operator < (TypeId a, TypeId b);
566  explicit TypeId (uint16_t tid);
575  uint16_t m_tid;
576 };
586 std::ostream & operator << (std::ostream &os, TypeId tid);
594 std::istream & operator >> (std::istream &is, TypeId &tid);
603 inline bool operator == (TypeId a, TypeId b);
604 inline bool operator != (TypeId a, TypeId b);
605 bool operator < (TypeId a, TypeId b);
610 } // namespace ns3
612 namespace ns3 {
615  : m_tid (0) {
616 }
618  : m_tid (o.m_tid) {
619 }
621 {
622  m_tid = o.m_tid;
623  return *this;
624 }
626 {
627 }
628 inline bool operator == (TypeId a, TypeId b)
629 {
630  return a.m_tid == b.m_tid;
631 }
633 inline bool operator != (TypeId a, TypeId b)
634 {
635  return a.m_tid != b.m_tid;
636 }
639 /*************************************************************************
640  * The TypeId implementation which depends on templates
641  *************************************************************************/
643 template <typename T>
644 TypeId
646 {
647  return SetParent (T::GetTypeId ());
648 }
650 template <typename T>
651 TypeId
653 {
654  struct Maker {
655  static ObjectBase * Create () {
656  ObjectBase * base = new T ();
657  return base;
658  }
659  };
661  DoAddConstructor (cb);
662  return *this;
663 }
665 } // namespace ns3
667 #endif /* TYPE_ID_H */
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:107
uint32_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1058
uint32_t hash_t
Type of hash values.
Definition: type-id.h:113
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
Attribute or trace source is currently used.
Definition: type-id.h:71
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker, SupportLevel supportLevel=SUPPORTED, const std::string &supportMsg="")
Definition: type-id.cc:995
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
TypeId AddConstructor(void)
Record in this TypeId the fact that the default constructor is accessible.
Definition: type-id.h:652
std::string help
Trace help string.
Definition: type-id.h:101
Callback template class.
Definition: callback.h:1176
TypeId SetParent(void)
Set the parent TypeId.
Definition: type-id.h:645
static TypeId LookupByHash(hash_t hash)
Get a TypeId by hash.
Definition: type-id.cc:833
Hold a value for an Attribute.
Definition: attribute.h:68
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:84
Ptr< const TraceSourceAccessor > accessor
Trace accessor.
Definition: type-id.h:105
TraceSource implementation.
Definition: type-id.h:97
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:925
std::string supportMsg
Support message.
Definition: type-id.h:109
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:821
Anchor the ns-3 type and attribute system.
Definition: object-base.h:68
Definition of the NS_DEPRECATED macro.
Attribute or trace source is not used anymore; simulation fails.
Definition: type-id.h:73
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
The attribute can be written at construction-time.
Definition: type-id.h:65
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
Definition: type-id.cc:1042
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Get a TypeId by hash.
Definition: type-id.cc:841
bool HasConstructor(void) const
Check if this TypeId has a constructor.
Definition: type-id.cc:980
Declaration of the various callback functions.
bool MustHideFromDocumentation(void) const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:1050
Ptr< const AttributeAccessor > accessor
Accessor object.
Definition: type-id.h:88
friend bool operator<(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.cc:1204
friend bool operator==(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.h:628
static uint32_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:853
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
Definition: type-id.cc:1165
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:86
uint16_t m_tid
The TypeId value.
Definition: type-id.h:575
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Default constructor.
Definition: type-id.h:614
bool HasParent(void) const
Check if this TypeId has a parent.
Definition: type-id.cc:932
uint32_t GetTraceSourceN(void) const
Get the number of Trace sources.
Definition: type-id.cc:1079
static TypeId GetRegistered(uint32_t i)
Get a TypeId by index.
Definition: type-id.cc:859
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:72
Attribute implementation.
Definition: type-id.h:76
Flags describing when a given attribute can be read or written.
Definition: type-id.h:62
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:92
uint32_t flags
AttributeFlags value.
Definition: type-id.h:82
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:356
TypeId SetGroupName(std::string groupName)
Set the group name.
Definition: type-id.cc:911
The attribute can be written.
Definition: type-id.h:64
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:90
std::string supportMsg
Support message.
Definition: type-id.h:94
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:1471
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string name
Attribute name.
Definition: type-id.h:78
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Definition: type-id.cc:866
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
std::string name
Trace name.
Definition: type-id.h:99
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
Get the name.
Definition: type-id.cc:958
The attribute can be read, and written at any time.
Definition: type-id.h:66
uint16_t GetUid(void) const
Get the internal id of this TypeId.
Definition: type-id.cc:1172
void DoAddConstructor(Callback< ObjectBase * > callback)
Implementation for AddConstructor().
Definition: type-id.cc:988
hash_t GetHash(void) const
Get the hash.
Definition: type-id.cc:966
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
Definition: type-id.cc:1178
Declaration of Attribute helper macros.
bool SetAttributeInitialValue(uint32_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1032
NS_DEPRECATED TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor)
Record a new TraceSource.
Definition: type-id.cc:1092
Mark a function as deprecated.
Definition: deprecated.h:60
The attribute can be read.
Definition: type-id.h:63
TypeId & operator=(const TypeId &o)
Definition: type-id.h:620
friend bool operator!=(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.h:633
std::size_t GetSize(void) const
Get the size of this object.
Definition: type-id.cc:972
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:95
The level of support or deprecation for attributes or trace sources.
Definition: type-id.h:69
TypeId SetSize(std::size_t size)
Set the size of this type.
Definition: type-id.cc:918
ns3::MakeAccessorHelper declarations and template implementations.
std::string callback
Callback function signature type.
Definition: type-id.h:103
std::string GetAttributeFullName(uint32_t i) const
Get the Attribute name by index.
Definition: type-id.cc:1071
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
Definition: type-id.cc:939
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
Get the trace source by index.
Definition: type-id.cc:1085
std::string GetGroupName(void) const
Get the group name.
Definition: type-id.cc:950
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Get Attribute information by index.
Definition: type-id.cc:1065
Definition: type-id.h:625
a unique identifier for an interface.
Definition: type-id.h:58
Declare the attribute value, accessor and checkers for class type.
std::string help
Attribute help string.
Definition: type-id.h:80
TypeId HideFromDocumentation(void)
Hide this TypeId from documentation.
Definition: type-id.cc:1117
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:813