forgot to add new files
This commit is contained in:
75
src/core/uint-value.cc
Normal file
75
src/core/uint-value.cc
Normal file
@@ -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
|
||||
108
src/core/uint-value.h
Normal file
108
src/core/uint-value.h
Normal file
@@ -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 */
|
||||
Reference in New Issue
Block a user