core (fixes #565): Change TypeId constructor to accept std::string

This commit is contained in:
Eduardo Almeida
2022-02-25 12:08:10 +00:00
committed by Tommaso Pecorella
parent d6e0211bff
commit a4d174f8bf
12 changed files with 23 additions and 23 deletions

View File

@@ -810,7 +810,7 @@ namespace ns3 {
* The TypeId class
*********************************************************************/
TypeId::TypeId (const char *name)
TypeId::TypeId (const std::string &name)
{
NS_LOG_FUNCTION (this << name);
uint16_t uid = IidManager::Get ()->AllocateUid (name);

View File

@@ -176,7 +176,7 @@ public:
* No two instances can share the same name. The name is expected to be
* the full c++ typename of associated c++ object.
*/
explicit TypeId (const char * name);
explicit TypeId (const std::string &name);
/**
* Get the parent of this TypeId.

View File

@@ -168,8 +168,8 @@ CollisionTestCase::DoRun (void)
<< "'" << t1Name << "', '" << t2Name << "'"
<< " in alphabetical order:"
<< endl;
TypeId t1 (t1Name.c_str ());
TypeId t2 (t2Name.c_str ());
TypeId t1 (t1Name);
TypeId t2 (t2Name);
// Check that they are alphabetical: t1 name < t2 name
NS_TEST_ASSERT_MSG_EQ ( (t1.GetHash () & HashChainFlag), 0,

View File

@@ -124,7 +124,7 @@ HistoryHeader<N>::GetTypeId (void)
{
std::ostringstream oss;
oss << "ns3::HistoryHeader<"<<N<<">";
static TypeId tid = TypeId (oss.str ().c_str ())
static TypeId tid = TypeId (oss.str ())
.SetParent<HistoryHeaderBase> ()
.AddConstructor<HistoryHeader<N> > ()
;
@@ -261,7 +261,7 @@ HistoryTrailer<N>::GetTypeId (void)
{
std::ostringstream oss;
oss << "ns3::HistoryTrailer<"<<N<<">";
static TypeId tid = TypeId (oss.str ().c_str ())
static TypeId tid = TypeId (oss.str ())
.SetParent<HistoryTrailerBase> ()
.AddConstructor<HistoryTrailer<N> > ()
;

View File

@@ -92,7 +92,7 @@ public:
static TypeId GetTypeId (void) {
std::ostringstream oss;
oss << "anon::ATestTag<" << N << ">";
static TypeId tid = TypeId (oss.str ().c_str ())
static TypeId tid = TypeId (oss.str ())
.SetParent<ATestTagBase> ()
.SetGroupName ("Network")
.HideFromDocumentation ()
@@ -250,7 +250,7 @@ public:
static TypeId GetTypeId (void) {
std::ostringstream oss;
oss << "anon::ATestHeader<" << N << ">";
static TypeId tid = TypeId (oss.str ().c_str ())
static TypeId tid = TypeId (oss.str ())
.SetParent<ATestHeaderBase> ()
.SetGroupName ("Network")
.HideFromDocumentation ()
@@ -336,7 +336,7 @@ public:
static TypeId GetTypeId (void) {
std::ostringstream oss;
oss << "anon::ATestTrailer<" << N << ">";
static TypeId tid = TypeId (oss.str ().c_str ())
static TypeId tid = TypeId (oss.str ())
.SetParent<ATestTrailerBase> ()
.SetGroupName ("Network")
.HideFromDocumentation ()

View File

@@ -71,7 +71,7 @@ template <typename Item>
TypeId
DropTailQueue<Item>::GetTypeId (void)
{
static TypeId tid = TypeId (("ns3::DropTailQueue<" + GetTypeParamName<DropTailQueue<Item> > () + ">").c_str ())
static TypeId tid = TypeId ("ns3::DropTailQueue<" + GetTypeParamName<DropTailQueue<Item> > () + ">")
.SetParent<Queue<Item> > ()
.SetGroupName ("Network")
.template AddConstructor<DropTailQueue<Item> > ()

View File

@@ -465,7 +465,7 @@ TypeId
Queue<Item>::GetTypeId (void)
{
std::string name = GetTypeParamName<Queue<Item> > ();
static TypeId tid = TypeId (("ns3::Queue<" + name + ">").c_str ())
static TypeId tid = TypeId ("ns3::Queue<" + name + ">")
.SetParent<QueueBase> ()
.SetGroupName ("Network")
.AddTraceSource ("Enqueue", "Enqueue a packet in the queue.",

View File

@@ -33,7 +33,7 @@ template <typename T>
NixVectorHelper<T>::NixVectorHelper ()
{
std::string name = (IsIpv4::value ? "Ipv4" : "Ipv6");
m_agentFactory.SetTypeId (("ns3::" + name + "NixVectorRouting").c_str ());
m_agentFactory.SetTypeId ("ns3::" + name + "NixVectorRouting");
}
template <typename T>

View File

@@ -56,7 +56,7 @@ NixVectorRouting<T>::GetTypeId (void)
{
std::string Tname = GetTypeParamName<NixVectorRouting<T> > ();
std::string name = (Tname == "Ipv4RoutingProtocol" ? "Ipv4" : "Ipv6");
static TypeId tid = TypeId (("ns3::" + name + "NixVectorRouting").c_str ())
static TypeId tid = TypeId ("ns3::" + name + "NixVectorRouting")
.SetParent<T> ()
.SetGroupName ("NixVectorRouting")
.template AddConstructor<NixVectorRouting<T> > ()

View File

@@ -163,9 +163,9 @@ template <typename T>
TypeId
MinMaxAvgTotalCalculator<T>::GetTypeId (void)
{
static TypeId tid = TypeId ( ("ns3::MinMaxAvgTotalCalculator<"
+ TypeNameGet<T> ()
+ ">").c_str () )
static TypeId tid = TypeId ("ns3::MinMaxAvgTotalCalculator<"
+ TypeNameGet<T> ()
+ ">")
.SetParent<Object> ()
.SetGroupName ("Stats")
.AddConstructor<MinMaxAvgTotalCalculator<T> > ()
@@ -329,9 +329,9 @@ template <typename T>
TypeId
CounterCalculator<T>::GetTypeId (void)
{
static TypeId tid = TypeId ( ("ns3::CounterCalculator<"
+ TypeNameGet<T> ()
+ ">").c_str () )
static TypeId tid = TypeId ("ns3::CounterCalculator<"
+ TypeNameGet<T> ()
+ ">")
.SetParent<Object> ()
.SetGroupName ("Stats")
.AddConstructor<CounterCalculator<T> > ()

View File

@@ -169,12 +169,12 @@ private:
static TypeId GetTypeId (void)
{
static TypeId tid =
TypeId ( ("CheckTvCb<" + TypeName<T>() + ">").c_str ())
TypeId ("CheckTvCb<" + TypeName<T>() + ">")
.SetParent <Object> ()
.AddTraceSource ("value",
"A value being traced.",
MakeTraceSourceAccessor (&CheckTvCb<T>::m_value),
("ns3::TracedValueCallback::" + TypeName<T>()).c_str () )
("ns3::TracedValueCallback::" + TypeName<T>()) )
;
return tid;
} // GetTypeId ()

View File

@@ -94,7 +94,7 @@ template <int N>
TypeId
BenchHeader<N>::GetTypeId (void)
{
static TypeId tid = TypeId (GetTypeName ().c_str ())
static TypeId tid = TypeId (GetTypeName ())
.SetParent<Header> ()
.SetGroupName ("Utils")
.HideFromDocumentation ()
@@ -161,7 +161,7 @@ public:
* \return The TypeId.
*/
static TypeId GetTypeId (void) {
static TypeId tid = TypeId (GetName ().c_str ())
static TypeId tid = TypeId (GetName ())
.SetParent<Tag> ()
.SetGroupName ("Utils")
.HideFromDocumentation ()