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 
58 class TypeId
59 {
60 public:
63  {
64  ATTR_GET = 1 << 0,
65  ATTR_SET = 1 << 1,
66  ATTR_CONSTRUCT = 1 << 2,
68  };
71  {
75  };
78  {
80  std::string name;
82  std::string help;
84  uint32_t flags;
96  std::string supportMsg;
97  };
100  {
102  std::string name;
104  std::string help;
106  std::string callback;
112  std::string supportMsg;
113  };
114 
116  typedef uint32_t hash_t;
117 
127  static TypeId LookupByName (std::string name);
136  static bool LookupByNameFailSafe (std::string name, TypeId *tid);
146  static TypeId LookupByHash (hash_t hash);
155  static bool LookupByHashFailSafe (hash_t hash, TypeId *tid);
156 
162  static uint16_t GetRegisteredN (void);
169  static TypeId GetRegistered (uint16_t i);
170 
179  explicit TypeId (const char * name);
180 
192  TypeId GetParent (void) const;
193 
199  bool HasParent (void) const;
200 
211  bool IsChildOf (TypeId other) const;
212 
218  std::string GetGroupName (void) const;
219 
225  std::string GetName (void) const;
226 
232  hash_t GetHash (void) const;
233 
239  std::size_t GetSize (void) const;
240 
246  bool HasConstructor (void) const;
247 
253  std::size_t GetAttributeN (void) const;
260  struct TypeId::AttributeInformation GetAttribute (std::size_t i) const;
267  std::string GetAttributeFullName (std::size_t i) const;
268 
275  Callback<ObjectBase *> GetConstructor (void) const;
276 
282  bool MustHideFromDocumentation (void) const;
283 
284 
290  std::size_t GetTraceSourceN (void) const;
297  struct TypeId::TraceSourceInformation GetTraceSource (std::size_t i) const;
298 
308  TypeId SetParent (TypeId tid);
318  template <typename T>
319  TypeId SetParent (void);
320 
331  TypeId SetGroupName (std::string groupName);
332 
347  TypeId SetSize (std::size_t size);
348 
356  template <typename T>
357  TypeId AddConstructor (void);
358 
381  TypeId AddAttribute (std::string name,
382  std::string help,
383  const AttributeValue &initialValue,
384  Ptr<const AttributeAccessor> accessor,
385  Ptr<const AttributeChecker> checker,
386  SupportLevel supportLevel = SUPPORTED,
387  const std::string &supportMsg = "");
388 
396  bool SetAttributeInitialValue (std::size_t i,
397  Ptr<const AttributeValue> initialValue);
398 
421  TypeId AddAttribute (std::string name,
422  std::string help,
423  uint32_t flags,
424  const AttributeValue &initialValue,
425  Ptr<const AttributeAccessor> accessor,
426  Ptr<const AttributeChecker> checker,
427  SupportLevel supportLevel = SUPPORTED,
428  const std::string &supportMsg = "");
429 
442  TypeId AddTraceSource (std::string name,
443  std::string help,
444  Ptr<const TraceSourceAccessor> accessor);
445 
468  TypeId AddTraceSource (std::string name,
469  std::string help,
470  Ptr<const TraceSourceAccessor> accessor,
471  std::string callback,
472  SupportLevel supportLevel = SUPPORTED,
473  const std::string &supportMsg = "");
474 
480 
490  bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
501  Ptr<const TraceSourceAccessor> LookupTraceSourceByName (std::string name) const;
513  Ptr<const TraceSourceAccessor> LookupTraceSourceByName (std::string name, struct TraceSourceInformation *info) const;
514 
523  uint16_t GetUid (void) const;
536  void SetUid (uint16_t uid);
537 
539  inline TypeId ();
544  inline TypeId (const TypeId &o);
550  inline TypeId &operator = (const TypeId &o);
552  inline ~TypeId ();
553 
554 private:
560  friend inline bool operator == (TypeId a, TypeId b);
561  friend inline bool operator != (TypeId a, TypeId b);
562  friend bool operator < (TypeId a, TypeId b);
569  explicit TypeId (uint16_t tid);
575  void DoAddConstructor (Callback<ObjectBase *> callback);
576 
578  uint16_t m_tid;
579 };
580 
589 std::ostream & operator << (std::ostream &os, TypeId tid);
597 std::istream & operator >> (std::istream &is, TypeId &tid);
598 
606 inline bool operator == (TypeId a, TypeId b);
607 inline bool operator != (TypeId a, TypeId b);
608 bool operator < (TypeId a, TypeId b);
611 ATTRIBUTE_HELPER_HEADER (TypeId);
612 
613 } // namespace ns3
614 
615 namespace ns3 {
616 
617 TypeId::TypeId ()
618  : m_tid (0)
619 {}
620 TypeId::TypeId (const TypeId &o)
621  : m_tid (o.m_tid)
622 {}
623 TypeId &TypeId::operator = (const TypeId &o)
624 {
625  m_tid = o.m_tid;
626  return *this;
627 }
628 TypeId::~TypeId ()
629 {}
630 inline bool operator == (TypeId a, TypeId b)
631 {
632  return a.m_tid == b.m_tid;
633 }
634 
635 inline bool operator != (TypeId a, TypeId b)
636 {
637  return a.m_tid != b.m_tid;
638 }
639 
640 
641 /*************************************************************************
642  * The TypeId implementation which depends on templates
643  *************************************************************************/
644 
645 template <typename T>
646 TypeId
647 TypeId::SetParent (void)
648 {
649  return SetParent (T::GetTypeId ());
650 }
651 
652 template <typename T>
653 TypeId
654 TypeId::AddConstructor (void)
655 {
656  struct Maker
657  {
658  static ObjectBase * Create ()
659  {
660  ObjectBase * base = new T ();
661  return base;
662  }
663  };
664  Callback<ObjectBase *> cb = MakeCallback (&Maker::Create);
665  DoAddConstructor (cb);
666  return *this;
667 }
668 
669 } // namespace ns3
670 
671 #endif /* TYPE_ID_H */
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
Definition: type-id.cc:957
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:110
uint32_t hash_t
Type of hash values.
Definition: type-id.h:116
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
Definition: type-id.cc:1060
std::string GetName(void) const
Get the name.
Definition: type-id.cc:976
hash_t GetHash(void) const
Get the hash.
Definition: type-id.cc:984
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="")
Record in this TypeId the fact that a new attribute exists.
Definition: type-id.cc:1013
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
Definition: type-id.cc:1185
TypeId AddConstructor(void)
Record in this TypeId the fact that the default constructor is accessible.
Definition: type-id.h:654
bool HasConstructor(void) const
Check if this TypeId has a constructor.
Definition: type-id.cc:998
std::string help
Trace help string.
Definition: type-id.h:104
Callback template class.
Definition: callback.h:1273
TypeId SetParent(void)
Set the parent TypeId.
Definition: type-id.h:647
static TypeId LookupByHash(hash_t hash)
Get a TypeId by hash.
Definition: type-id.cc:849
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:86
Ptr< const TraceSourceAccessor > accessor
Trace accessor.
Definition: type-id.h:108
TraceSource implementation.
Definition: type-id.h:99
std::string supportMsg
Support message.
Definition: type-id.h:112
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:875
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:837
The attribute can be written at construction-time.
Definition: type-id.h:66
NS_DEPRECATED macro definition.
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Definition: type-id.cc:882
bool HasParent(void) const
Check if this TypeId has a parent.
Definition: type-id.cc:950
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
The attribute can be read, and written at any time.
Definition: type-id.h:67
STL namespace.
std::size_t GetTraceSourceN(void) const
Get the number of Trace sources.
Definition: type-id.cc:1097
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1050
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:943
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Get a TypeId by hash.
Definition: type-id.cc:857
The attribute can be read.
Definition: type-id.h:64
Declaration of the various callback functions.
Ptr< const AttributeAccessor > accessor
Accessor object.
Definition: type-id.h:90
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:88
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
TypeId()
Default constructor.
Definition: type-id.h:617
bool MustHideFromDocumentation(void) const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:1068
struct TypeId::TraceSourceInformation GetTraceSource(std::size_t i) const
Get the trace source by index.
Definition: type-id.cc:1103
Attribute implementation.
Definition: type-id.h:77
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:94
uint32_t flags
AttributeFlags value.
Definition: type-id.h:84
TypeId SetGroupName(std::string groupName)
Set the group name.
Definition: type-id.cc:929
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:92
std::string supportMsg
Support message.
Definition: type-id.h:96
uint16_t GetUid(void) const
Get the internal id of this TypeId.
Definition: type-id.cc:1192
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string name
Attribute name.
Definition: type-id.h:80
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
std::string GetGroupName(void) const
Get the group name.
Definition: type-id.cc:968
std::size_t GetSize(void) const
Get the size of this object.
Definition: type-id.cc:990
The attribute can be written.
Definition: type-id.h:65
std::string GetAttributeFullName(std::size_t i) const
Get the Attribute name by index.
Definition: type-id.cc:1089
std::string name
Trace name.
Definition: type-id.h:102
AttributeFlag
Flags describing when a given attribute can be read or written.
Definition: type-id.h:62
Attribute or trace source is currently used.
Definition: type-id.h:72
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
Definition: type-id.cc:1198
Attribute helper (ATTRIBUTE_ )macros definition.
NS_DEPRECATED TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor)
Record a new TraceSource.
Definition: type-id.cc:1110
Attribute or trace source is not used anymore; simulation fails.
Definition: type-id.h:74
#define NS_DEPRECATED
Mark a function as deprecated.
Definition: deprecated.h:60
std::size_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1076
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1083
TypeId SetSize(std::size_t size)
Set the size of this type.
Definition: type-id.cc:936
ns3::MakeAccessorHelper declarations and template implementations.
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:73
SupportLevel
The level of support or deprecation for attributes or trace sources.
Definition: type-id.h:70
std::string callback
Callback function signature type.
Definition: type-id.h:106
static uint16_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:869
a unique identifier for an interface.
Definition: type-id.h:58
std::string help
Attribute help string.
Definition: type-id.h:82
TypeId HideFromDocumentation(void)
Hide this TypeId from documentation.
Definition: type-id.cc:1135
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:829