From baca67f7a327fbab6bfee88597ae206b6baeaa95 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 21 Feb 2008 00:54:05 +0100 Subject: [PATCH] fpValue -> Double --- samples/main-grid-topology.cc | 8 ++-- src/core/fp-value.cc | 60 ++++++++++-------------------- src/core/fp-value.h | 47 ++++++++--------------- src/core/value-test.cc | 10 ++--- src/mobility/position-allocator.cc | 36 +++++++++--------- 5 files changed, 63 insertions(+), 98 deletions(-) diff --git a/samples/main-grid-topology.cc b/samples/main-grid-topology.cc index c9c6a655a..4cc1bea50 100644 --- a/samples/main-grid-topology.cc +++ b/samples/main-grid-topology.cc @@ -29,10 +29,10 @@ int main (int argc, char *argv[]) // the x interval between each object is 5 meters // and the y interval between each object is 20 meters mobility.SetPositionAllocator ("GridPositionAllocator", - "MinX", FpValue (-100.0), - "MinY", FpValue (-100.0), - "DeltaX", FpValue (5.0), - "DeltaY", FpValue (20.0), + "MinX", Double (-100.0), + "MinY", Double (-100.0), + "DeltaX", Double (5.0), + "DeltaY", Double (20.0), "GridWidth", Uinteger (20), "LayoutType", "RowFirst"); // each object will be attached a static position. diff --git a/src/core/fp-value.cc b/src/core/fp-value.cc index 935facf89..2a518ca5a 100644 --- a/src/core/fp-value.cc +++ b/src/core/fp-value.cc @@ -4,62 +4,42 @@ namespace ns3 { -FpValue::FpValue (double value) +Double::Double () +{} +Double::Double (double value) : m_value (value) {} -Attribute -FpValue::Copy (void) const -{ - return Attribute::Create (*this); -} - void -FpValue::Set (double value) +Double::Set (double value) { m_value = value; } double -FpValue::Get (void) const +Double::Get (void) const { return m_value; } -std::string -FpValue::SerializeToString (Ptr checker) const +Double::operator double () const { - std::ostringstream oss; - oss << m_value; - return oss.str (); + return m_value; } -bool -FpValue::DeserializeFromString (std::string value, Ptr checker) +std::ostream & operator << (std::ostream &os, const Double &value) +{ + os << value.Get (); + return os; +} +std::istream & operator >> (std::istream &is, Double &value) { double v; - std::istringstream iss; - iss.str (value); - iss >> v; - bool ok = !iss.bad () && !iss.fail (); - if (ok) - { - m_value = v; - } - return ok; + is >> v; + value.Set (v); + return is; } -FpValue::FpValue (Attribute value) -{ - const FpValue *v = value.DynCast (); - if (v == 0) - { - NS_FATAL_ERROR ("assigning non-Fp value to Fp value."); - } - m_value = v->m_value; -} -FpValue::operator Attribute () const -{ - return Attribute::Create (*this); -} +ATTRIBUTE_VALUE_IMPLEMENT (Double); + ATTRIBUTE_CONVERTER_IMPLEMENT (Double); -Ptr MakeFpChecker (double min, double max) +Ptr MakeDoubleChecker (double min, double max) { struct Checker : public AttributeChecker { @@ -67,7 +47,7 @@ Ptr MakeFpChecker (double min, double max) : m_minValue (minValue), m_maxValue (maxValue) {} virtual bool Check (Attribute value) const { - const FpValue *v = value.DynCast (); + const DoubleValue *v = value.DynCast (); if (v == 0) { return false; diff --git a/src/core/fp-value.h b/src/core/fp-value.h index c95691884..e04802aee 100644 --- a/src/core/fp-value.h +++ b/src/core/fp-value.h @@ -2,63 +2,48 @@ #define FP_VALUE_H #include "attribute.h" -#include "param-spec-helper.h" +#include "value-helper.h" #include namespace ns3 { -class FpValue : public AttributeValue +class Double { public: - FpValue (double value); - - virtual Attribute Copy (void) const; - virtual std::string SerializeToString (Ptr checker) const; - virtual bool DeserializeFromString (std::string value, Ptr checker); + Double (); + Double (double value); void Set (double value); double Get (void) const; - FpValue (Attribute value); - operator Attribute () const; + operator double () const; + + ATTRIBUTE_CONVERTER_DEFINE (Double); private: double m_value; }; -class FpAccessor : public AttributeAccessor {}; +std::ostream & operator << (std::ostream &os, const Double &value); +std::istream & operator >> (std::istream &is, Double &value); -template -Ptr MakeFpAccessor (T1 a1); -template -Ptr MakeFpAccessor (T1 a1, T2 a2); +ATTRIBUTE_VALUE_DEFINE (Double); +ATTRIBUTE_ACCESSOR_DEFINE (Double); template -Ptr MakeFpChecker (void); - -Ptr MakeFpChecker (double min, double max); +Ptr MakeDoubleChecker (void); +Ptr MakeDoubleChecker (double min, double max); } // namespace ns3 namespace ns3 { -template -Ptr MakeFpAccessor (T1 a1) -{ - return MakeAccessorHelper (a1); -} -template -Ptr MakeFpAccessor (T1 a1, T2 a2) -{ - return MakeAccessorHelper (a1, a2); -} - template -Ptr MakeFpChecker (void) +Ptr MakeDoubleChecker (void) { - return MakeFpChecker (-std::numeric_limits::max (), - std::numeric_limits::max ()); + return MakeDoubleChecker (-std::numeric_limits::max (), + std::numeric_limits::max ()); } } // namespace ns3 diff --git a/src/core/value-test.cc b/src/core/value-test.cc index 1e68ebfe1..13a5e1b07 100644 --- a/src/core/value-test.cc +++ b/src/core/value-test.cc @@ -82,9 +82,9 @@ public: MakeRandomVariableAccessor (&AccessorObjectTest::m_random), MakeRandomVariableChecker ()) .AddParameter ("TestFloat", "help text", - FpValue (-1.1), - MakeFpAccessor (&AccessorObjectTest::m_float), - MakeFpChecker ()) + Double (-1.1), + MakeDoubleAccessor (&AccessorObjectTest::m_float), + MakeDoubleChecker ()) .AddParameter ("TestVector1", "help text", ObjectVector (), MakeObjectVectorAccessor (&AccessorObjectTest::m_vector1), @@ -285,8 +285,8 @@ AccessorTest::RunTests (void) CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); CHECK_GET_STR (p, "TestFloat", "-1.1"); - NS_TEST_ASSERT (p->Set ("TestFloat", FpValue ((float)+2.3))); - CHECK_GET_PARAM (p, "TestFloat", FpValue, (float)+2.3); + NS_TEST_ASSERT (p->Set ("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, AccessorObjectTest::TEST_A); diff --git a/src/mobility/position-allocator.cc b/src/mobility/position-allocator.cc index 2ae7a5bd1..56b13f430 100644 --- a/src/mobility/position-allocator.cc +++ b/src/mobility/position-allocator.cc @@ -58,21 +58,21 @@ GridPositionAllocator::GetTypeId (void) MakeIntegerAccessor (&GridPositionAllocator::m_n), MakeIntegerChecker ()) .AddParameter ("MinX", "The x coordinate where the grid starts.", - FpValue (1.0), - MakeFpAccessor (&GridPositionAllocator::m_xMin), - MakeFpChecker ()) + Double (1.0), + MakeDoubleAccessor (&GridPositionAllocator::m_xMin), + MakeDoubleChecker ()) .AddParameter ("MinY", "The y coordinate where the grid starts.", - FpValue (0.0), - MakeFpAccessor (&GridPositionAllocator::m_yMin), - MakeFpChecker ()) + Double (0.0), + MakeDoubleAccessor (&GridPositionAllocator::m_yMin), + MakeDoubleChecker ()) .AddParameter ("DeltaX", "The x space between objects.", - FpValue (1.0), - MakeFpAccessor (&GridPositionAllocator::m_deltaX), - MakeFpChecker ()) + Double (1.0), + MakeDoubleAccessor (&GridPositionAllocator::m_deltaX), + MakeDoubleChecker ()) .AddParameter ("DeltaY", "The y space between objects.", - FpValue (1.0), - MakeFpAccessor (&GridPositionAllocator::m_deltaY), - MakeFpChecker ()) + Double (1.0), + MakeDoubleAccessor (&GridPositionAllocator::m_deltaY), + MakeDoubleChecker ()) .AddParameter ("LayoutType", "The type of layout.", Enum (ROW_FIRST), MakeEnumAccessor (&GridPositionAllocator::m_layoutType), @@ -159,14 +159,14 @@ RandomDiscPositionAllocator::GetTypeId (void) MakeRandomVariableChecker ()) .AddParameter ("X", "The x coordinate of the center of the random position disc.", - FpValue (0.0), - MakeFpAccessor (&RandomDiscPositionAllocator::m_x), - MakeFpChecker ()) + Double (0.0), + MakeDoubleAccessor (&RandomDiscPositionAllocator::m_x), + MakeDoubleChecker ()) .AddParameter ("Y", "The y coordinate of the center of the random position disc.", - FpValue (0.0), - MakeFpAccessor (&RandomDiscPositionAllocator::m_y), - MakeFpChecker ()) + Double (0.0), + MakeDoubleAccessor (&RandomDiscPositionAllocator::m_y), + MakeDoubleChecker ()) ; return tid; }