forgot to add new files
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 04 Feb 2008 22:47:26 +0100
changeset 2379 db1eb36bfaa4
parent 2378 bc706b6e9df3
child 2380 64dbfb5cf589
forgot to add new files
src/core/uint-value.cc
src/core/uint-value.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/uint-value.cc	Mon Feb 04 22:47:26 2008 +0100
@@ -0,0 +1,75 @@
+#include "uint-value.h"
+#include "fatal-error.h"
+#include <sstream>
+
+namespace ns3 {
+
+UintValue::UintValue (uint64_t value)
+  : m_value (value)
+{}
+PValue
+UintValue::Copy (void) const
+{
+  return PValue::Create<UintValue> (*this);
+}
+
+void 
+UintValue::Set (uint64_t value)
+{
+  m_value = value;
+}
+uint64_t 
+UintValue::Get (void) const
+{
+  return m_value;
+}
+std::string 
+UintValue::SerializeToString (Ptr<const ParamSpec> spec) const
+{
+  std::ostringstream oss;
+  oss << m_value;
+  return oss.str ();
+}
+bool 
+UintValue::DeserializeFromString (std::string value, Ptr<const ParamSpec> spec)
+{
+  uint64_t v;
+  std::istringstream iss;
+  iss.str (value);
+  iss >> v;
+  bool ok = !iss.bad () && !iss.fail ();
+  if (ok)
+    {
+      m_value = v;
+    }
+  return ok;
+}
+
+UintValue::UintValue (PValue value)
+{
+  const UintValue *v = value.DynCast<const UintValue *> ();
+  if (v == 0)
+    {
+      NS_FATAL_ERROR ("assigning non-Uint value to Uint value.");
+    }
+  m_value = v->m_value;
+}
+UintValue::operator PValue () const
+{
+  return PValue::Create<UintValue> (*this);
+}
+
+
+
+UintValueChecker::UintValueChecker (uint64_t minValue, uint64_t maxValue)
+  : m_minValue (minValue),
+    m_maxValue (maxValue)
+{}
+bool 
+UintValueChecker::Check (const uint64_t &value) const
+{
+  return value >= m_minValue && value <= m_maxValue;
+}
+
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/uint-value.h	Mon Feb 04 22:47:26 2008 +0100
@@ -0,0 +1,108 @@
+#ifndef UINT_VALUE_H
+#define UINT_VALUE_H
+
+#include "value.h"
+#include "param-spec-helper.h"
+#include <stdint.h>
+
+namespace ns3 {
+
+class UintValue : public Value
+{
+public:
+  UintValue (uint64_t value);
+  virtual PValue Copy (void) const;
+  virtual std::string SerializeToString (Ptr<const ParamSpec> spec) const;
+  virtual bool DeserializeFromString (std::string value, Ptr<const ParamSpec> spec);
+
+  void Set (uint64_t value);
+  uint64_t Get (void) const;
+
+  UintValue (PValue value);
+  operator PValue () const;
+private:
+  uint64_t m_value;
+};
+
+template <typename U, typename T>
+Ptr<const ParamSpec> MakeUintParamSpec (uint64_t initialValue,
+					U T::*memberVariable);
+template <typename U, typename T>
+Ptr<const ParamSpec> MakePtrUintParamSpec (uint64_t initialValue,
+					   uint64_t minValue,
+					   uint64_t maxValue,
+					   U T::*memberVariable);
+template <typename U, typename T>
+Ptr<const ParamSpec> MakeUintParamSpec (uint64_t initialValue,
+					void (T::*setter) (U),
+					U (T::*getter) (void) const);
+template <typename U, typename T>
+Ptr<const ParamSpec> MakeUintParamSpec (uint64_t initialValue,
+					uint64_t minValue,
+					uint64_t maxValue,
+					void (T::*setter) (U),
+					U (T::*getter) (void) const);
+
+} // namespace ns3
+
+namespace ns3 {
+
+class UintValueChecker
+{
+public:
+  UintValueChecker (uint64_t minValue, uint64_t maxValue);
+  bool Check (const uint64_t &value) const;
+private:
+  uint64_t m_minValue;
+  uint64_t m_maxValue;
+};
+
+template <typename U, typename T>
+Ptr<const ParamSpec> 
+MakeUintParamSpec (U T::*memberVariable,
+		   uint64_t initialValue)
+{
+  uint64_t minValue = std::numeric_limits<U>::min ();
+  uint64_t maxValue = std::numeric_limits<U>::max ();
+  return MakeMemberVariableParamSpecWithChecker (memberVariable, UintValue (initialValue),
+						 UintValueChecker (minValue, maxValue));
+}
+
+template <typename U, typename T>
+Ptr<const ParamSpec> 
+MakeUintParamSpec (U T::*memberVariable,
+		   uint64_t initialValue,
+		   uint64_t minValue,
+		   uint64_t maxValue)
+{
+  return MakeMemberVariableParamSpecWithChecker (memberVariable, UintValue (initialValue),
+						 UintValueChecker (minValue, maxValue));
+}
+
+template <typename U, typename T>
+Ptr<const ParamSpec> 
+MakeUintParamSpec (void (T::*setter) (U),
+		   U (T::*getter) (void) const,
+		   uint64_t initialValue)
+{
+  uint64_t minValue = std::numeric_limits<U>::min ();
+  uint64_t maxValue = std::numeric_limits<U>::max ();
+  return MakeMemberMethodParamSpecWithChecker (setter, getter, UintValue (initialValue),
+					       UintValueChecker (minValue, maxValue));
+}
+template <typename U, typename T>
+Ptr<const ParamSpec> 
+MakeUintParamSpec (void (T::*setter) (U),
+		   U (T::*getter) (void) const,
+		   uint64_t initialValue,
+		   uint64_t minValue,
+		   uint64_t maxValue)
+{
+  return MakeMemberMethodParamSpecWithChecker (setter, getter, UintValue (initialValue),
+					       UintValueChecker (minValue, maxValue));
+}
+
+
+} // namespace ns3
+
+#endif /* UINT_PARAMETER_H */