A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
type-id.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef TYPE_ID_H
20#define TYPE_ID_H
21
23#include "attribute-helper.h"
24#include "attribute.h"
25#include "callback.h"
26#include "hash.h"
28
29#include <stdint.h>
30#include <string>
31
38namespace ns3
39{
40
41class ObjectBase;
42
58class TypeId
59{
60 public:
63 {
64 ATTR_GET = 1 << 0,
65 ATTR_SET = 1 << 1,
66 ATTR_CONSTRUCT = 1 << 2,
69 };
70
73 {
77 };
78
81 {
83 std::string name;
85 std::string help;
99 std::string supportMsg;
100 };
101
104 {
106 std::string name;
108 std::string help;
110 std::string callback;
116 std::string supportMsg;
117 };
118
121
131 static TypeId LookupByName(std::string name);
140 static bool LookupByNameFailSafe(std::string name, TypeId* tid);
150 static TypeId LookupByHash(hash_t hash);
159 static bool LookupByHashFailSafe(hash_t hash, TypeId* tid);
160
166 static uint16_t GetRegisteredN();
173 static TypeId GetRegistered(uint16_t i);
174
183 explicit TypeId(const std::string& name);
184
196 TypeId GetParent() const;
197
203 bool HasParent() const;
204
215 bool IsChildOf(TypeId other) const;
216
222 std::string GetGroupName() const;
223
229 std::string GetName() const;
230
236 hash_t GetHash() const;
237
243 std::size_t GetSize() const;
244
250 bool HasConstructor() const;
251
257 std::size_t GetAttributeN() const;
264 struct TypeId::AttributeInformation GetAttribute(std::size_t i) const;
271 std::string GetAttributeFullName(std::size_t i) const;
272
279 Callback<ObjectBase*> GetConstructor() const;
280
286 bool MustHideFromDocumentation() const;
287
293 std::size_t GetTraceSourceN() const;
300 struct TypeId::TraceSourceInformation GetTraceSource(std::size_t i) const;
301
311 TypeId SetParent(TypeId tid);
321 template <typename T>
323
334 TypeId SetGroupName(std::string groupName);
335
350 TypeId SetSize(std::size_t size);
351
359 template <typename T>
361
384 TypeId AddAttribute(std::string name,
385 std::string help,
386 const AttributeValue& initialValue,
387 Ptr<const AttributeAccessor> accessor,
388 Ptr<const AttributeChecker> checker,
389 SupportLevel supportLevel = SUPPORTED,
390 const std::string& supportMsg = "");
391
399 bool SetAttributeInitialValue(std::size_t i, Ptr<const AttributeValue> initialValue);
400
423 TypeId AddAttribute(std::string name,
424 std::string help,
425 uint32_t flags,
426 const AttributeValue& initialValue,
427 Ptr<const AttributeAccessor> accessor,
428 Ptr<const AttributeChecker> checker,
429 SupportLevel supportLevel = SUPPORTED,
430 const std::string& supportMsg = "");
431
454 TypeId AddTraceSource(std::string name,
455 std::string help,
456 Ptr<const TraceSourceAccessor> accessor,
457 std::string callback,
458 SupportLevel supportLevel = SUPPORTED,
459 const std::string& supportMsg = "");
460
466
476 bool LookupAttributeByName(std::string name, struct AttributeInformation* info) const;
487 Ptr<const TraceSourceAccessor> LookupTraceSourceByName(std::string name) const;
499 Ptr<const TraceSourceAccessor> LookupTraceSourceByName(
500 std::string name,
501 struct TraceSourceInformation* info) const;
502
511 uint16_t GetUid() const;
524 void SetUid(uint16_t uid);
525
527 inline TypeId();
532 inline TypeId(const TypeId& o);
538 inline TypeId& operator=(const TypeId& o);
540 inline ~TypeId();
541
542 private:
548 friend inline bool operator==(TypeId a, TypeId b);
549 friend inline bool operator!=(TypeId a, TypeId b);
550 friend bool operator<(TypeId a, TypeId b);
557 explicit TypeId(uint16_t tid);
563 void DoAddConstructor(Callback<ObjectBase*> callback);
564
566 uint16_t m_tid;
567};
568
577std::ostream& operator<<(std::ostream& os, TypeId tid);
585std::istream& operator>>(std::istream& is, TypeId& tid);
586
594inline bool operator==(TypeId a, TypeId b);
595inline bool operator!=(TypeId a, TypeId b);
596bool operator<(TypeId a, TypeId b);
599ATTRIBUTE_HELPER_HEADER(TypeId);
600
601} // namespace ns3
602
603namespace ns3
604{
605
606TypeId::TypeId()
607 : m_tid(0)
608{
609}
610
611TypeId::TypeId(const TypeId& o)
612 : m_tid(o.m_tid)
613{
614}
615
616TypeId&
617TypeId::operator=(const TypeId& o)
618{
619 m_tid = o.m_tid;
620 return *this;
621}
622
623TypeId::~TypeId()
624{
625}
626
627inline bool
628operator==(TypeId a, TypeId b)
629{
630 return a.m_tid == b.m_tid;
631}
632
633inline bool
634operator!=(TypeId a, TypeId b)
635{
636 return a.m_tid != b.m_tid;
637}
638
639/*************************************************************************
640 * The TypeId implementation which depends on templates
641 *************************************************************************/
642
643template <typename T>
644TypeId
645TypeId::SetParent()
646{
647 return SetParent(T::GetTypeId());
648}
649
650template <typename T>
651TypeId
652TypeId::AddConstructor()
653{
654 struct Maker
655 {
656 static ObjectBase* Create()
657 {
658 ObjectBase* base = new T();
659 return base;
660 }
661 };
662
663 Callback<ObjectBase*> cb = MakeCallback(&Maker::Create);
664 DoAddConstructor(cb);
665 return *this;
666}
667
668} // namespace ns3
669
670#endif /* TYPE_ID_H */
ns3::MakeAccessorHelper declarations and template implementations.
Attribute helper (ATTRIBUTE_ )macros definition.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Declaration of the various callback functions.
Callback template class.
Definition: callback.h:443
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:59
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
Definition: type-id.cc:975
std::size_t GetTraceSourceN() const
Get the number of Trace sources.
Definition: type-id.cc:1127
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1080
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:839
bool HasParent() const
Check if this TypeId has a parent.
Definition: type-id.cc:967
TypeId SetSize(std::size_t size)
Set the size of this type.
Definition: type-id.cc:951
hash_t GetHash() const
Get the hash.
Definition: type-id.cc:1003
TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor, std::string callback, SupportLevel supportLevel=SUPPORTED, const std::string &supportMsg="")
Record a new TraceSource.
Definition: type-id.cc:1141
struct TypeId::TraceSourceInformation GetTraceSource(std::size_t i) const
Get the trace source by index.
Definition: type-id.cc:1134
bool MustHideFromDocumentation() const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:1096
AttributeFlag
Flags describing when a given attribute can be read or written.
Definition: type-id.h:63
@ ATTR_GET
The attribute can be read.
Definition: type-id.h:64
@ ATTR_SGC
The attribute can be read, and written at any time.
Definition: type-id.h:67
@ ATTR_SET
The attribute can be written.
Definition: type-id.h:65
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
Definition: type-id.h:66
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Get a TypeId by hash.
Definition: type-id.cc:871
std::string GetGroupName() const
Get the group name.
Definition: type-id.cc:987
TypeId HideFromDocumentation()
Hide this TypeId from documentation.
Definition: type-id.cc:1155
Callback< ObjectBase * > GetConstructor() const
Get the constructor callback.
Definition: type-id.cc:1088
static uint16_t GetRegisteredN()
Get the number of registered TypeIds.
Definition: type-id.cc:883
std::string GetAttributeFullName(std::size_t i) const
Get the Attribute name by index.
Definition: type-id.cc:1119
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1112
bool HasConstructor() const
Check if this TypeId has a constructor.
Definition: type-id.cc:1018
std::size_t GetAttributeN() const
Get the number of attributes.
Definition: type-id.cc:1104
TypeId GetParent() const
Get the parent of this TypeId.
Definition: type-id.cc:959
TypeId AddConstructor()
Record in this TypeId the fact that the default constructor is accessible.
Definition: type-id.h:652
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
Definition: type-id.cc:1216
TypeId SetGroupName(std::string groupName)
Set the group name.
Definition: type-id.cc:943
static TypeId LookupByHash(hash_t hash)
Get a TypeId by hash.
Definition: type-id.cc:861
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:890
std::size_t GetSize() const
Get the size of this object.
Definition: type-id.cc:1010
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
Definition: type-id.cc:1202
uint32_t hash_t
Type of hash values.
Definition: type-id.h:120
TypeId()
Default constructor.
Definition: type-id.h:606
uint16_t GetUid() const
Get the internal id of this TypeId.
Definition: type-id.cc:1209
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Definition: type-id.cc:897
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:848
SupportLevel
The level of support or deprecation for attributes or trace sources.
Definition: type-id.h:73
@ SUPPORTED
Attribute or trace source is currently used.
Definition: type-id.h:74
@ OBSOLETE
Attribute or trace source is not used anymore; simulation fails.
Definition: type-id.h:76
@ DEPRECATED
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:75
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:1033
std::string GetName() const
Get the name.
Definition: type-id.cc:995
TypeId SetParent()
Set the parent TypeId.
Definition: type-id.h:645
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.
Attribute implementation.
Definition: type-id.h:81
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:89
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:97
std::string name
Attribute name.
Definition: type-id.h:83
Ptr< const AttributeAccessor > accessor
Accessor object.
Definition: type-id.h:93
uint32_t flags
AttributeFlags value.
Definition: type-id.h:87
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:95
std::string supportMsg
Support message.
Definition: type-id.h:99
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:91
std::string help
Attribute help string.
Definition: type-id.h:85
TraceSource implementation.
Definition: type-id.h:104
std::string name
Trace name.
Definition: type-id.h:106
std::string supportMsg
Support message.
Definition: type-id.h:116
std::string help
Trace help string.
Definition: type-id.h:108
Ptr< const TraceSourceAccessor > accessor
Trace accessor.
Definition: type-id.h:112
std::string callback
Callback function signature type.
Definition: type-id.h:110
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:114
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.