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  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  };
111 
113  typedef uint32_t hash_t;
114 
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);
153 
159  static uint16_t GetRegisteredN (void);
166  static TypeId GetRegistered (uint16_t i);
167 
176  explicit TypeId (const char * name);
177 
189  TypeId GetParent (void) const;
190 
196  bool HasParent (void) const;
197 
208  bool IsChildOf (TypeId other) const;
209 
215  std::string GetGroupName (void) const;
216 
222  std::string GetName (void) const;
223 
229  hash_t GetHash (void) const;
230 
236  std::size_t GetSize (void) const;
237 
243  bool HasConstructor (void) const;
244 
250  std::size_t GetAttributeN (void) const;
257  struct TypeId::AttributeInformation GetAttribute (std::size_t i) const;
264  std::string GetAttributeFullName (std::size_t i) const;
265 
272  Callback<ObjectBase *> GetConstructor (void) const;
273 
279  bool MustHideFromDocumentation (void) const;
280 
281 
287  std::size_t GetTraceSourceN (void) const;
294  struct TypeId::TraceSourceInformation GetTraceSource (std::size_t i) const;
295 
305  TypeId SetParent (TypeId tid);
315  template <typename T>
316  TypeId SetParent (void);
317 
328  TypeId SetGroupName (std::string groupName);
329 
344  TypeId SetSize (std::size_t size);
345 
353  template <typename T>
354  TypeId AddConstructor (void);
355 
378  TypeId AddAttribute (std::string name,
379  std::string help,
380  const AttributeValue &initialValue,
381  Ptr<const AttributeAccessor> accessor,
382  Ptr<const AttributeChecker> checker,
383  SupportLevel supportLevel = SUPPORTED,
384  const std::string &supportMsg = "");
385 
393  bool SetAttributeInitialValue (std::size_t i,
394  Ptr<const AttributeValue> initialValue);
395 
418  TypeId AddAttribute (std::string name,
419  std::string help,
420  uint32_t flags,
421  const AttributeValue &initialValue,
422  Ptr<const AttributeAccessor> accessor,
423  Ptr<const AttributeChecker> checker,
424  SupportLevel supportLevel = SUPPORTED,
425  const std::string &supportMsg = "");
426 
439  TypeId AddTraceSource (std::string name,
440  std::string help,
441  Ptr<const TraceSourceAccessor> accessor);
442 
465  TypeId AddTraceSource (std::string name,
466  std::string help,
467  Ptr<const TraceSourceAccessor> accessor,
468  std::string callback,
469  SupportLevel supportLevel = SUPPORTED,
470  const std::string &supportMsg = "");
471 
477 
487  bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
498  Ptr<const TraceSourceAccessor> LookupTraceSourceByName (std::string name) const;
510  Ptr<const TraceSourceAccessor> LookupTraceSourceByName (std::string name, struct TraceSourceInformation *info) const;
511 
520  uint16_t GetUid (void) const;
533  void SetUid (uint16_t uid);
534 
536  inline TypeId ();
541  inline TypeId (const TypeId &o);
547  inline TypeId &operator = (const TypeId &o);
549  inline ~TypeId ();
550 
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);
572  void DoAddConstructor (Callback<ObjectBase *> callback);
573 
575  uint16_t m_tid;
576 };
577 
586 std::ostream & operator << (std::ostream &os, TypeId tid);
594 std::istream & operator >> (std::istream &is, TypeId &tid);
595 
603 inline bool operator == (TypeId a, TypeId b);
604 inline bool operator != (TypeId a, TypeId b);
605 bool operator < (TypeId a, TypeId b);
608 ATTRIBUTE_HELPER_HEADER (TypeId);
609 
610 } // namespace ns3
611 
612 namespace ns3 {
613 
614 TypeId::TypeId ()
615  : m_tid (0) {
616 }
617 TypeId::TypeId (const TypeId &o)
618  : m_tid (o.m_tid) {
619 }
620 TypeId &TypeId::operator = (const TypeId &o)
621 {
622  m_tid = o.m_tid;
623  return *this;
624 }
625 TypeId::~TypeId ()
626 {
627 }
628 inline bool operator == (TypeId a, TypeId b)
629 {
630  return a.m_tid == b.m_tid;
631 }
632 
633 inline bool operator != (TypeId a, TypeId b)
634 {
635  return a.m_tid != b.m_tid;
636 }
637 
638 
639 /*************************************************************************
640  * The TypeId implementation which depends on templates
641  *************************************************************************/
642 
643 template <typename T>
644 TypeId
645 TypeId::SetParent (void)
646 {
647  return SetParent (T::GetTypeId ());
648 }
649 
650 template <typename T>
651 TypeId
652 TypeId::AddConstructor (void)
653 {
654  struct Maker {
655  static ObjectBase * Create () {
656  ObjectBase * base = new T ();
657  return base;
658  }
659  };
660  Callback<ObjectBase *> cb = MakeCallback (&Maker::Create);
661  DoAddConstructor (cb);
662  return *this;
663 }
664 
665 } // namespace ns3
666 
667 #endif /* TYPE_ID_H */
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
Definition: type-id.cc:950
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:107
uint32_t hash_t
Type of hash values.
Definition: type-id.h:113
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
Definition: type-id.cc:1053
std::string GetName(void) const
Get the name.
Definition: type-id.cc:969
hash_t GetHash(void) const
Get the hash.
Definition: type-id.cc:977
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:1006
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:1176
TypeId AddConstructor(void)
Record in this TypeId the fact that the default constructor is accessible.
Definition: type-id.h:652
bool HasConstructor(void) const
Check if this TypeId has a constructor.
Definition: type-id.cc:991
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:844
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
std::string supportMsg
Support message.
Definition: type-id.h:109
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:870
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:832
The attribute can be written at construction-time.
Definition: type-id.h:65
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:877
bool HasParent(void) const
Check if this TypeId has a parent.
Definition: type-id.cc:943
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
The attribute can be read, and written at any time.
Definition: type-id.h:66
STL namespace.
std::size_t GetTraceSourceN(void) const
Get the number of Trace sources.
Definition: type-id.cc:1090
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1043
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:936
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Get a TypeId by hash.
Definition: type-id.cc:852
The attribute can be read.
Definition: type-id.h:63
Declaration of the various callback functions.
Ptr< const AttributeAccessor > accessor
Accessor object.
Definition: type-id.h:88
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:86
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
TypeId()
Default constructor.
Definition: type-id.h:614
bool MustHideFromDocumentation(void) const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:1061
struct TypeId::TraceSourceInformation GetTraceSource(std::size_t i) const
Get the trace source by index.
Definition: type-id.cc:1096
Attribute implementation.
Definition: type-id.h:76
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:92
uint32_t flags
AttributeFlags value.
Definition: type-id.h:82
TypeId SetGroupName(std::string groupName)
Set the group name.
Definition: type-id.cc:922
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:90
std::string supportMsg
Support message.
Definition: type-id.h:94
uint16_t GetUid(void) const
Get the internal id of this TypeId.
Definition: type-id.cc:1183
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string name
Attribute name.
Definition: type-id.h:78
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
std::string GetGroupName(void) const
Get the group name.
Definition: type-id.cc:961
std::size_t GetSize(void) const
Get the size of this object.
Definition: type-id.cc:983
The attribute can be written.
Definition: type-id.h:64
std::string GetAttributeFullName(std::size_t i) const
Get the Attribute name by index.
Definition: type-id.cc:1082
std::string name
Trace name.
Definition: type-id.h:99
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:71
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
Definition: type-id.cc:1189
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:1103
Attribute or trace source is not used anymore; simulation fails.
Definition: type-id.h:73
#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:1069
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1076
TypeId SetSize(std::size_t size)
Set the size of this type.
Definition: type-id.cc:929
ns3::MakeAccessorHelper declarations and template implementations.
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:72
SupportLevel
The level of support or deprecation for attributes or trace sources.
Definition: type-id.h:69
std::string callback
Callback function signature type.
Definition: type-id.h:103
static uint16_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:864
a unique identifier for an interface.
Definition: type-id.h:58
std::string help
Attribute help string.
Definition: type-id.h:80
TypeId HideFromDocumentation(void)
Hide this TypeId from documentation.
Definition: type-id.cc:1128
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:824