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 TypeId::AttributeInformation GetAttribute(std::size_t i) const;
271 std::string GetAttributeFullName(std::size_t i) const;
272
280
286 bool MustHideFromDocumentation() const;
287
293 std::size_t GetTraceSourceN() const;
301
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,
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,
429 SupportLevel supportLevel = SUPPORTED,
430 const std::string& supportMsg = "");
431
454 TypeId AddTraceSource(std::string name,
455 std::string help,
457 std::string callback,
458 SupportLevel supportLevel = SUPPORTED,
459 const std::string& supportMsg = "");
460
466
476 bool LookupAttributeByName(std::string name, AttributeInformation* info) const;
500 TraceSourceInformation* info) const;
501
510 uint16_t GetUid() const;
523 void SetUid(uint16_t uid);
524
526 inline TypeId();
531 inline TypeId(const TypeId& o);
537 inline TypeId& operator=(const TypeId& o);
539 inline ~TypeId();
540
541 private:
547 friend inline bool operator==(TypeId a, TypeId b);
548 friend inline bool operator!=(TypeId a, TypeId b);
549 friend bool operator<(TypeId a, TypeId b);
556 explicit TypeId(uint16_t tid);
563
565 uint16_t m_tid;
566};
567
576std::ostream& operator<<(std::ostream& os, TypeId tid);
584std::istream& operator>>(std::istream& is, TypeId& tid);
585
593inline bool operator==(TypeId a, TypeId b);
594inline bool operator!=(TypeId a, TypeId b);
595bool operator<(TypeId a, TypeId b);
599
600} // namespace ns3
601
602namespace ns3
603{
604
606 : m_tid(0)
607{
608}
609
611 : m_tid(o.m_tid)
612{
613}
614
615TypeId&
617{
618 m_tid = o.m_tid;
619 return *this;
620}
621
623{
624}
625
626inline bool
628{
629 return a.m_tid == b.m_tid;
630}
631
632inline bool
634{
635 return a.m_tid != b.m_tid;
636}
637
638/*************************************************************************
639 * The TypeId implementation which depends on templates
640 *************************************************************************/
641
642template <typename T>
643TypeId
645{
646 return SetParent(T::GetTypeId());
647}
648
649template <typename T>
650TypeId
652{
653 struct Maker
654 {
655 static ObjectBase* Create()
656 {
657 ObjectBase* base = new T();
658 return base;
659 }
660 };
661
662 Callback<ObjectBase*> cb = MakeCallback(&Maker::Create);
664 return *this;
665}
666
667} // namespace ns3
668
669#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.
Hold a value for an Attribute.
Definition: attribute.h:70
Callback template class.
Definition: callback.h:438
Anchor the ns-3 type and attribute system.
Definition: object-base.h:173
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:976
friend bool operator!=(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.h:633
std::size_t GetTraceSourceN() const
Get the number of Trace sources.
Definition: type-id.cc:1128
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1081
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:840
bool HasParent() const
Check if this TypeId has a parent.
Definition: type-id.cc:968
TypeId SetSize(std::size_t size)
Set the size of this type.
Definition: type-id.cc:952
hash_t GetHash() const
Get the hash.
Definition: type-id.cc:1004
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:1142
bool MustHideFromDocumentation() const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:1097
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:872
TypeId::TraceSourceInformation GetTraceSource(std::size_t i) const
Get the trace source by index.
Definition: type-id.cc:1135
std::string GetGroupName() const
Get the group name.
Definition: type-id.cc:988
TypeId HideFromDocumentation()
Hide this TypeId from documentation.
Definition: type-id.cc:1156
Callback< ObjectBase * > GetConstructor() const
Get the constructor callback.
Definition: type-id.cc:1089
static uint16_t GetRegisteredN()
Get the number of registered TypeIds.
Definition: type-id.cc:884
std::string GetAttributeFullName(std::size_t i) const
Get the Attribute name by index.
Definition: type-id.cc:1120
bool HasConstructor() const
Check if this TypeId has a constructor.
Definition: type-id.cc:1019
std::size_t GetAttributeN() const
Get the number of attributes.
Definition: type-id.cc:1105
TypeId GetParent() const
Get the parent of this TypeId.
Definition: type-id.cc:960
TypeId AddConstructor()
Record in this TypeId the fact that the default constructor is accessible.
Definition: type-id.h:651
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
Definition: type-id.cc:1217
uint16_t m_tid
The TypeId value.
Definition: type-id.h:565
TypeId SetGroupName(std::string groupName)
Set the group name.
Definition: type-id.cc:944
static TypeId LookupByHash(hash_t hash)
Get a TypeId by hash.
Definition: type-id.cc:862
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:891
friend bool operator==(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.h:627
std::size_t GetSize() const
Get the size of this object.
Definition: type-id.cc:1011
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
Definition: type-id.cc:1203
TypeId & operator=(const TypeId &o)
Assignment.
Definition: type-id.h:616
~TypeId()
Destructor.
Definition: type-id.h:622
friend bool operator<(TypeId a, TypeId b)
Comparison operator.
Definition: type-id.cc:1258
uint32_t hash_t
Type of hash values.
Definition: type-id.h:120
TypeId()
Default constructor.
Definition: type-id.h:605
TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1113
uint16_t GetUid() const
Get the internal id of this TypeId.
Definition: type-id.cc:1210
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:849
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:1034
bool LookupAttributeByName(std::string name, AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Definition: type-id.cc:898
std::string GetName() const
Get the name.
Definition: type-id.cc:996
TypeId SetParent()
Set the parent TypeId.
Definition: type-id.h:644
void DoAddConstructor(Callback< ObjectBase * > callback)
Implementation for AddConstructor().
Definition: type-id.cc:1027
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition: ptr.h:481
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:676
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:702
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:153
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
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.