From 9849b4cea66d131b326dec486cde6942a412e8ae Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 21 Feb 2008 19:46:39 +0100 Subject: [PATCH] Object::Set/Get -> Object::SetAttribute/GetAttribute --- src/core/attribute-test.cc | 105 +++++++++++++++++------------------- src/core/object.cc | 6 +-- src/core/object.h | 8 +-- src/node/drop-tail-queue.cc | 2 +- 4 files changed, 58 insertions(+), 63 deletions(-) diff --git a/src/core/attribute-test.cc b/src/core/attribute-test.cc index e75b422b5..92a61928f 100644 --- a/src/core/attribute-test.cc +++ b/src/core/attribute-test.cc @@ -144,7 +144,7 @@ private: { \ std::string expected = value; \ std::string got; \ - bool ok = p->Get (name, got); \ + bool ok = p->GetAttribute (name, got); \ NS_TEST_ASSERT (ok); \ NS_TEST_ASSERT_EQUAL (got, expected); \ } @@ -152,7 +152,7 @@ private: { \ const type expected = value; \ type got = value; \ - Attribute v = p->Get (name); \ + Attribute v = p->GetAttribute (name); \ got = v; \ NS_TEST_ASSERT_EQUAL (got.Get (), expected.Get ()); \ } @@ -174,11 +174,11 @@ AttributeTest::RunTests (void) CHECK_GET_STR (p, "TestBoolName", "false"); CHECK_GET_PARAM (p, "TestBoolName", Boolean, false); - NS_TEST_ASSERT (p->Set ("TestBoolName", "true")); + NS_TEST_ASSERT (p->SetAttribute("TestBoolName", "true")); CHECK_GET_STR (p, "TestBoolName", "true"); CHECK_GET_PARAM (p, "TestBoolName", Boolean, true); - NS_TEST_ASSERT (p->Set ("TestBoolName", Boolean (false))); + NS_TEST_ASSERT (p->SetAttribute("TestBoolName", Boolean (false))); CHECK_GET_STR (p, "TestBoolName", "false"); CHECK_GET_PARAM (p, "TestBoolName", Boolean, false); @@ -190,168 +190,163 @@ AttributeTest::RunTests (void) CHECK_GET_STR (p, "TestBoolName", "true"); CHECK_GET_PARAM (p, "TestBoolName", Boolean, true); - NS_TEST_ASSERT (p->Set ("TestBoolA", "false")); + NS_TEST_ASSERT (p->SetAttribute("TestBoolA", "false")); CHECK_GET_STR (p, "TestBoolA", "false"); CHECK_GET_PARAM (p, "TestBoolA", Boolean, false); - NS_TEST_ASSERT (p->Set ("TestBoolA", "true")); + NS_TEST_ASSERT (p->SetAttribute("TestBoolA", "true")); CHECK_GET_STR (p, "TestBoolA", "true"); CHECK_GET_PARAM (p, "TestBoolA", Boolean, true); - Ptr derived = p->Get ("TestPtr"); + Ptr derived = p->GetAttribute ("TestPtr"); NS_TEST_ASSERT (derived == 0); derived = Create (); - NS_TEST_ASSERT (p->Set ("TestPtr", derived)); - Ptr stored = p->Get ("TestPtr"); + NS_TEST_ASSERT (p->SetAttribute("TestPtr", derived)); + Ptr stored = p->GetAttribute ("TestPtr"); NS_TEST_ASSERT (stored == derived); - Ptr storedBase = p->Get ("TestPtr"); + Ptr storedBase = p->GetAttribute ("TestPtr"); NS_TEST_ASSERT (stored == storedBase); - Ptr x = p->Get ("TestPtr"); + Ptr x = p->GetAttribute ("TestPtr"); NS_TEST_ASSERT (x == 0); p = CreateObjectWith ("TestPtr", Create ()); NS_TEST_ASSERT (p != 0); derived = 0; - derived = p->Get ("TestPtr"); + derived = p->GetAttribute ("TestPtr"); NS_TEST_ASSERT (derived != 0); CHECK_GET_STR (p, "TestInt16", "-2"); CHECK_GET_PARAM (p, "TestInt16", Integer, -2); - NS_TEST_ASSERT (p->Set ("TestInt16", "-5")); + NS_TEST_ASSERT (p->SetAttribute("TestInt16", "-5")); CHECK_GET_STR (p, "TestInt16", "-5"); CHECK_GET_PARAM (p, "TestInt16", Integer, -5); - NS_TEST_ASSERT (p->Set ("TestInt16", Integer (+2))); + NS_TEST_ASSERT (p->SetAttribute("TestInt16", Integer (+2))); CHECK_GET_STR (p, "TestInt16", "2"); CHECK_GET_PARAM (p, "TestInt16", Integer, +2); - NS_TEST_ASSERT (p->Set ("TestInt16", Integer (-32768))); + NS_TEST_ASSERT (p->SetAttribute("TestInt16", Integer (-32768))); CHECK_GET_STR (p, "TestInt16", "-32768"); CHECK_GET_PARAM (p, "TestInt16", Integer, -32768); - NS_TEST_ASSERT (!p->Set ("TestInt16", Integer (-32769))); + NS_TEST_ASSERT (!p->SetAttribute("TestInt16", Integer (-32769))); CHECK_GET_STR (p, "TestInt16", "-32768"); CHECK_GET_PARAM (p, "TestInt16", Integer, -32768); - NS_TEST_ASSERT (p->Set ("TestInt16", Integer (32767))); + NS_TEST_ASSERT (p->SetAttribute("TestInt16", Integer (32767))); CHECK_GET_STR (p, "TestInt16", "32767"); CHECK_GET_PARAM (p, "TestInt16", Integer, 32767); - NS_TEST_ASSERT (!p->Set ("TestInt16", Integer (32768))); + NS_TEST_ASSERT (!p->SetAttribute("TestInt16", Integer (32768))); CHECK_GET_STR (p, "TestInt16", "32767"); CHECK_GET_PARAM (p, "TestInt16", Integer, 32767); - NS_TEST_ASSERT (p->Set ("TestInt16WithBounds", Integer (10))); + NS_TEST_ASSERT (p->SetAttribute("TestInt16WithBounds", Integer (10))); CHECK_GET_STR (p, "TestInt16WithBounds", "10"); CHECK_GET_PARAM (p, "TestInt16WithBounds", Integer, 10); - NS_TEST_ASSERT (!p->Set ("TestInt16WithBounds", Integer (11))); + NS_TEST_ASSERT (!p->SetAttribute("TestInt16WithBounds", Integer (11))); CHECK_GET_STR (p, "TestInt16WithBounds", "10"); CHECK_GET_PARAM (p, "TestInt16WithBounds", Integer, 10); - NS_TEST_ASSERT (p->Set ("TestInt16WithBounds", Integer (-5))); + NS_TEST_ASSERT (p->SetAttribute("TestInt16WithBounds", Integer (-5))); CHECK_GET_STR (p, "TestInt16WithBounds", "-5"); CHECK_GET_PARAM (p, "TestInt16WithBounds", Integer, -5); - NS_TEST_ASSERT (!p->Set ("TestInt16WithBounds", Integer (-6))); + NS_TEST_ASSERT (!p->SetAttribute("TestInt16WithBounds", Integer (-6))); CHECK_GET_STR (p, "TestInt16WithBounds", "-5"); CHECK_GET_PARAM (p, "TestInt16WithBounds", Integer, -5); CHECK_GET_STR (p, "TestInt16SetGet", "6"); CHECK_GET_PARAM (p, "TestInt16SetGet", Integer, 6); - NS_TEST_ASSERT (p->Set ("TestInt16SetGet", Integer (0))); + NS_TEST_ASSERT (p->SetAttribute("TestInt16SetGet", Integer (0))); CHECK_GET_STR (p, "TestInt16SetGet", "0"); CHECK_GET_PARAM (p, "TestInt16SetGet", Integer, 0); CHECK_GET_STR (p, "TestUint8", "1"); CHECK_GET_PARAM (p, "TestUint8", Uinteger, 1); - NS_TEST_ASSERT (p->Set ("TestUint8", Uinteger (0))); + NS_TEST_ASSERT (p->SetAttribute("TestUint8", Uinteger (0))); CHECK_GET_STR (p, "TestUint8", "0"); CHECK_GET_PARAM (p, "TestUint8", Uinteger, 0); - NS_TEST_ASSERT (p->Set ("TestUint8", Uinteger (255))); + NS_TEST_ASSERT (p->SetAttribute("TestUint8", Uinteger (255))); CHECK_GET_STR (p, "TestUint8", "255"); CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); - NS_TEST_ASSERT (p->Set ("TestUint8", "255")); + NS_TEST_ASSERT (p->SetAttribute("TestUint8", "255")); CHECK_GET_STR (p, "TestUint8", "255"); CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); - NS_TEST_ASSERT (!p->Set ("TestUint8", "256")); + NS_TEST_ASSERT (!p->SetAttribute("TestUint8", "256")); CHECK_GET_STR (p, "TestUint8", "255"); CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); - NS_TEST_ASSERT (!p->Set ("TestUint8", "-1")); + NS_TEST_ASSERT (!p->SetAttribute("TestUint8", "-1")); CHECK_GET_STR (p, "TestUint8", "255"); CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); - NS_TEST_ASSERT (!p->Set ("TestUint8", Uinteger (-1))); + NS_TEST_ASSERT (!p->SetAttribute("TestUint8", Uinteger (-1))); CHECK_GET_STR (p, "TestUint8", "255"); CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); CHECK_GET_STR (p, "TestFloat", "-1.1"); - NS_TEST_ASSERT (p->Set ("TestFloat", Double ((float)+2.3))); + NS_TEST_ASSERT (p->SetAttribute("TestFloat", Double ((float)+2.3))); CHECK_GET_PARAM (p, "TestFloat", Double, (float)+2.3); CHECK_GET_STR (p, "TestEnum", "TestA"); CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_A); - NS_TEST_ASSERT (p->Set ("TestEnum", Enum (AttributeObjectTest::TEST_C))); + NS_TEST_ASSERT (p->SetAttribute("TestEnum", Enum (AttributeObjectTest::TEST_C))); CHECK_GET_STR (p, "TestEnum", "TestC"); CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_C); - NS_TEST_ASSERT (p->Set ("TestEnum", "TestB")); + NS_TEST_ASSERT (p->SetAttribute("TestEnum", "TestB")); CHECK_GET_STR (p, "TestEnum", "TestB"); CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_B); - NS_TEST_ASSERT (!p->Set ("TestEnum", "TestD")); + NS_TEST_ASSERT (!p->SetAttribute("TestEnum", "TestD")); CHECK_GET_STR (p, "TestEnum", "TestB"); CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_B); - NS_TEST_ASSERT (!p->Set ("TestEnum", Enum (5))); + NS_TEST_ASSERT (!p->SetAttribute("TestEnum", Enum (5))); CHECK_GET_STR (p, "TestEnum", "TestB"); CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_B); - RandomVariable ran = p->Get ("TestRandom"); - NS_TEST_ASSERT (p->Set ("TestRandom", UniformVariable (0.0, 1.0))); - NS_TEST_ASSERT (p->Set ("TestRandom", ConstantVariable (10.0))); + RandomVariable ran = p->GetAttribute ("TestRandom"); + NS_TEST_ASSERT (p->SetAttribute("TestRandom", UniformVariable (0.0, 1.0))); + NS_TEST_ASSERT (p->SetAttribute("TestRandom", ConstantVariable (10.0))); { - ObjectVector vector = p->Get ("TestVector1"); + ObjectVector vector = p->GetAttribute ("TestVector1"); NS_TEST_ASSERT_EQUAL (vector.GetN (), 0); p->AddToVector1 (); NS_TEST_ASSERT_EQUAL (vector.GetN (), 0); - vector = p->Get ("TestVector1"); + vector = p->GetAttribute ("TestVector1"); NS_TEST_ASSERT_EQUAL (vector.GetN (), 1); Ptr a = vector.Get (0); NS_TEST_ASSERT_UNEQUAL (a, 0); p->AddToVector1 (); NS_TEST_ASSERT_EQUAL (vector.GetN (), 1); - vector = p->Get ("TestVector1"); + vector = p->GetAttribute ("TestVector1"); NS_TEST_ASSERT_EQUAL (vector.GetN (), 2); } { - ObjectVector vector = p->Get ("TestVector2"); + ObjectVector vector = p->GetAttribute ("TestVector2"); NS_TEST_ASSERT_EQUAL (vector.GetN (), 0); p->AddToVector2 (); NS_TEST_ASSERT_EQUAL (vector.GetN (), 0); - vector = p->Get ("TestVector2"); + vector = p->GetAttribute ("TestVector2"); NS_TEST_ASSERT_EQUAL (vector.GetN (), 1); Ptr a = vector.Get (0); NS_TEST_ASSERT_UNEQUAL (a, 0); p->AddToVector2 (); NS_TEST_ASSERT_EQUAL (vector.GetN (), 1); - vector = p->Get ("TestVector2"); + vector = p->GetAttribute ("TestVector2"); NS_TEST_ASSERT_EQUAL (vector.GetN (), 2); } - -#if 0 - p->Set ("TestBool"TestVector2"", "true"); - NS_TEST_ASSERT_EQUAL (p->Get ("TestBool"), "true"); - p->Set ("TestBool", "false"); - NS_TEST_ASSERT_EQUAL (p->Get ("TestBool"), "false"); - - AttributeList::GetGlobal ()->Set ("TestBool", "true"); + NS_TEST_ASSERT (AttributeList::GetGlobal ()->Set ("AttributeObjectTest::TestBoolName", "true")); p = CreateObjectWith (); - NS_TEST_ASSERT_EQUAL (p->Get ("TestBool"), "true"); + Boolean boolV = p->GetAttribute ("TestBoolName"); + NS_TEST_ASSERT_EQUAL (boolV, Boolean (true)); - AttributeList::GetGlobal ()->Set ("TestBool", "false"); + NS_TEST_ASSERT (AttributeList::GetGlobal ()->Set ("AttributeObjectTest::TestBoolName", "false")); p = CreateObjectWith (); - NS_TEST_ASSERT_EQUAL (p->Get ("TestBool"), "false"); -#endif + boolV = p->GetAttribute ("TestBoolName"); + NS_TEST_ASSERT_EQUAL (boolV, Boolean (false)); + return result; } diff --git a/src/core/object.cc b/src/core/object.cc index 6ae8fc442..3137d334e 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -980,7 +980,7 @@ Object::DoSet (Ptr spec, Attribute initialValue, return ok; } bool -Object::Set (std::string name, Attribute value) +Object::SetAttribute (std::string name, Attribute value) { struct TypeId::AttributeInfo info; if (!m_tid.LookupAttributeByName (name, &info)) @@ -994,7 +994,7 @@ Object::Set (std::string name, Attribute value) return DoSet (info.accessor, info.initialValue, info.checker, value); } bool -Object::Get (std::string name, std::string &value) const +Object::GetAttribute (std::string name, std::string &value) const { struct TypeId::AttributeInfo info; if (!m_tid.LookupAttributeByName (name, &info)) @@ -1015,7 +1015,7 @@ Object::Get (std::string name, std::string &value) const } Attribute -Object::Get (std::string name) const +Object::GetAttribute (std::string name) const { struct TypeId::AttributeInfo info; if (!m_tid.LookupAttributeByName (name, &info)) diff --git a/src/core/object.h b/src/core/object.h index bd3292fdb..f3ba1a1ca 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -356,21 +356,21 @@ public: * * Set a single attribute. */ - bool Set (std::string name, Attribute value); + bool SetAttribute (std::string name, Attribute value); /** * \param name the name of the attribute to read * \param value a reference to the string where the value of the * attribute should be stored. * \returns true if the requested attribute was found, false otherwise. */ - bool Get (std::string name, std::string &value) const; + bool GetAttribute (std::string name, std::string &value) const; /** * \param name the name of the attribute to read * \param value a reference to the object where the value of the * attribute should be stored. * \returns true if the requested attribute was found, false otherwise. */ - Attribute Get (std::string name) const; + Attribute GetAttribute (std::string name) const; /** * Increment the reference count. This method should not be called @@ -733,7 +733,7 @@ Ptr CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) template Ptr -CreateObjectWith (std::string n1, Attribute v1, +CreateObjectWith (std::string n1 = "", Attribute v1 = Attribute (), std::string n2 = "", Attribute v2 = Attribute ()) { diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index ef285f15a..e6d94a8ea 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -133,7 +133,7 @@ DropTailQueueTest::RunTests (void) bool result = true; Ptr queue = CreateObject (); - NS_TEST_ASSERT (queue->Set ("MaxPackets", Uinteger (3))); + NS_TEST_ASSERT (queue->SetAttribute ("MaxPackets", Uinteger (3))); Ptr p1, p2, p3, p4; p1 = Create ();