A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "hash.h"
29 #include <string>
30 #include <stdint.h>
31 
32 namespace ns3 {
33 
34 class ObjectBase;
35 
49 class TypeId
50 {
51 public:
56  ATTR_GET = 1<<0,
57  ATTR_SET = 1<<1,
58  ATTR_CONSTRUCT = 1<<2,
60  };
62  std::string name;
63  std::string help;
64  uint32_t flags;
69  };
71  std::string name;
72  std::string help;
74  };
75 
79  typedef uint32_t hash_t;
80 
89  static TypeId LookupByName (std::string name);
96  static bool LookupByNameFailSafe (std::string name, TypeId *tid);
104  static TypeId LookupByHash (hash_t hash);
111  static bool LookupByHashFailSafe (hash_t hash, TypeId *tid);
112 
116  static uint32_t GetRegisteredN (void);
121  static TypeId GetRegistered (uint32_t i);
122 
129  explicit TypeId (const char * name);
130 
140  TypeId GetParent (void) const;
141 
142  bool HasParent (void) const;
143 
153  bool IsChildOf (TypeId other) const;
154 
158  std::string GetGroupName (void) const;
159 
163  std::string GetName (void) const;
164 
168  hash_t GetHash (void) const;
169 
173  bool HasConstructor (void) const;
174 
178  uint32_t GetAttributeN (void) const;
184  struct TypeId::AttributeInformation GetAttribute(uint32_t i) const;
190  std::string GetAttributeFullName (uint32_t i) const;
191 
197 
202  bool MustHideFromDocumentation (void) const;
203 
204 
208  uint32_t GetTraceSourceN (void) const;
213  struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const;
214 
222  TypeId SetParent (TypeId tid);
229  template <typename T>
230  TypeId SetParent (void);
231 
240  TypeId SetGroupName (std::string groupName);
241 
248  template <typename T>
249  TypeId AddConstructor (void);
250 
262  TypeId AddAttribute (std::string name,
263  std::string help,
264  const AttributeValue &initialValue,
267 
273  bool SetAttributeInitialValue(uint32_t i,
274  Ptr<const AttributeValue> initialValue);
275 
288  TypeId AddAttribute (std::string name,
289  std::string help,
290  uint32_t flags,
291  const AttributeValue &initialValue,
294 
303  TypeId AddTraceSource (std::string name,
304  std::string help,
306 
308 
315  bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
324 
332  uint16_t GetUid (void) const;
341  void SetUid (uint16_t tid);
342 
343  // construct an invalid TypeId.
344  inline TypeId ();
345  inline TypeId (const TypeId &o);
346  inline TypeId &operator = (const TypeId &o);
347  inline ~TypeId ();
348 
349 private:
350  friend class AttributeList;
351  friend bool operator == (TypeId a, TypeId b);
352  friend bool operator != (TypeId a, TypeId b);
353  friend bool operator < (TypeId a, TypeId b);
354 
355 
356  explicit TypeId (uint16_t tid);
358 
359  uint16_t m_tid;
360 };
361 
362 std::ostream & operator << (std::ostream &os, TypeId tid);
363 std::istream & operator >> (std::istream &is, TypeId &tid);
364 inline bool operator == (TypeId a, TypeId b);
365 inline bool operator != (TypeId a, TypeId b);
366 bool operator < (TypeId a, TypeId b);
367 
375 
376 } // namespace ns3
377 
378 namespace ns3 {
379 
381  : m_tid (0) {
382 }
384  : m_tid (o.m_tid) {
385 }
387 {
388  m_tid = o.m_tid;
389  return *this;
390 }
392 {
393 }
394 inline bool operator == (TypeId a, TypeId b)
395 {
396  return a.m_tid == b.m_tid;
397 }
398 
399 inline bool operator != (TypeId a, TypeId b)
400 {
401  return a.m_tid != b.m_tid;
402 }
403 
404 
405 /*************************************************************************
406  * The TypeId implementation which depends on templates
407  *************************************************************************/
408 
409 template <typename T>
410 TypeId
412 {
413  return SetParent (T::GetTypeId ());
414 }
415 
416 template <typename T>
417 TypeId
419 {
420  struct Maker {
421  static ObjectBase * Create () {
422  ObjectBase * base = new T ();
423  return base;
424  }
425  };
427  DoAddConstructor (cb);
428  return *this;
429 }
430 
431 } // namespace ns3
432 
433 #endif /* TYPE_ID_H */
ATTRIBUTE_HELPER_HEADER(ObjectFactory)
uint32_t GetAttributeN(void) const
Definition: type-id.cc:738
uint32_t hash_t
Type of hash values.
Definition: type-id.h:79
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:49
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
TypeId AddConstructor(void)
Definition: type-id.h:418
Callback template class.
Definition: callback.h:924
TypeId SetParent(void)
Definition: type-id.h:411
static TypeId LookupByHash(hash_t hash)
Definition: type-id.cc:555
Hold a value for an Attribute.
Definition: attribute.h:56
Ptr< const AttributeValue > originalInitialValue
Definition: type-id.h:65
Ptr< const TraceSourceAccessor > accessor
Definition: type-id.h:73
TypeId GetParent(void) const
Definition: type-id.cc:624
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Definition: type-id.cc:543
implement the ns-3 type and attribute system
Definition: object-base.h:61
The attribute can be written at construction-time.
Definition: type-id.h:58
The attribute can be read, and written at any time.
Definition: type-id.h:59
Callback< ObjectBase * > GetConstructor(void) const
Definition: type-id.cc:722
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Definition: type-id.cc:563
bool HasConstructor(void) const
Definition: type-id.cc:672
The attribute can be read.
Definition: type-id.h:56
bool MustHideFromDocumentation(void) const
Definition: type-id.cc:730
Ptr< const AttributeAccessor > accessor
Definition: type-id.h:67
friend bool operator<(TypeId a, TypeId b)
Definition: type-id.cc:844
friend bool operator==(TypeId a, TypeId b)
Definition: type-id.h:394
Ptr< T > Create(void)
Definition: ptr.h:232
static uint32_t GetRegisteredN(void)
Definition: type-id.cc:575
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Definition: type-id.cc:791
Ptr< const AttributeValue > initialValue
Definition: type-id.h:66
uint16_t m_tid
Definition: type-id.h:359
bool HasParent(void) const
Definition: type-id.cc:631
uint32_t GetTraceSourceN(void) const
Definition: type-id.cc:759
static TypeId GetRegistered(uint32_t i)
Definition: type-id.cc:581
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1242
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:327
TypeId SetGroupName(std::string groupName)
Definition: type-id.cc:617
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker)
Definition: type-id.cc:687
Ptr< const AttributeChecker > checker
Definition: type-id.h:68
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:1217
void SetUid(uint16_t tid)
Definition: type-id.cc:818
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Definition: type-id.cc:588
The attribute can be written.
Definition: type-id.h:57
AttributeFlag
Flags describing when a given attribute can be read or written.
Definition: type-id.h:55
std::string GetName(void) const
Definition: type-id.cc:657
friend class AttributeList
Definition: type-id.h:350
uint16_t GetUid(void) const
Definition: type-id.cc:812
void DoAddConstructor(Callback< ObjectBase * > callback)
Definition: type-id.cc:680
hash_t GetHash(void) const
Definition: type-id.cc:665
bool SetAttributeInitialValue(uint32_t i, Ptr< const AttributeValue > initialValue)
Definition: type-id.cc:712
TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor)
Definition: type-id.cc:772
TypeId & operator=(const TypeId &o)
Definition: type-id.h:386
friend bool operator!=(TypeId a, TypeId b)
Definition: type-id.h:399
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:89
std::string GetAttributeFullName(uint32_t i) const
Definition: type-id.cc:751
bool IsChildOf(TypeId other) const
Definition: type-id.cc:638
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
Definition: type-id.cc:765
std::string GetGroupName(void) const
Definition: type-id.cc:649
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Definition: type-id.cc:745
a unique identifier for an interface.
Definition: type-id.h:49
TypeId HideFromDocumentation(void)
Definition: type-id.cc:782
static TypeId LookupByName(std::string name)
Definition: type-id.cc:535