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  };
71  std::string name;
73  std::string help;
75  uint32_t flags;
84  };
88  std::string name;
90  std::string help;
92  std::string callback;
95  };
96 
98  typedef uint32_t hash_t;
99 
109  static TypeId LookupByName (std::string name);
118  static bool LookupByNameFailSafe (std::string name, TypeId *tid);
128  static TypeId LookupByHash (hash_t hash);
137  static bool LookupByHashFailSafe (hash_t hash, TypeId *tid);
138 
144  static uint32_t GetRegisteredN (void);
151  static TypeId GetRegistered (uint32_t i);
152 
161  explicit TypeId (const char * name);
162 
174  TypeId GetParent (void) const;
175 
181  bool HasParent (void) const;
182 
193  bool IsChildOf (TypeId other) const;
194 
200  std::string GetGroupName (void) const;
201 
207  std::string GetName (void) const;
208 
214  hash_t GetHash (void) const;
215 
221  std::size_t GetSize (void) const;
222 
228  bool HasConstructor (void) const;
229 
235  uint32_t GetAttributeN (void) const;
242  struct TypeId::AttributeInformation GetAttribute(uint32_t i) const;
249  std::string GetAttributeFullName (uint32_t i) const;
250 
258 
264  bool MustHideFromDocumentation (void) const;
265 
266 
272  uint32_t GetTraceSourceN (void) const;
279  struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const;
280 
290  TypeId SetParent (TypeId tid);
300  template <typename T>
301  TypeId SetParent (void);
302 
313  TypeId SetGroupName (std::string groupName);
314 
329  TypeId SetSize (std::size_t size);
330 
338  template <typename T>
339  TypeId AddConstructor (void);
340 
354  TypeId AddAttribute (std::string name,
355  std::string help,
356  const AttributeValue &initialValue,
359 
367  bool SetAttributeInitialValue(uint32_t i,
368  Ptr<const AttributeValue> initialValue);
369 
384  TypeId AddAttribute (std::string name,
385  std::string help,
386  uint32_t flags,
387  const AttributeValue &initialValue,
390 
401  TypeId AddTraceSource (std::string name,
402  std::string help,
405 
419  TypeId AddTraceSource (std::string name,
420  std::string help,
422  std::string callback);
423 
429 
439  bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
451 
460  uint16_t GetUid (void) const;
473  void SetUid (uint16_t tid);
474 
476  inline TypeId ();
481  inline TypeId (const TypeId &o);
487  inline TypeId &operator = (const TypeId &o);
489  inline ~TypeId ();
490 
491 private:
497  friend inline bool operator == (TypeId a, TypeId b);
498  friend inline bool operator != (TypeId a, TypeId b);
499  friend bool operator < (TypeId a, TypeId b);
506  explicit TypeId (uint16_t tid);
513 
515  uint16_t m_tid;
516 };
517 
526 std::ostream & operator << (std::ostream &os, TypeId tid);
534 std::istream & operator >> (std::istream &is, TypeId &tid);
535 
543 inline bool operator == (TypeId a, TypeId b);
544 inline bool operator != (TypeId a, TypeId b);
545 bool operator < (TypeId a, TypeId b);
549 
550 } // namespace ns3
551 
552 namespace ns3 {
553 
555  : m_tid (0) {
556 }
558  : m_tid (o.m_tid) {
559 }
561 {
562  m_tid = o.m_tid;
563  return *this;
564 }
566 {
567 }
568 inline bool operator == (TypeId a, TypeId b)
569 {
570  return a.m_tid == b.m_tid;
571 }
572 
573 inline bool operator != (TypeId a, TypeId b)
574 {
575  return a.m_tid != b.m_tid;
576 }
577 
578 
579 /*************************************************************************
580  * The TypeId implementation which depends on templates
581  *************************************************************************/
582 
583 template <typename T>
584 TypeId
586 {
587  return SetParent (T::GetTypeId ());
588 }
589 
590 template <typename T>
591 TypeId
593 {
594  struct Maker {
595  static ObjectBase * Create () {
596  ObjectBase * base = new T ();
597  return base;
598  }
599  };
601  DoAddConstructor (cb);
602  return *this;
603 }
604 
605 } // namespace ns3
606 
607 #endif /* TYPE_ID_H */
uint32_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:968
uint32_t hash_t
Type of hash values.
Definition: type-id.h:98
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
Record a new TraceSource.
Definition: type-id.cc:1002
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:592
std::string help
Trace help string.
Definition: type-id.h:90
Callback template class.
Definition: callback.h:1164
TypeId SetParent(void)
Set the parent TypeId.
Definition: type-id.h:585
static TypeId LookupByHash(hash_t hash)
Get a TypeId by hash.
Definition: type-id.cc:771
Hold a value for an Attribute.
Definition: attribute.h:68
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:77
Ptr< const TraceSourceAccessor > accessor
Trace accessor.
Definition: type-id.h:94
TraceSource implementation.
Definition: type-id.h:86
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:847
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:759
Anchor the ns-3 type and attribute system.
Definition: object-base.h:68
Definition of the NS_DEPRECATED macro.
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:952
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Get a TypeId by hash.
Definition: type-id.cc:779
bool HasConstructor(void) const
Check if this TypeId has a constructor.
Definition: type-id.cc:902
Declaration of the various callback functions.
bool MustHideFromDocumentation(void) const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:960
Ptr< const AttributeAccessor > accessor
Accessor object.
Definition: type-id.h:81
friend bool operator<(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.cc:1083
friend bool operator==(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.h:568
static uint32_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:791
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
Definition: type-id.cc:1030
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:79
uint16_t m_tid
The TypeId value.
Definition: type-id.h:515
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
TypeId()
Default constructor.
Definition: type-id.h:554
bool HasParent(void) const
Check if this TypeId has a parent.
Definition: type-id.cc:854
uint32_t GetTraceSourceN(void) const
Get the number of Trace sources.
Definition: type-id.cc:989
static TypeId GetRegistered(uint32_t i)
Get a TypeId by index.
Definition: type-id.cc:797
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1480
Attribute implementation.
Definition: type-id.h:69
AttributeFlag
Flags describing when a given attribute can be read or written.
Definition: type-id.h:62
uint32_t flags
AttributeFlags value.
Definition: type-id.h:75
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:833
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
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker)
Record in this TypeId the fact that a new attribute exists.
Definition: type-id.cc:917
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:83
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:1462
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetUid(uint16_t tid)
Set the internal id of this TypeId.
Definition: type-id.cc:1057
std::string name
Attribute name.
Definition: type-id.h:71
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name.
Definition: type-id.cc:804
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
std::string name
Trace name.
Definition: type-id.h:88
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:880
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:1051
void DoAddConstructor(Callback< ObjectBase * > callback)
Implementation for AddConstructor().
Definition: type-id.cc:910
hash_t GetHash(void) const
Get the hash.
Definition: type-id.cc:888
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:942
#define NS_DEPRECATED
Mark a function as deprecated.
Definition: deprecated.h:47
The attribute can be read.
Definition: type-id.h:63
TypeId & operator=(const TypeId &o)
Assignment.
Definition: type-id.h:560
friend bool operator!=(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.h:573
std::size_t GetSize(void) const
Get the size of this object.
Definition: type-id.cc:894
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.
Definition: type-id.cc:840
ns3::MakeAccessorHelper declarations and template implementations.
std::string callback
Callback function signature type.
Definition: type-id.h:92
std::string GetAttributeFullName(uint32_t i) const
Get the Attribute name by index.
Definition: type-id.cc:981
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
Definition: type-id.cc:861
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
Get the trace source by index.
Definition: type-id.cc:995
std::string GetGroupName(void) const
Get the group name.
Definition: type-id.cc:872
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Get Attribute information by index.
Definition: type-id.cc:975
~TypeId()
Destructor.
Definition: type-id.h:565
a unique identifier for an interface.
Definition: type-id.h:58
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type.
std::string help
Attribute help string.
Definition: type-id.h:73
TypeId HideFromDocumentation(void)
Hide this TypeId from documentation.
Definition: type-id.cc:1021
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:751