Files
unison/src/core/integer.cc

74 lines
1.4 KiB
C++
Raw Normal View History

2008-02-21 19:04:18 +01:00
#include "integer.h"
2008-02-04 22:32:13 +01:00
#include "fatal-error.h"
2008-02-04 22:18:07 +01:00
#include <sstream>
namespace ns3 {
Integer::Integer (int64_t value)
2008-02-04 22:18:07 +01:00
: m_value (value)
{}
Integer::Integer ()
: m_value (0)
{}
2008-02-04 22:18:07 +01:00
void
Integer::Set (int64_t value)
2008-02-04 22:18:07 +01:00
{
m_value = value;
}
int64_t
Integer::Get (void) const
2008-02-04 22:18:07 +01:00
{
return m_value;
}
Integer::operator int64_t () const
2008-02-04 22:18:07 +01:00
{
return m_value;
2008-02-04 22:18:07 +01:00
}
ATTRIBUTE_VALUE_IMPLEMENT (Integer);
std::ostream &operator << (std::ostream &os, const Integer &integer)
2008-02-04 22:18:07 +01:00
{
os << integer.Get ();
return os;
2008-02-04 22:18:07 +01:00
}
std::istream &operator >> (std::istream &is, Integer &integer)
2008-02-04 22:18:07 +01:00
{
int64_t v;
is >> v;
integer.Set (v);
return is;
2008-02-04 22:18:07 +01:00
}
ATTRIBUTE_CONVERTER_IMPLEMENT (Integer);
2008-02-20 20:57:59 +01:00
Ptr<const AttributeChecker>
MakeIntegerChecker (int64_t min, int64_t max)
{
struct IntegerChecker : public AttributeChecker
{
IntegerChecker (int64_t minValue, int64_t maxValue)
: m_minValue (minValue),
m_maxValue (maxValue) {}
2008-02-20 19:57:31 +01:00
virtual bool Check (Attribute value) const {
const IntegerValue *v = value.DynCast<const IntegerValue *> ();
if (v == 0)
{
return false;
}
return v->Get ().Get () >= m_minValue && v->Get ().Get() <= m_maxValue;
}
virtual Attribute Create (void) const {
return Attribute::Create<IntegerValue> ();
}
int64_t m_minValue;
int64_t m_maxValue;
} *checker = new IntegerChecker (min, max);
return Ptr<AttributeChecker> (checker, false);
}
2008-02-04 22:18:07 +01:00
} // namespace ns3