src/core/uint-value.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 07 Feb 2008 22:40:46 +0100
changeset 2384 500ada6a4874
parent 2379 db1eb36bfaa4
child 2427 9245ec163111
permissions -rw-r--r--
add Value support to RandomVariable.

#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