From a4d174f8bf1de720dddf28eb3f6bea600ebf5d12 Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Fri, 25 Feb 2022 12:08:10 +0000 Subject: [PATCH] core (fixes #565): Change TypeId constructor to accept std::string --- src/core/model/type-id.cc | 2 +- src/core/model/type-id.h | 2 +- src/core/test/type-id-test-suite.cc | 4 ++-- src/network/test/packet-metadata-test.cc | 4 ++-- src/network/test/packet-test-suite.cc | 6 +++--- src/network/utils/drop-tail-queue.h | 2 +- src/network/utils/queue.h | 2 +- src/nix-vector-routing/helper/nix-vector-helper.cc | 2 +- src/nix-vector-routing/model/nix-vector-routing.cc | 2 +- src/stats/model/basic-data-calculators.h | 12 ++++++------ .../traced-value-callback-typedef-test-suite.cc | 4 ++-- utils/bench-packets.cc | 4 ++-- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/core/model/type-id.cc b/src/core/model/type-id.cc index b80a79015..d11ced560 100644 --- a/src/core/model/type-id.cc +++ b/src/core/model/type-id.cc @@ -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); diff --git a/src/core/model/type-id.h b/src/core/model/type-id.h index c2d3cb7f4..582acfd23 100644 --- a/src/core/model/type-id.h +++ b/src/core/model/type-id.h @@ -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. diff --git a/src/core/test/type-id-test-suite.cc b/src/core/test/type-id-test-suite.cc index 943920168..e2d5cc67d 100644 --- a/src/core/test/type-id-test-suite.cc +++ b/src/core/test/type-id-test-suite.cc @@ -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, diff --git a/src/network/test/packet-metadata-test.cc b/src/network/test/packet-metadata-test.cc index 5f1567b5e..9ac18c599 100644 --- a/src/network/test/packet-metadata-test.cc +++ b/src/network/test/packet-metadata-test.cc @@ -124,7 +124,7 @@ HistoryHeader::GetTypeId (void) { std::ostringstream oss; oss << "ns3::HistoryHeader<"<"; - static TypeId tid = TypeId (oss.str ().c_str ()) + static TypeId tid = TypeId (oss.str ()) .SetParent () .AddConstructor > () ; @@ -261,7 +261,7 @@ HistoryTrailer::GetTypeId (void) { std::ostringstream oss; oss << "ns3::HistoryTrailer<"<"; - static TypeId tid = TypeId (oss.str ().c_str ()) + static TypeId tid = TypeId (oss.str ()) .SetParent () .AddConstructor > () ; diff --git a/src/network/test/packet-test-suite.cc b/src/network/test/packet-test-suite.cc index 385aa74ee..403f0e755 100644 --- a/src/network/test/packet-test-suite.cc +++ b/src/network/test/packet-test-suite.cc @@ -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 () .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 () .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 () .SetGroupName ("Network") .HideFromDocumentation () diff --git a/src/network/utils/drop-tail-queue.h b/src/network/utils/drop-tail-queue.h index 3ea5774fa..4401cb344 100644 --- a/src/network/utils/drop-tail-queue.h +++ b/src/network/utils/drop-tail-queue.h @@ -71,7 +71,7 @@ template TypeId DropTailQueue::GetTypeId (void) { - static TypeId tid = TypeId (("ns3::DropTailQueue<" + GetTypeParamName > () + ">").c_str ()) + static TypeId tid = TypeId ("ns3::DropTailQueue<" + GetTypeParamName > () + ">") .SetParent > () .SetGroupName ("Network") .template AddConstructor > () diff --git a/src/network/utils/queue.h b/src/network/utils/queue.h index 3814657ba..f26732b77 100644 --- a/src/network/utils/queue.h +++ b/src/network/utils/queue.h @@ -465,7 +465,7 @@ TypeId Queue::GetTypeId (void) { std::string name = GetTypeParamName > (); - static TypeId tid = TypeId (("ns3::Queue<" + name + ">").c_str ()) + static TypeId tid = TypeId ("ns3::Queue<" + name + ">") .SetParent () .SetGroupName ("Network") .AddTraceSource ("Enqueue", "Enqueue a packet in the queue.", diff --git a/src/nix-vector-routing/helper/nix-vector-helper.cc b/src/nix-vector-routing/helper/nix-vector-helper.cc index 4c8462046..bca4cd678 100644 --- a/src/nix-vector-routing/helper/nix-vector-helper.cc +++ b/src/nix-vector-routing/helper/nix-vector-helper.cc @@ -33,7 +33,7 @@ template NixVectorHelper::NixVectorHelper () { std::string name = (IsIpv4::value ? "Ipv4" : "Ipv6"); - m_agentFactory.SetTypeId (("ns3::" + name + "NixVectorRouting").c_str ()); + m_agentFactory.SetTypeId ("ns3::" + name + "NixVectorRouting"); } template diff --git a/src/nix-vector-routing/model/nix-vector-routing.cc b/src/nix-vector-routing/model/nix-vector-routing.cc index 4e80f8245..3504a7670 100644 --- a/src/nix-vector-routing/model/nix-vector-routing.cc +++ b/src/nix-vector-routing/model/nix-vector-routing.cc @@ -56,7 +56,7 @@ NixVectorRouting::GetTypeId (void) { std::string Tname = GetTypeParamName > (); std::string name = (Tname == "Ipv4RoutingProtocol" ? "Ipv4" : "Ipv6"); - static TypeId tid = TypeId (("ns3::" + name + "NixVectorRouting").c_str ()) + static TypeId tid = TypeId ("ns3::" + name + "NixVectorRouting") .SetParent () .SetGroupName ("NixVectorRouting") .template AddConstructor > () diff --git a/src/stats/model/basic-data-calculators.h b/src/stats/model/basic-data-calculators.h index db3947608..3e8264480 100644 --- a/src/stats/model/basic-data-calculators.h +++ b/src/stats/model/basic-data-calculators.h @@ -163,9 +163,9 @@ template TypeId MinMaxAvgTotalCalculator::GetTypeId (void) { - static TypeId tid = TypeId ( ("ns3::MinMaxAvgTotalCalculator<" - + TypeNameGet () - + ">").c_str () ) + static TypeId tid = TypeId ("ns3::MinMaxAvgTotalCalculator<" + + TypeNameGet () + + ">") .SetParent () .SetGroupName ("Stats") .AddConstructor > () @@ -329,9 +329,9 @@ template TypeId CounterCalculator::GetTypeId (void) { - static TypeId tid = TypeId ( ("ns3::CounterCalculator<" - + TypeNameGet () - + ">").c_str () ) + static TypeId tid = TypeId ("ns3::CounterCalculator<" + + TypeNameGet () + + ">") .SetParent () .SetGroupName ("Stats") .AddConstructor > () diff --git a/src/test/traced/traced-value-callback-typedef-test-suite.cc b/src/test/traced/traced-value-callback-typedef-test-suite.cc index 8e6754701..3758ace11 100644 --- a/src/test/traced/traced-value-callback-typedef-test-suite.cc +++ b/src/test/traced/traced-value-callback-typedef-test-suite.cc @@ -169,12 +169,12 @@ private: static TypeId GetTypeId (void) { static TypeId tid = - TypeId ( ("CheckTvCb<" + TypeName() + ">").c_str ()) + TypeId ("CheckTvCb<" + TypeName() + ">") .SetParent () .AddTraceSource ("value", "A value being traced.", MakeTraceSourceAccessor (&CheckTvCb::m_value), - ("ns3::TracedValueCallback::" + TypeName()).c_str () ) + ("ns3::TracedValueCallback::" + TypeName()) ) ; return tid; } // GetTypeId () diff --git a/utils/bench-packets.cc b/utils/bench-packets.cc index bb3b92c36..c4404820d 100644 --- a/utils/bench-packets.cc +++ b/utils/bench-packets.cc @@ -94,7 +94,7 @@ template TypeId BenchHeader::GetTypeId (void) { - static TypeId tid = TypeId (GetTypeName ().c_str ()) + static TypeId tid = TypeId (GetTypeName ()) .SetParent
() .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 () .SetGroupName ("Utils") .HideFromDocumentation ()