From d4cd3c92fd282ac82e64a6159e33288b42edc31d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 9 Apr 2008 11:46:04 -0700 Subject: [PATCH 01/77] Pointer class for primitive type pointer. --- src/core/attribute-test.cc | 24 +++ src/core/pointer.cc | 59 ++++++++ src/core/pointer.h | 297 +++++++++++++++++++++++++++++++++++++ src/core/wscript | 2 + 4 files changed, 382 insertions(+) create mode 100644 src/core/pointer.cc create mode 100644 src/core/pointer.h diff --git a/src/core/attribute-test.cc b/src/core/attribute-test.cc index 9a2a38a4a..bf8edf462 100644 --- a/src/core/attribute-test.cc +++ b/src/core/attribute-test.cc @@ -30,6 +30,7 @@ #include "object-vector.h" #include "traced-value.h" #include "trace-source-accessor.h" +#include "pointer.h" namespace ns3 { @@ -171,6 +172,10 @@ public: MakeTraceSourceAccessor (&AttributeObjectTest::m_cb)) .AddTraceSource ("ValueSource", "help text", MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc)) + .AddAttribute ("Pointer", "XXX", + Pointer (), + MakePointerAccessor (&AttributeObjectTest::m_ptr), + MakePointerChecker ()) ; return tid; @@ -228,6 +233,7 @@ private: TracedValue m_intSrc2; TracedCallback m_cb; TracedValue m_valueSrc; + Ptr m_ptr; }; @@ -481,6 +487,24 @@ AttributeTest::RunTests (void) NS_TEST_ASSERT_EQUAL (m_got2, 1.0); NS_TEST_ASSERT (p->TraceConnectWithoutContext ("ValueSource", MakeCallback (&AttributeTest::NotifySourceValue, this))); + + + derived = Pointer (p->GetAttribute ("Pointer")); + NS_TEST_ASSERT (derived == 0); + derived = Create (); + NS_TEST_ASSERT (p->SetAttributeFailSafe("Pointer", Pointer (derived))); + stored = Pointer (p->GetAttribute ("Pointer")); + NS_TEST_ASSERT (stored == derived); + storedBase = Pointer (p->GetAttribute ("Pointer")); + NS_TEST_ASSERT (stored == storedBase); + x = Pointer (p->GetAttribute ("Pointer")); + NS_TEST_ASSERT (x == 0); + + p = CreateObject ("Pointer", Pointer (Create ())); + NS_TEST_ASSERT (p != 0); + derived = 0; + derived = Pointer (p->GetAttribute ("Pointer")); + NS_TEST_ASSERT (derived != 0); diff --git a/src/core/pointer.cc b/src/core/pointer.cc new file mode 100644 index 000000000..4af0de42a --- /dev/null +++ b/src/core/pointer.cc @@ -0,0 +1,59 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + */ +#include "pointer.h" + +namespace ns3 { + +Pointer::Pointer () + : m_value () +{} + +Pointer::Pointer (Ptr object) + : m_value (object) +{} + +void +Pointer::SetObject (Ptr object) +{ + m_value = object; +} + +Ptr +Pointer::GetObject (void) const +{ + return m_value; +} + +ATTRIBUTE_VALUE_IMPLEMENT (Pointer); +ATTRIBUTE_CONVERTER_IMPLEMENT (Pointer); + +std::ostream & operator << (std::ostream &os, const Pointer &pointer) +{ + os << pointer.GetObject (); + return os; +} +std::istream & operator >> (std::istream &is, Pointer &pointer) +{ + // XXX: This cannot work; + return is; +} + + +} // namespace ns3 diff --git a/src/core/pointer.h b/src/core/pointer.h new file mode 100644 index 000000000..c9183f041 --- /dev/null +++ b/src/core/pointer.h @@ -0,0 +1,297 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + */ +#ifndef NS_POINTER_H +#define NS_POINTER_H + +#include "attribute.h" +#include "object.h" + +namespace ns3 { + +class Pointer +{ +public: + Pointer (); + + Pointer (Ptr object); + + void SetObject (Ptr object); + + Ptr GetObject (void) const; + + template + Pointer (const Ptr &object); + + template + void Set (const Ptr &object); + + template + Ptr Get (void) const; + + template + operator Ptr () const; + + ATTRIBUTE_CONVERTER_DEFINE (Pointer); +private: + Ptr m_value; +}; + +std::ostream & operator << (std::ostream &os, const Pointer &pointer); +std::istream & operator >> (std::istream &is, Pointer &pointer); + +ATTRIBUTE_VALUE_DEFINE (Pointer); + +template +Ptr +MakePointerAccessor (Ptr T::*memberVariable); +template +Ptr +MakePointerAccessor (void (T::*setter) (Ptr)); +template +Ptr +MakePointerAccessor (Ptr (T::*getter) (void) const); +template +Ptr +MakePointerAccessor (void (T::*setter) (Ptr), + Ptr (T::*getter) (void) const); +template +Ptr +MakePointerAccessor (Ptr (T::*getter) (void) const, + void (T::*setter) (Ptr)); + +class PointerChecker : public AttributeChecker {}; +template +Ptr MakePointerChecker (void); + +} // namespace ns3 + +namespace ns3 { + + +namespace internal { + +template +class APointerChecker : public PtrChecker +{ + virtual bool Check (Attribute val) const { + const PointerValue *value = val.DynCast (); + if (value == 0) + { + return false; + } + if (value->Get ().GetObject () == 0) + { + return true; + } + T *ptr = dynamic_cast (PeekPointer (value->Get ().GetObject ())); + if (ptr == 0) + { + return false; + } + return true; + } + virtual std::string GetType (void) const { + // XXX: we should be able to return better information + TypeId tid = T::GetTypeId (); + return "Ptr<" + tid.GetName () + ">"; + } + virtual bool HasTypeConstraints (void) const { + return false; + } + virtual std::string GetTypeConstraints (void) const { + return ""; + } + virtual Attribute Create (void) const { + return Attribute::Create (); + } +}; + +/******************************************************** + * The Accessor associated to + * PointerValue + ********************************************************/ + +template +class PointerAccessor : public AttributeAccessor +{ +public: + virtual ~PointerAccessor () {} + virtual bool Set (ObjectBase * object, Attribute val) const { + T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + const PointerValue *value = val.DynCast (); + if (value == 0) + { + return false; + } + Ptr ptr = dynamic_cast (PeekPointer (value->Get ().GetObject ())); + if (ptr == 0) + { + return false; + } + DoSet (obj, ptr); + return true; + } + virtual bool Get (const ObjectBase * object, Attribute val) const { + const T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + PointerValue *value = val.DynCast (); + if (value == 0) + { + return false; + } + value->Set (Pointer (DoGet (obj))); + return true; + } +private: + virtual void DoSet (T *object, Ptr value) const = 0; + virtual Ptr DoGet (const T *object) const = 0; +}; + +} // namespace internal + + +template +Pointer::Pointer (const Ptr &object) +{ + m_value = object; +} + +template +void +Pointer::Set (const Ptr &object) +{ + m_value = object; +} + +template +Ptr +Pointer::Get (void) const +{ + T *v = dynamic_cast (PeekPointer (m_value)); + return v; +} + +template +Pointer::operator Ptr () const +{ + return Get (); +} + + +template +Ptr +MakePointerAccessor (Ptr T::*memberVariable) +{ + struct MemberVariable : public internal::PointerAccessor + { + Ptr T::*m_memberVariable; + virtual void DoSet (T *object, Ptr value) const { + (object->*m_memberVariable) = value; + } + virtual Ptr DoGet (const T *object) const { + return object->*m_memberVariable; + } + } *spec = new MemberVariable (); + spec->m_memberVariable = memberVariable; + return Ptr (spec, false); +} + +template +Ptr +MakePointerAccessor (void (T::*setter) (Ptr)) +{ + struct MemberMethod : public internal::PointerAccessor + { + void (T::*m_setter) (Ptr); + virtual void DoSet (T *object, Ptr value) const { + (object->*m_setter) (value); + } + virtual Ptr DoGet (const T *object) const { + return 0; + //return (object->*m_getter) (); + } + } *spec = new MemberMethod (); + spec->m_setter = setter; + return Ptr (spec, false); +} + +template +Ptr +MakePointerAccessor (Ptr (T::*getter) (void) const) +{ + struct MemberMethod : public internal::PointerAccessor + { + Ptr (T::*m_getter) (void) const; + virtual void DoSet (T *object, Ptr value) const { + //(object->*m_setter) (value); + } + virtual Ptr DoGet (const T *object) const { + return (object->*m_getter) (); + } + } *spec = new MemberMethod (); + spec->m_getter = getter; + return Ptr (spec, false); +} +template +Ptr +MakePointerAccessor (void (T::*setter) (Ptr), + Ptr (T::*getter) (void) const) +{ + return MakePointerAccessor (getter, setter); +} +template +Ptr +MakePointerAccessor (Ptr (T::*getter) (void) const, + void (T::*setter) (Ptr)) +{ + struct MemberMethod : public internal::PointerAccessor + { + void (T::*m_setter) (Ptr); + Ptr (T::*m_getter) (void) const; + virtual void DoSet (T *object, Ptr value) const { + (object->*m_setter) (value); + } + virtual Ptr DoGet (const T *object) const { + return (object->*m_getter) (); + } + } *spec = new MemberMethod (); + spec->m_setter = setter; + spec->m_getter = getter; + return Ptr (spec, false); +} + +template +Ptr +MakePointerChecker (void) +{ + return Create > (); +} + + +} // namespace ns3 + +#endif /* NS_POINTER_H */ diff --git a/src/core/wscript b/src/core/wscript index 97eed7fd8..21b63b143 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -52,6 +52,7 @@ def build(bld): 'enum.cc', 'double.cc', 'string.cc', + 'pointer.cc', 'object-factory.cc', 'object-vector.cc', 'global-value.cc', @@ -100,6 +101,7 @@ def build(bld): 'double.h', 'enum.h', 'string.h', + 'pointer.h', 'object-factory.h', 'attribute-helper.h', 'global-value.h', From e110fea8ff96af53e730586cf18091bdf569cf87 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 9 Apr 2008 12:15:24 -0700 Subject: [PATCH 02/77] get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class. --- examples/simple-error-model.cc | 4 +- samples/main-attribute-value.cc | 3 +- src/core/attribute-test.cc | 31 +- src/core/attribute.cc | 15 - src/core/attribute.h | 285 ------------------ src/core/config.cc | 20 +- src/core/pointer.h | 2 +- src/devices/csma/csma-net-device.cc | 13 +- .../point-to-point-net-device.cc | 13 +- src/devices/wifi/propagation-loss-model.cc | 7 +- src/devices/wifi/wifi-channel.cc | 13 +- src/devices/wifi/wifi-net-device.cc | 33 +- src/helper/mobility-helper.cc | 5 +- src/mobility/hierarchical-mobility-model.cc | 13 +- .../random-waypoint-mobility-model.cc | 7 +- src/simulator/simulator.cc | 7 +- 16 files changed, 78 insertions(+), 393 deletions(-) diff --git a/examples/simple-error-model.cc b/examples/simple-error-model.cc index 249523391..e455bd62b 100644 --- a/examples/simple-error-model.cc +++ b/examples/simple-error-model.cc @@ -159,7 +159,7 @@ main (int argc, char *argv[]) // specified by the default classId Ptr em = CreateObject ("RanVar", UniformVariable (0.0, 1.0), "ErrorRate", Double (0.001)); - d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", em); + d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", Pointer (em)); // Now, let's use the ListErrorModel and explicitly force a loss // of the packets with pkt-uids = 11 and 17 on node 2, device 0 @@ -169,7 +169,7 @@ main (int argc, char *argv[]) // This time, we'll explicitly create the error model we want Ptr pem = CreateObject (); pem->SetList (sampleList); - d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", pem); + d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", Pointer (pem)); std::ofstream ascii; ascii.open ("simple-error-model.tr"); diff --git a/samples/main-attribute-value.cc b/samples/main-attribute-value.cc index 2a1841951..76fc3216b 100644 --- a/samples/main-attribute-value.cc +++ b/samples/main-attribute-value.cc @@ -24,6 +24,7 @@ #include "ns3/config.h" #include "ns3/uinteger.h" #include "ns3/string.h" +#include "ns3/pointer.h" #include "ns3/simulator.h" #include "ns3/node.h" @@ -87,7 +88,7 @@ main (int argc, char *argv[]) // First, we observe that we can get a pointer to the (base class) // queue via the PointToPointNetDevice attributes, where it is called // TxQueue - Ptr txQueue = net0->GetAttribute ("TxQueue"); + Ptr txQueue = Pointer (net0->GetAttribute ("TxQueue")); // Using the GetObject function, we can perform a safe downcast // to a DropTailQueue, where MaxPackets is a member diff --git a/src/core/attribute-test.cc b/src/core/attribute-test.cc index bf8edf462..af261e891 100644 --- a/src/core/attribute-test.cc +++ b/src/core/attribute-test.cc @@ -109,10 +109,6 @@ public: MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB, &AttributeObjectTest::DoGetTestB), MakeBooleanChecker ()) - .AddAttribute ("TestPtr", "help text", - Ptr (0), - MakePtrAccessor (&AttributeObjectTest::m_derived), - MakePtrChecker ()) .AddAttribute ("TestInt16", "help text", Integer (-2), MakeIntegerAccessor (&AttributeObjectTest::m_int16), @@ -219,7 +215,6 @@ private: } bool m_boolTestA; bool m_boolTest; - Ptr m_derived; int16_t m_int16; int16_t m_int16WithBounds; int16_t m_int16SetGet; @@ -298,23 +293,6 @@ AttributeTest::RunTests (void) CHECK_GET_PARAM (p, "TestBoolA", Boolean, true); - Ptr derived = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (derived == 0); - derived = Create (); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestPtr", derived)); - Ptr stored = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (stored == derived); - Ptr storedBase = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (stored == storedBase); - Ptr x = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (x == 0); - - p = CreateObject ("TestPtr", Create ()); - NS_TEST_ASSERT (p != 0); - derived = 0; - derived = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (derived != 0); - CHECK_GET_STR (p, "TestInt16", "-2"); CHECK_GET_PARAM (p, "TestInt16", Integer, -2); @@ -488,16 +466,15 @@ AttributeTest::RunTests (void) NS_TEST_ASSERT (p->TraceConnectWithoutContext ("ValueSource", MakeCallback (&AttributeTest::NotifySourceValue, this))); - - derived = Pointer (p->GetAttribute ("Pointer")); + Ptrderived = Pointer (p->GetAttribute ("Pointer")); NS_TEST_ASSERT (derived == 0); derived = Create (); NS_TEST_ASSERT (p->SetAttributeFailSafe("Pointer", Pointer (derived))); - stored = Pointer (p->GetAttribute ("Pointer")); + Ptr stored = Pointer (p->GetAttribute ("Pointer")); NS_TEST_ASSERT (stored == derived); - storedBase = Pointer (p->GetAttribute ("Pointer")); + Ptr storedBase = Pointer (p->GetAttribute ("Pointer")); NS_TEST_ASSERT (stored == storedBase); - x = Pointer (p->GetAttribute ("Pointer")); + Ptr x = Pointer (p->GetAttribute ("Pointer")); NS_TEST_ASSERT (x == 0); p = CreateObject ("Pointer", Pointer (Create ())); diff --git a/src/core/attribute.cc b/src/core/attribute.cc index 453a05cb3..3e37f8423 100644 --- a/src/core/attribute.cc +++ b/src/core/attribute.cc @@ -172,19 +172,4 @@ AttributeChecker::Unref (void) const AttributeChecker::~AttributeChecker () {} -std::string -PtrValueBase::SerializeToString (Ptr checker) const -{ - std::ostringstream oss; - oss << PeekObjectBase (); - return oss.str (); -} - -bool -PtrValueBase::DeserializeFromString (std::string value, Ptr checker) -{ - // XXX - return false; -} - } // namespace ns3 diff --git a/src/core/attribute.h b/src/core/attribute.h index 687d772c0..4065e0e5a 100644 --- a/src/core/attribute.h +++ b/src/core/attribute.h @@ -135,17 +135,6 @@ public: template T DynCast (void) const; - /** - * \param pointer a pointer to convert into an Attribute. - */ - template - Attribute (Ptr pointer); - /** - * \returns a pointer converted from this Attribute instance. - */ - template - operator Ptr (); - private: Attribute (AttributeValue *value); AttributeValue *m_value; @@ -231,170 +220,10 @@ private: mutable uint32_t m_count; }; -template -Ptr -MakePtrAccessor (Ptr T::*memberVariable); - -template -Ptr -MakePtrAccessor (void (T::*setter) (Ptr)); -template -Ptr -MakePtrAccessor (Ptr (T::*getter) (void) const); -template -Ptr -MakePtrAccessor (void (T::*setter) (Ptr), - Ptr (T::*getter) (void) const); -template -Ptr -MakePtrAccessor (Ptr (T::*getter) (void) const, - void (T::*setter) (Ptr)); - - - -class PtrChecker : public AttributeChecker {}; - -template -Ptr MakePtrChecker (void); - - - } // namespace ns3 namespace ns3 { -/******************************************************** - * The class used to access the pointer stored in a - * PtrValue AttributeValue instance. - ********************************************************/ - -class PtrValueBase : public AttributeValue -{ -public: - virtual ObjectBase *PeekObjectBase (void) const = 0; - virtual bool SetObjectBase (ObjectBase *object) = 0; - virtual std::string SerializeToString (Ptr checker) const; - virtual bool DeserializeFromString (std::string value, Ptr checker); -}; - -/******************************************************** - * Store the content of a Ptr in a AttributeValue - ********************************************************/ - -namespace internal { - -template -class PtrValue : public PtrValueBase -{ -public: - PtrValue () - : m_pointer () {} - PtrValue (Ptr pointer) - : m_pointer (pointer) {} - - virtual ObjectBase *PeekObjectBase (void) const { - return PeekPointer (m_pointer); - } - virtual bool SetObjectBase (ObjectBase *object) { - T *ptr = dynamic_cast (object); - if (ptr == 0) - { - return false; - } - m_pointer = ptr; - return true; - } - virtual Attribute Copy (void) const { - return Attribute::Create > (*this); - } -private: - Ptr m_pointer; -}; - -template -class APtrChecker : public PtrChecker -{ - virtual bool Check (Attribute val) const { - const PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - if (value->PeekObjectBase () == 0) - { - return true; - } - T *ptr = dynamic_cast (value->PeekObjectBase ()); - if (ptr == 0) - { - return false; - } - return true; - } - virtual std::string GetType (void) const { - // XXX: we should be able to return better information - return "Ptr<>"; - } - virtual bool HasTypeConstraints (void) const { - return false; - } - virtual std::string GetTypeConstraints (void) const { - return ""; - } - virtual Attribute Create (void) const { - return Attribute::Create > (); - } -}; - -/******************************************************** - * The Accessor associated to - * PtrValue - ********************************************************/ - -template -class PtrAccessor : public AttributeAccessor -{ -public: - virtual ~PtrAccessor () {} - virtual bool Set (ObjectBase * object, Attribute val) const { - T *obj = dynamic_cast (object); - if (obj == 0) - { - return false; - } - const PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - Ptr ptr = dynamic_cast (value->PeekObjectBase ()); - if (ptr == 0) - { - return false; - } - DoSet (obj, ptr); - return true; - } - virtual bool Get (const ObjectBase * object, Attribute val) const { - const T *obj = dynamic_cast (object); - if (obj == 0) - { - return false; - } - PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - return value->SetObjectBase (PeekPointer (DoGet (obj))); - } -private: - virtual void DoSet (T *object, Ptr value) const = 0; - virtual Ptr DoGet (const T *object) const = 0; -}; - -} // namespace internal - /******************************************************** * The implementation of the Attribute * class template methods. @@ -420,120 +249,6 @@ Attribute::DynCast (void) const return dynamic_cast (m_value); } -template -Attribute::Attribute (Ptr pointer) - : m_value (new internal::PtrValue (pointer)) -{} -template -Attribute::operator Ptr () -{ - PtrValueBase *value = DynCast (); - if (value == 0) - { - return 0; - } - ObjectBase *objectBase = value->PeekObjectBase (); - T *obj = dynamic_cast (objectBase); - if (obj == 0) - { - return 0; - } - return obj; -} - - - -template -Ptr -MakePtrAccessor (Ptr T::*memberVariable) -{ - struct MemberVariable : public internal::PtrAccessor - { - Ptr T::*m_memberVariable; - virtual void DoSet (T *object, Ptr value) const { - (object->*m_memberVariable) = value; - } - virtual Ptr DoGet (const T *object) const { - return object->*m_memberVariable; - } - } *spec = new MemberVariable (); - spec->m_memberVariable = memberVariable; - return Ptr (spec, false); -} - -template -Ptr -MakePtrAccessor (void (T::*setter) (Ptr)) -{ - struct MemberMethod : public internal::PtrAccessor - { - void (T::*m_setter) (Ptr); - virtual void DoSet (T *object, Ptr value) const { - (object->*m_setter) (value); - } - virtual Ptr DoGet (const T *object) const { - return 0; - //return (object->*m_getter) (); - } - } *spec = new MemberMethod (); - spec->m_setter = setter; - return Ptr (spec, false); -} - -template -Ptr -MakePtrAccessor (Ptr (T::*getter) (void) const) -{ - struct MemberMethod : public internal::PtrAccessor - { - Ptr (T::*m_getter) (void) const; - virtual void DoSet (T *object, Ptr value) const { - //(object->*m_setter) (value); - } - virtual Ptr DoGet (const T *object) const { - return (object->*m_getter) (); - } - } *spec = new MemberMethod (); - spec->m_getter = getter; - return Ptr (spec, false); -} -template -Ptr -MakePtrAccessor (void (T::*setter) (Ptr), - Ptr (T::*getter) (void) const) -{ - return MakePtrAccessor (getter, setter); -} -template -Ptr -MakePtrAccessor (Ptr (T::*getter) (void) const, - void (T::*setter) (Ptr)) -{ - struct MemberMethod : public internal::PtrAccessor - { - void (T::*m_setter) (Ptr); - Ptr (T::*m_getter) (void) const; - virtual void DoSet (T *object, Ptr value) const { - (object->*m_setter) (value); - } - virtual Ptr DoGet (const T *object) const { - return (object->*m_getter) (); - } - } *spec = new MemberMethod (); - spec->m_setter = setter; - spec->m_getter = getter; - return Ptr (spec, false); -} - - - -template -Ptr -MakePtrChecker (void) -{ - return Create > (); -} - } // namespace ns3 #endif /* ATTRIBUTE_H */ diff --git a/src/core/config.cc b/src/core/config.cc index cd47003e8..cf2e75eb0 100644 --- a/src/core/config.cc +++ b/src/core/config.cc @@ -22,6 +22,7 @@ #include "object.h" #include "global-value.h" #include "object-vector.h" +#include "pointer.h" #include "log.h" #include @@ -213,14 +214,11 @@ Resolver::DoResolve (std::string path, Ptr root) return; } // attempt to cast to a pointer checker. - const PtrChecker *ptr = dynamic_cast (PeekPointer (info.checker)); + const PointerChecker *ptr = dynamic_cast (PeekPointer (info.checker)); if (ptr != 0) { NS_LOG_DEBUG ("GetAttribute(ptr)="<. We really need to fix this by thinking seriously about our - // object hierarchy. - Ptr object = root->GetAttribute (item); + Ptr object = Pointer (root->GetAttribute (item)); if (object == 0) { NS_LOG_ERROR ("Requested object name=\""< (0), - MakePtrAccessor (&MyNode::m_nodeA), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&MyNode::m_nodeA), + MakePointerChecker ()) .AddAttribute ("NodeB", "", - Ptr (0), - MakePtrAccessor (&MyNode::m_nodeB), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&MyNode::m_nodeB), + MakePointerChecker ()) .AddAttribute ("A", "", Integer (10), MakeIntegerAccessor (&MyNode::m_a), diff --git a/src/core/pointer.h b/src/core/pointer.h index c9183f041..39e2237cc 100644 --- a/src/core/pointer.h +++ b/src/core/pointer.h @@ -88,7 +88,7 @@ namespace ns3 { namespace internal { template -class APointerChecker : public PtrChecker +class APointerChecker : public PointerChecker { virtual bool Check (Attribute val) const { const PointerValue *value = val.DynCast (); diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 8553dc618..109708a9e 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -27,6 +27,7 @@ #include "ns3/error-model.h" #include "ns3/enum.h" #include "ns3/boolean.h" +#include "ns3/pointer.h" #include "ns3/trace-source-accessor.h" #include "csma-net-device.h" #include "csma-channel.h" @@ -68,13 +69,13 @@ CsmaNetDevice::GetTypeId (void) MakeDataRateAccessor (&CsmaNetDevice::m_bps), MakeDataRateChecker ()) .AddAttribute ("RxErrorModel", "XXX", - Ptr (0), - MakePtrAccessor (&CsmaNetDevice::m_receiveErrorModel), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&CsmaNetDevice::m_receiveErrorModel), + MakePointerChecker ()) .AddAttribute ("TxQueue", "XXX", - Ptr (0), - MakePtrAccessor (&CsmaNetDevice::m_queue), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&CsmaNetDevice::m_queue), + MakePointerChecker ()) .AddTraceSource ("Rx", "Receive MAC packet.", MakeTraceSourceAccessor (&CsmaNetDevice::m_rxTrace)) .AddTraceSource ("Drop", "Drop MAC packet.", diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index 49bbd8551..c154d560c 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -26,6 +26,7 @@ #include "ns3/llc-snap-header.h" #include "ns3/error-model.h" #include "ns3/trace-source-accessor.h" +#include "ns3/pointer.h" #include "point-to-point-net-device.h" #include "point-to-point-channel.h" @@ -50,13 +51,13 @@ PointToPointNetDevice::GetTypeId (void) MakeDataRateAccessor (&PointToPointNetDevice::m_bps), MakeDataRateChecker ()) .AddAttribute ("ReceiveErrorModel", "XXX", - Ptr (0), - MakePtrAccessor (&PointToPointNetDevice::m_receiveErrorModel), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&PointToPointNetDevice::m_receiveErrorModel), + MakePointerChecker ()) .AddAttribute ("TxQueue", "XXX", - Ptr (0), - MakePtrAccessor (&PointToPointNetDevice::m_queue), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&PointToPointNetDevice::m_queue), + MakePointerChecker ()) .AddAttribute ("InterframeGap", "XXX", Seconds (0.0), MakeTimeAccessor (&PointToPointNetDevice::m_tInterframeGap), diff --git a/src/devices/wifi/propagation-loss-model.cc b/src/devices/wifi/propagation-loss-model.cc index e522f0517..c57406a4d 100644 --- a/src/devices/wifi/propagation-loss-model.cc +++ b/src/devices/wifi/propagation-loss-model.cc @@ -22,6 +22,7 @@ #include "ns3/mobility-model.h" #include "ns3/static-mobility-model.h" #include "ns3/double.h" +#include "ns3/pointer.h" #include NS_LOG_COMPONENT_DEFINE ("PropagationLossModel"); @@ -192,9 +193,9 @@ LogDistancePropagationLossModel::GetTypeId (void) MakeDoubleChecker ()) .AddAttribute ("ReferenceModel", "The reference model at the reference distance.", - Ptr (0), - MakePtrAccessor (&LogDistancePropagationLossModel::m_reference), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&LogDistancePropagationLossModel::m_reference), + MakePointerChecker ()) ; return tid; diff --git a/src/devices/wifi/wifi-channel.cc b/src/devices/wifi/wifi-channel.cc index cec9770ad..e527ae985 100644 --- a/src/devices/wifi/wifi-channel.cc +++ b/src/devices/wifi/wifi-channel.cc @@ -23,6 +23,7 @@ #include "ns3/net-device.h" #include "ns3/node.h" #include "ns3/log.h" +#include "ns3/pointer.h" #include "wifi-channel.h" #include "propagation-loss-model.h" #include "propagation-delay-model.h" @@ -38,13 +39,13 @@ WifiChannel::GetTypdId (void) .SetParent () .AddConstructor () .AddAttribute ("PropagationLossModel", "XXX", - Ptr (0), - MakePtrAccessor (&WifiChannel::m_loss), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&WifiChannel::m_loss), + MakePointerChecker ()) .AddAttribute ("PropagationDelayModel", "XXX", - Ptr (0), - MakePtrAccessor (&WifiChannel::m_delay), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&WifiChannel::m_delay), + MakePointerChecker ()) ; return tid; } diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index 8475dcea0..5a0b9a812 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -25,6 +25,7 @@ #include "ns3/llc-snap-header.h" #include "ns3/packet.h" #include "ns3/uinteger.h" +#include "ns3/pointer.h" #include "ns3/node.h" #include "ns3/trace-source-accessor.h" @@ -36,25 +37,25 @@ WifiNetDevice::GetTypeId (void) static TypeId tid = TypeId ("ns3::WifiNetDevice") .SetParent () .AddAttribute ("Channel", "XXX", - Ptr (0), - MakePtrAccessor (&WifiNetDevice::DoGetChannel, - &WifiNetDevice::SetChannel), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&WifiNetDevice::DoGetChannel, + &WifiNetDevice::SetChannel), + MakePointerChecker ()) .AddAttribute ("Phy", "XXX", - Ptr (0), - MakePtrAccessor (&WifiNetDevice::GetPhy, - &WifiNetDevice::SetPhy), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&WifiNetDevice::GetPhy, + &WifiNetDevice::SetPhy), + MakePointerChecker ()) .AddAttribute ("Mac", "XXX", - Ptr (0), - MakePtrAccessor (&WifiNetDevice::GetMac, - &WifiNetDevice::SetMac), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&WifiNetDevice::GetMac, + &WifiNetDevice::SetMac), + MakePointerChecker ()) .AddAttribute ("RemoteStationManager", "XXX", - Ptr (0), - MakePtrAccessor (&WifiNetDevice::SetRemoteStationManager, - &WifiNetDevice::GetRemoteStationManager), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&WifiNetDevice::SetRemoteStationManager, + &WifiNetDevice::GetRemoteStationManager), + MakePointerChecker ()) .AddTraceSource ("Rx", "XXX", MakeTraceSourceAccessor (&WifiNetDevice::m_rxLogger)) .AddTraceSource ("Tx", "XXX", diff --git a/src/helper/mobility-helper.cc b/src/helper/mobility-helper.cc index 94ade79c7..74e728ee4 100644 --- a/src/helper/mobility-helper.cc +++ b/src/helper/mobility-helper.cc @@ -23,6 +23,7 @@ #include "ns3/position-allocator.h" #include "ns3/hierarchical-mobility-model.h" #include "ns3/log.h" +#include "ns3/pointer.h" namespace ns3 { @@ -146,8 +147,8 @@ MobilityHelper::Layout (NodeContainer c) // we need to setup a hierarchical mobility model Ptr parent = m_mobilityStack.back (); Ptr hierarchical = - CreateObject ("Child", model, - "Parent", parent); + CreateObject ("Child", Pointer (model), + "Parent", Pointer (parent)); object->AggregateObject (hierarchical); NS_LOG_DEBUG ("node="< () .AddConstructor () .AddAttribute ("Child", "The child mobility model.", - Ptr (0), - MakePtrAccessor (&HierarchicalMobilityModel::SetChild), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&HierarchicalMobilityModel::SetChild), + MakePointerChecker ()) .AddAttribute ("Parent", "The parent mobility model.", - Ptr (0), - MakePtrAccessor (&HierarchicalMobilityModel::SetParent), - MakePtrChecker ()) + Pointer (), + MakePointerAccessor (&HierarchicalMobilityModel::SetParent), + MakePointerChecker ()) ; return tid; } diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index d5d98e299..dac694dfa 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -20,6 +20,7 @@ #include #include "ns3/simulator.h" #include "ns3/random-variable.h" +#include "ns3/pointer.h" #include "random-waypoint-mobility-model.h" #include "position-allocator.h" @@ -46,9 +47,9 @@ RandomWaypointMobilityModel::GetTypeId (void) MakeRandomVariableChecker ()) .AddAttribute ("Position", "The position model used to pick a destination point.", - Ptr (0), - MakePtrAccessor (&RandomWaypointMobilityModel::m_position), - MakePtrChecker ()); + Pointer (), + MakePointerAccessor (&RandomWaypointMobilityModel::m_position), + MakePointerChecker ()); return tid; } diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index aa2a0be93..0d7a12f8c 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -23,6 +23,7 @@ #include "event-impl.h" #include "ns3/ptr.h" +#include "ns3/pointer.h" #include "ns3/assert.h" @@ -108,10 +109,10 @@ SimulatorPrivate::GetTypeId (void) .AddConstructor () .AddAttribute ("Scheduler", "XXX", - Ptr (0), + Pointer (), // XXX: allow getting the scheduler too. - MakePtrAccessor (&SimulatorPrivate::SetScheduler), - MakePtrChecker ()) + MakePointerAccessor (&SimulatorPrivate::SetScheduler), + MakePointerChecker ()) ; return tid; } From e0570ec0b02992195962e95d96948ab01aec80fb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 9 Apr 2008 13:03:58 -0700 Subject: [PATCH 03/77] add doxygen anchors to avoid warnings. --- src/core/boolean.h | 2 ++ src/core/double.h | 1 + src/core/integer.h | 5 +++++ src/core/uinteger.h | 5 +++++ 4 files changed, 13 insertions(+) diff --git a/src/core/boolean.h b/src/core/boolean.h index 74885e089..81f4de74b 100644 --- a/src/core/boolean.h +++ b/src/core/boolean.h @@ -28,6 +28,8 @@ namespace ns3 { /** * \brief Hold a bool native type * + * \anchor bool + * * This class can be used to hold bool variables * which must go through the Attribute system. */ diff --git a/src/core/double.h b/src/core/double.h index e5ab55bd3..4a7420f96 100644 --- a/src/core/double.h +++ b/src/core/double.h @@ -29,6 +29,7 @@ namespace ns3 { /** * \brief Hold an floating point type * + * \anchor double * This class can be used to hold variables of floating point type * such as 'double' or 'float'. The internal format is 'double'. */ diff --git a/src/core/integer.h b/src/core/integer.h index eab6d7032..cbce92f09 100644 --- a/src/core/integer.h +++ b/src/core/integer.h @@ -29,6 +29,11 @@ namespace ns3 { /** * \brief Hold a signed integer type * + * \anchor int8_t + * \anchor int16_t + * \anchor int32_t + * \anchor int64_t + * * This class can be used to hold variables of signed integer * type such as int8_t, int16_t, int32_t, int64_t, or, * int, etc. diff --git a/src/core/uinteger.h b/src/core/uinteger.h index 3c1503951..7d93e6738 100644 --- a/src/core/uinteger.h +++ b/src/core/uinteger.h @@ -29,6 +29,11 @@ namespace ns3 { /** * \brief Hold an unsigned integer type * + * \anchor uint8_t + * \anchor uint16_t + * \anchor uint32_t + * \anchor uint64_t + * * This class can be used to hold variables of unsigned integer * type such as uint8_t, uint16_t, uint32_t, uint64_t, or, * unsigned int, etc. From 560a34ba9754b77fdc26334c8a9d69bc505e95c4 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 9 Apr 2008 13:04:18 -0700 Subject: [PATCH 04/77] add space to ensure doxygen reference generation. --- src/core/pointer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/pointer.h b/src/core/pointer.h index 39e2237cc..592af2bdf 100644 --- a/src/core/pointer.h +++ b/src/core/pointer.h @@ -110,7 +110,7 @@ class APointerChecker : public PointerChecker virtual std::string GetType (void) const { // XXX: we should be able to return better information TypeId tid = T::GetTypeId (); - return "Ptr<" + tid.GetName () + ">"; + return "Ptr< " + tid.GetName () + " >"; } virtual bool HasTypeConstraints (void) const { return false; From 53fb65aea750197081977f5aeaea0d9f12755a1b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 9 Apr 2008 13:04:37 -0700 Subject: [PATCH 05/77] add doxygen documentation to avoid doxygen warnings. --- src/core/object-vector.h | 6 ++++++ src/devices/wifi/ssid.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/core/object-vector.h b/src/core/object-vector.h index 6f43b8c9f..545d9c6ea 100644 --- a/src/core/object-vector.h +++ b/src/core/object-vector.h @@ -9,6 +9,12 @@ namespace ns3 { +/** + * \brief contain a vector of ns3::Object pointers. + * + * This class it used to get attribute access to an array of + * ns3::Object pointers. + */ class ObjectVector { public: diff --git a/src/devices/wifi/ssid.h b/src/devices/wifi/ssid.h index 5040a6193..f149170c6 100644 --- a/src/devices/wifi/ssid.h +++ b/src/devices/wifi/ssid.h @@ -26,6 +26,10 @@ namespace ns3 { +/** + * \brief a IEEE 802.11 SSID + * + */ class Ssid { public: From cc927f907f0ae9587e9498993f97aa87d16fa604 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 9 Apr 2008 13:05:20 -0700 Subject: [PATCH 06/77] improve type linking behavior. --- utils/print-introspected-doxygen.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/print-introspected-doxygen.cc b/utils/print-introspected-doxygen.cc index 4ec34ea9c..5f8c562c9 100644 --- a/utils/print-introspected-doxygen.cc +++ b/utils/print-introspected-doxygen.cc @@ -12,7 +12,7 @@ PrintAttributes (TypeId tid, std::ostream &os) os << "
  • " << tid.GetAttributeName (j) << ": " << tid.GetAttributeHelp (j) << std::endl; Ptr checker = tid.GetAttributeChecker (j); - os << "