fpValue -> Double
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<FpValue> (*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<const AttributeChecker> 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<const AttributeChecker> 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<const FpValue *> ();
|
||||
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<FpValue> (*this);
|
||||
}
|
||||
ATTRIBUTE_VALUE_IMPLEMENT (Double);
|
||||
ATTRIBUTE_CONVERTER_IMPLEMENT (Double);
|
||||
|
||||
Ptr<const AttributeChecker> MakeFpChecker (double min, double max)
|
||||
Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max)
|
||||
{
|
||||
struct Checker : public AttributeChecker
|
||||
{
|
||||
@@ -67,7 +47,7 @@ Ptr<const AttributeChecker> MakeFpChecker (double min, double max)
|
||||
: m_minValue (minValue),
|
||||
m_maxValue (maxValue) {}
|
||||
virtual bool Check (Attribute value) const {
|
||||
const FpValue *v = value.DynCast<const FpValue *> ();
|
||||
const DoubleValue *v = value.DynCast<const DoubleValue *> ();
|
||||
if (v == 0)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -2,63 +2,48 @@
|
||||
#define FP_VALUE_H
|
||||
|
||||
#include "attribute.h"
|
||||
#include "param-spec-helper.h"
|
||||
#include "value-helper.h"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class FpValue : public AttributeValue
|
||||
class Double
|
||||
{
|
||||
public:
|
||||
FpValue (double value);
|
||||
|
||||
virtual Attribute Copy (void) const;
|
||||
virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
|
||||
virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> 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 <typename T1>
|
||||
Ptr<const AttributeAccessor> MakeFpAccessor (T1 a1);
|
||||
template <typename T1, typename T2>
|
||||
Ptr<const AttributeAccessor> MakeFpAccessor (T1 a1, T2 a2);
|
||||
ATTRIBUTE_VALUE_DEFINE (Double);
|
||||
ATTRIBUTE_ACCESSOR_DEFINE (Double);
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeFpChecker (void);
|
||||
|
||||
Ptr<const AttributeChecker> MakeFpChecker (double min, double max);
|
||||
Ptr<const AttributeChecker> MakeDoubleChecker (void);
|
||||
|
||||
Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max);
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
template <typename T1>
|
||||
Ptr<const AttributeAccessor> MakeFpAccessor (T1 a1)
|
||||
{
|
||||
return MakeAccessorHelper<FpAccessor,FpValue> (a1);
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
Ptr<const AttributeAccessor> MakeFpAccessor (T1 a1, T2 a2)
|
||||
{
|
||||
return MakeAccessorHelper<FpAccessor,FpValue> (a1, a2);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeFpChecker (void)
|
||||
Ptr<const AttributeChecker> MakeDoubleChecker (void)
|
||||
{
|
||||
return MakeFpChecker (-std::numeric_limits<T>::max (),
|
||||
std::numeric_limits<T>::max ());
|
||||
return MakeDoubleChecker (-std::numeric_limits<T>::max (),
|
||||
std::numeric_limits<T>::max ());
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -82,9 +82,9 @@ public:
|
||||
MakeRandomVariableAccessor (&AccessorObjectTest::m_random),
|
||||
MakeRandomVariableChecker ())
|
||||
.AddParameter ("TestFloat", "help text",
|
||||
FpValue (-1.1),
|
||||
MakeFpAccessor (&AccessorObjectTest::m_float),
|
||||
MakeFpChecker<float> ())
|
||||
Double (-1.1),
|
||||
MakeDoubleAccessor (&AccessorObjectTest::m_float),
|
||||
MakeDoubleChecker<float> ())
|
||||
.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);
|
||||
|
||||
@@ -58,21 +58,21 @@ GridPositionAllocator::GetTypeId (void)
|
||||
MakeIntegerAccessor (&GridPositionAllocator::m_n),
|
||||
MakeIntegerChecker<uint32_t> ())
|
||||
.AddParameter ("MinX", "The x coordinate where the grid starts.",
|
||||
FpValue (1.0),
|
||||
MakeFpAccessor (&GridPositionAllocator::m_xMin),
|
||||
MakeFpChecker<double> ())
|
||||
Double (1.0),
|
||||
MakeDoubleAccessor (&GridPositionAllocator::m_xMin),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddParameter ("MinY", "The y coordinate where the grid starts.",
|
||||
FpValue (0.0),
|
||||
MakeFpAccessor (&GridPositionAllocator::m_yMin),
|
||||
MakeFpChecker<double> ())
|
||||
Double (0.0),
|
||||
MakeDoubleAccessor (&GridPositionAllocator::m_yMin),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddParameter ("DeltaX", "The x space between objects.",
|
||||
FpValue (1.0),
|
||||
MakeFpAccessor (&GridPositionAllocator::m_deltaX),
|
||||
MakeFpChecker<double> ())
|
||||
Double (1.0),
|
||||
MakeDoubleAccessor (&GridPositionAllocator::m_deltaX),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddParameter ("DeltaY", "The y space between objects.",
|
||||
FpValue (1.0),
|
||||
MakeFpAccessor (&GridPositionAllocator::m_deltaY),
|
||||
MakeFpChecker<double> ())
|
||||
Double (1.0),
|
||||
MakeDoubleAccessor (&GridPositionAllocator::m_deltaY),
|
||||
MakeDoubleChecker<double> ())
|
||||
.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> ())
|
||||
Double (0.0),
|
||||
MakeDoubleAccessor (&RandomDiscPositionAllocator::m_x),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddParameter ("Y",
|
||||
"The y coordinate of the center of the random position disc.",
|
||||
FpValue (0.0),
|
||||
MakeFpAccessor (&RandomDiscPositionAllocator::m_y),
|
||||
MakeFpChecker<double> ())
|
||||
Double (0.0),
|
||||
MakeDoubleAccessor (&RandomDiscPositionAllocator::m_y),
|
||||
MakeDoubleChecker<double> ())
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user