--- a/src/mobility/vector.cc Thu Feb 07 23:55:23 2008 +0100
+++ b/src/mobility/vector.cc Thu Feb 07 23:55:43 2008 +0100
@@ -18,7 +18,9 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "vector.h"
+#include "ns3/fatal-error.h"
#include <cmath>
+#include <sstream>
namespace ns3 {
@@ -35,6 +37,21 @@
z (0.0)
{}
+Vector::Vector (PValue value)
+{
+ const VectorValue *v = value.DynCast<const VectorValue *> ();
+ if (v == 0)
+ {
+ NS_FATAL_ERROR ("Expected value of type Vector");
+ }
+ *this = v->Get ();
+}
+Vector::operator PValue () const
+{
+ return PValue::Create<VectorValue> (*this);
+}
+
+
double
CalculateDistance (const Vector &a, const Vector &b)
{
@@ -45,4 +62,49 @@
return distance;
}
+
+
+VectorValue::VectorValue (const Vector &vector)
+ : m_vector (vector)
+{}
+
+void
+VectorValue::Set (const Vector &vector)
+{
+ m_vector = vector;
+}
+Vector
+VectorValue::Get (void) const
+{
+ return m_vector;
+}
+
+PValue
+VectorValue::Copy (void) const
+{
+ return PValue::Create<VectorValue> (*this);
+}
+std::string
+VectorValue::SerializeToString (Ptr<const ParamSpec> spec) const
+{
+ std::ostringstream oss;
+ oss << m_vector.x << ":" << m_vector.y << ":" << m_vector.z;
+ return oss.str ();
+}
+bool
+VectorValue::DeserializeFromString (std::string value, Ptr<const ParamSpec> spec)
+{
+ // XXX implement parsing
+ return false;
+}
+
+VectorValue::VectorValue (PValue value)
+ : m_vector (value)
+{}
+VectorValue::operator PValue () const
+{
+ return m_vector;
+}
+
+
} // namespace ns3
--- a/src/mobility/vector.h Thu Feb 07 23:55:23 2008 +0100
+++ b/src/mobility/vector.h Thu Feb 07 23:55:43 2008 +0100
@@ -20,6 +20,9 @@
#ifndef VECTOR_H
#define VECTOR_H
+#include "ns3/value.h"
+#include "ns3/param-spec-helper.h"
+
namespace ns3 {
/**
@@ -54,10 +57,47 @@
* z coordinate of vector vector
*/
double z;
+
+ Vector (PValue value);
+ operator PValue () const;
};
double CalculateDistance (const Vector &a, const Vector &b);
+class VectorValue : public Value
+{
+public:
+ VectorValue (const Vector &vector);
+
+ void Set (const Vector &vector);
+ Vector Get (void) const;
+
+ virtual PValue Copy (void) const;
+ virtual std::string SerializeToString (Ptr<const ParamSpec> spec) const;
+ virtual bool DeserializeFromString (std::string value, Ptr<const ParamSpec> spec);
+
+ VectorValue (PValue value);
+ operator PValue () const;
+private:
+ Vector m_vector;
+};
+
+template <typename T>
+Ptr<ParamSpec>
+MakeVectorParamSpec (Vector T::*memberVariable, const Vector &initialValue);
+
+} // namespace ns3
+
+namespace ns3 {
+
+template <typename T>
+Ptr<ParamSpec>
+MakeVectorParamSpec (Vector T::*memberVariable, const Vector &initialValue)
+{
+ return MakeMemberVariableParamSpec (memberVariable, VectorValue (initialValue));
+}
+
+
} // namespace ns3
#endif /* VECTOR_H */