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 
33 namespace ns3 {
34 
35 class ObjectBase;
36 
51 class TypeId
52 {
53 public:
58  ATTR_GET = 1<<0,
59  ATTR_SET = 1<<1,
60  ATTR_CONSTRUCT = 1<<2,
62  };
64  std::string name;
65  std::string help;
66  uint32_t flags;
71  };
73  std::string name;
74  std::string help;
75  std::string callback;
77  };
78 
82  typedef uint32_t hash_t;
83 
92  static TypeId LookupByName (std::string name);
99  static bool LookupByNameFailSafe (std::string name, TypeId *tid);
107  static TypeId LookupByHash (hash_t hash);
114  static bool LookupByHashFailSafe (hash_t hash, TypeId *tid);
115 
119  static uint32_t GetRegisteredN (void);
124  static TypeId GetRegistered (uint32_t i);
125 
132  explicit TypeId (const char * name);
133 
143  TypeId GetParent (void) const;
144 
145  bool HasParent (void) const;
146 
156  bool IsChildOf (TypeId other) const;
157 
161  std::string GetGroupName (void) const;
162 
166  std::string GetName (void) const;
167 
171  hash_t GetHash (void) const;
172 
176  std::size_t GetSize (void) const;
177 
181  bool HasConstructor (void) const;
182 
186  uint32_t GetAttributeN (void) const;
192  struct TypeId::AttributeInformation GetAttribute(uint32_t i) const;
198  std::string GetAttributeFullName (uint32_t i) const;
199 
205 
210  bool MustHideFromDocumentation (void) const;
211 
212 
216  uint32_t GetTraceSourceN (void) const;
221  struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const;
222 
230  TypeId SetParent (TypeId tid);
237  template <typename T>
238  TypeId SetParent (void);
239 
248  TypeId SetGroupName (std::string groupName);
249 
264  TypeId SetSize (std::size_t size);
265 
272  template <typename T>
273  TypeId AddConstructor (void);
274 
286  TypeId AddAttribute (std::string name,
287  std::string help,
288  const AttributeValue &initialValue,
291 
297  bool SetAttributeInitialValue(uint32_t i,
298  Ptr<const AttributeValue> initialValue);
299 
312  TypeId AddAttribute (std::string name,
313  std::string help,
314  uint32_t flags,
315  const AttributeValue &initialValue,
318 
329  TypeId AddTraceSource (std::string name,
330  std::string help,
333 
344  TypeId AddTraceSource (std::string name,
345  std::string help,
347  std::string callback);
348 
350 
357  bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
366 
374  uint16_t GetUid (void) const;
383  void SetUid (uint16_t tid);
384 
385  // construct an invalid TypeId.
386  inline TypeId ();
387  inline TypeId (const TypeId &o);
388  inline TypeId &operator = (const TypeId &o);
389  inline ~TypeId ();
390 
391 private:
392  friend class AttributeList;
393  friend bool operator == (TypeId a, TypeId b);
394  friend bool operator != (TypeId a, TypeId b);
395  friend bool operator < (TypeId a, TypeId b);
396 
397 
398  explicit TypeId (uint16_t tid);
400 
401  uint16_t m_tid;
402 };
403 
404 std::ostream & operator << (std::ostream &os, TypeId tid);
405 std::istream & operator >> (std::istream &is, TypeId &tid);
406 inline bool operator == (TypeId a, TypeId b);
407 inline bool operator != (TypeId a, TypeId b);
408 bool operator < (TypeId a, TypeId b);
409 
411 
412 } // namespace ns3
413 
414 namespace ns3 {
415 
417  : m_tid (0) {
418 }
420  : m_tid (o.m_tid) {
421 }
423 {
424  m_tid = o.m_tid;
425  return *this;
426 }
428 {
429 }
430 inline bool operator == (TypeId a, TypeId b)
431 {
432  return a.m_tid == b.m_tid;
433 }
434 
435 inline bool operator != (TypeId a, TypeId b)
436 {
437  return a.m_tid != b.m_tid;
438 }
439 
440 
441 /*************************************************************************
442  * The TypeId implementation which depends on templates
443  *************************************************************************/
444 
445 template <typename T>
446 TypeId
448 {
449  return SetParent (T::GetTypeId ());
450 }
451 
452 template <typename T>
453 TypeId
455 {
456  struct Maker {
457  static ObjectBase * Create () {
458  ObjectBase * base = new T ();
459  return base;
460  }
461  };
463  DoAddConstructor (cb);
464  return *this;
465 }
466 
467 } // namespace ns3
468 
469 #endif /* TYPE_ID_H */
uint32_t GetAttributeN(void) const
Definition: type-id.cc:773
uint32_t hash_t
Type of hash values.
Definition: type-id.h:82
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:807
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
TypeId AddConstructor(void)
Definition: type-id.h:454
Callback template class.
Definition: callback.h:978
TypeId SetParent(void)
Definition: type-id.h:447
static TypeId LookupByHash(hash_t hash)
Definition: type-id.cc:576
Hold a value for an Attribute.
Definition: attribute.h:68
Ptr< const AttributeValue > originalInitialValue
Definition: type-id.h:67
Ptr< const TraceSourceAccessor > accessor
Definition: type-id.h:76
TypeId GetParent(void) const
Definition: type-id.cc:652
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Definition: type-id.cc:564
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:60
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
The attribute can be read, and written at any time.
Definition: type-id.h:61
Callback< ObjectBase * > GetConstructor(void) const
Definition: type-id.cc:757
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Definition: type-id.cc:584
bool HasConstructor(void) const
Definition: type-id.cc:707
The attribute can be read.
Definition: type-id.h:58
bool MustHideFromDocumentation(void) const
Definition: type-id.cc:765
Ptr< const AttributeAccessor > accessor
Definition: type-id.h:69
friend bool operator<(TypeId a, TypeId b)
Definition: type-id.cc:888
#define NS_DEPRECATED
Definition: deprecated.h:7
friend bool operator==(TypeId a, TypeId b)
Definition: type-id.h:430
static uint32_t GetRegisteredN(void)
Definition: type-id.cc:596
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Definition: type-id.cc:835
Ptr< const AttributeValue > initialValue
Definition: type-id.h:68
uint16_t m_tid
Definition: type-id.h:401
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
bool HasParent(void) const
Definition: type-id.cc:659
uint32_t GetTraceSourceN(void) const
Definition: type-id.cc:794
static TypeId GetRegistered(uint32_t i)
Definition: type-id.cc:602
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1290
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:350
TypeId SetGroupName(std::string groupName)
Definition: type-id.cc:638
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:722
Ptr< const AttributeChecker > checker
Definition: type-id.h:70
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:1272
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetUid(uint16_t tid)
Definition: type-id.cc:862
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Definition: type-id.cc:609
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
The attribute can be written.
Definition: type-id.h:59
AttributeFlag
Flags describing when a given attribute can be read or written.
Definition: type-id.h:57
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:685
friend class AttributeList
Definition: type-id.h:392
uint16_t GetUid(void) const
Definition: type-id.cc:856
void DoAddConstructor(Callback< ObjectBase * > callback)
Definition: type-id.cc:715
hash_t GetHash(void) const
Definition: type-id.cc:693
Declaration of Attribute helper macros.
bool SetAttributeInitialValue(uint32_t i, Ptr< const AttributeValue > initialValue)
Definition: type-id.cc:747
TypeId & operator=(const TypeId &o)
Definition: type-id.h:422
friend bool operator!=(TypeId a, TypeId b)
Definition: type-id.h:435
std::size_t GetSize(void) const
Definition: type-id.cc:699
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:645
ns3::MakeAccessorHelper declarations and template implementations.
std::string GetAttributeFullName(uint32_t i) const
Definition: type-id.cc:786
bool IsChildOf(TypeId other) const
Definition: type-id.cc:666
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
Definition: type-id.cc:800
std::string GetGroupName(void) const
Definition: type-id.cc:677
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Definition: type-id.cc:780
a unique identifier for an interface.
Definition: type-id.h:51
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type.
TypeId HideFromDocumentation(void)
Definition: type-id.cc:826
static TypeId LookupByName(std::string name)
Definition: type-id.cc:556