2008-03-10 00:38:48 +01:00
|
|
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2008 INRIA
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
|
|
|
|
*/
|
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 {
|
|
|
|
|
|
2008-02-21 00:09:16 +01:00
|
|
|
Integer::Integer (int64_t value)
|
2008-02-04 22:18:07 +01:00
|
|
|
: m_value (value)
|
|
|
|
|
{}
|
2008-02-21 00:09:16 +01:00
|
|
|
Integer::Integer ()
|
|
|
|
|
: m_value (0)
|
|
|
|
|
{}
|
2008-02-04 22:18:07 +01:00
|
|
|
void
|
2008-02-21 00:09:16 +01:00
|
|
|
Integer::Set (int64_t value)
|
2008-02-04 22:18:07 +01:00
|
|
|
{
|
|
|
|
|
m_value = value;
|
|
|
|
|
}
|
|
|
|
|
int64_t
|
2008-02-21 00:09:16 +01:00
|
|
|
Integer::Get (void) const
|
2008-02-04 22:18:07 +01:00
|
|
|
{
|
|
|
|
|
return m_value;
|
|
|
|
|
}
|
2008-02-21 00:09:16 +01:00
|
|
|
|
|
|
|
|
Integer::operator int64_t () const
|
2008-02-04 22:18:07 +01:00
|
|
|
{
|
2008-02-21 00:09:16 +01:00
|
|
|
return m_value;
|
2008-02-04 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
2008-02-21 00:09:16 +01:00
|
|
|
ATTRIBUTE_VALUE_IMPLEMENT (Integer);
|
|
|
|
|
|
|
|
|
|
std::ostream &operator << (std::ostream &os, const Integer &integer)
|
2008-02-04 22:18:07 +01:00
|
|
|
{
|
2008-02-21 00:09:16 +01:00
|
|
|
os << integer.Get ();
|
|
|
|
|
return os;
|
2008-02-04 22:18:07 +01:00
|
|
|
}
|
2008-02-21 00:09:16 +01:00
|
|
|
std::istream &operator >> (std::istream &is, Integer &integer)
|
2008-02-04 22:18:07 +01:00
|
|
|
{
|
2008-02-21 00:09:16 +01:00
|
|
|
int64_t v;
|
|
|
|
|
is >> v;
|
|
|
|
|
integer.Set (v);
|
|
|
|
|
return is;
|
2008-02-04 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
2008-02-21 00:09:16 +01:00
|
|
|
ATTRIBUTE_CONVERTER_IMPLEMENT (Integer);
|
|
|
|
|
|
|
|
|
|
|
2008-02-20 20:57:59 +01:00
|
|
|
Ptr<const AttributeChecker>
|
2008-02-21 00:09:16 +01:00
|
|
|
MakeIntegerChecker (int64_t min, int64_t max)
|
2008-02-18 03:01:42 +01:00
|
|
|
{
|
2008-02-21 00:09:16 +01:00
|
|
|
struct IntegerChecker : public AttributeChecker
|
2008-02-18 03:01:42 +01:00
|
|
|
{
|
2008-02-21 00:09:16 +01:00
|
|
|
IntegerChecker (int64_t minValue, int64_t maxValue)
|
2008-02-18 03:01:42 +01:00
|
|
|
: m_minValue (minValue),
|
|
|
|
|
m_maxValue (maxValue) {}
|
2008-02-20 19:57:31 +01:00
|
|
|
virtual bool Check (Attribute value) const {
|
2008-02-21 00:09:16 +01:00
|
|
|
const IntegerValue *v = value.DynCast<const IntegerValue *> ();
|
2008-02-18 03:01:42 +01:00
|
|
|
if (v == 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-02-21 00:09:16 +01:00
|
|
|
return v->Get ().Get () >= m_minValue && v->Get ().Get() <= m_maxValue;
|
2008-02-18 03:01:42 +01:00
|
|
|
}
|
2008-03-01 19:54:48 +01:00
|
|
|
virtual Attribute Create (void) const {
|
|
|
|
|
return Attribute::Create<IntegerValue> ();
|
|
|
|
|
}
|
2008-02-18 03:01:42 +01:00
|
|
|
int64_t m_minValue;
|
|
|
|
|
int64_t m_maxValue;
|
2008-02-21 00:09:16 +01:00
|
|
|
} *checker = new IntegerChecker (min, max);
|
2008-02-18 03:01:42 +01:00
|
|
|
return Ptr<AttributeChecker> (checker, false);
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-04 22:18:07 +01:00
|
|
|
|
|
|
|
|
} // namespace ns3
|