move checker creation function to .cc file.

This commit is contained in:
Mathieu Lacage
2008-02-18 03:01:42 +01:00
parent c194579f5e
commit 8bac0c2ba3
6 changed files with 72 additions and 73 deletions

View File

@@ -59,4 +59,26 @@ FpValue::operator PValue () const
return PValue::Create<FpValue> (*this);
}
Ptr<AttributeChecker> MakeFpChecker (double min, double max)
{
struct Checker : public AttributeChecker
{
Checker (double minValue, double maxValue)
: m_minValue (minValue),
m_maxValue (maxValue) {}
virtual bool Check (PValue value) const {
const FpValue *v = value.DynCast<const FpValue *> ();
if (v == 0)
{
return false;
}
return v->Get () >= m_minValue && v->Get () <= m_maxValue;
}
double m_minValue;
double m_maxValue;
} *checker = new Checker (min, max);
return Ptr<AttributeChecker> (checker, false);
}
} // namespace ns3

View File

@@ -34,8 +34,8 @@ Ptr<ParamSpec> MakeFpParamSpec (T1 a1, T2 a2);
template <typename T>
Ptr<AttributeChecker> MakeFpChecker (void);
template <typename T>
Ptr<AttributeChecker> MakeFpChecker (T min, T max);
Ptr<AttributeChecker> MakeFpChecker (double min, double max);
@@ -60,28 +60,6 @@ Ptr<AttributeChecker> MakeFpChecker (void)
return MakeFpChecker (-std::numeric_limits<T>::max (),
std::numeric_limits<T>::max ());
}
template <typename T>
Ptr<AttributeChecker> MakeFpChecker (T min, T max)
{
struct Checker : public AttributeChecker
{
Checker (double minValue, double maxValue)
: m_minValue (minValue),
m_maxValue (maxValue) {}
virtual bool Check (PValue value) const {
const FpValue *v = value.DynCast<const FpValue *> ();
if (v == 0)
{
return false;
}
return v->Get () >= m_minValue && v->Get () <= m_maxValue;
}
double m_minValue;
double m_maxValue;
} *checker = new Checker (min, max);
return Ptr<AttributeChecker> (checker, false);
}
} // namespace ns3

View File

@@ -59,5 +59,27 @@ IntValue::operator PValue () const
return PValue::Create<IntValue> (*this);
}
Ptr<AttributeChecker>
MakeIntChecker (int64_t min, int64_t max)
{
struct IntChecker : public AttributeChecker
{
IntChecker (int64_t minValue, int64_t maxValue)
: m_minValue (minValue),
m_maxValue (maxValue) {}
virtual bool Check (PValue value) const {
const IntValue *v = value.DynCast<const IntValue *> ();
if (v == 0)
{
return false;
}
return v->Get () >= m_minValue && v->Get () <= m_maxValue;
}
int64_t m_minValue;
int64_t m_maxValue;
} *checker = new IntChecker (min, max);
return Ptr<AttributeChecker> (checker, false);
}
} // namespace ns3

View File

@@ -34,8 +34,7 @@ Ptr<ParamSpec> MakeIntParamSpec (T1 a1, T2 a2);
template <typename T>
Ptr<AttributeChecker> MakeIntChecker (void);
template <typename T>
Ptr<AttributeChecker> MakeIntChecker (T min, T max);
Ptr<AttributeChecker> MakeIntChecker (int64_t min, int64_t max);
} // namespace ns3
@@ -61,30 +60,6 @@ MakeIntChecker (void)
std::numeric_limits<T>::max ());
}
template <typename T>
Ptr<AttributeChecker>
MakeIntChecker (T min, T max)
{
struct IntChecker : public AttributeChecker
{
IntChecker (int64_t minValue, int64_t maxValue)
: m_minValue (minValue),
m_maxValue (maxValue) {}
virtual bool Check (PValue value) const {
const IntValue *v = value.DynCast<const IntValue *> ();
if (v == 0)
{
return false;
}
return v->Get () >= m_minValue && v->Get () <= m_maxValue;
}
int64_t m_minValue;
int64_t m_maxValue;
} *checker = new IntChecker (min, max);
return Ptr<AttributeChecker> (checker, false);
}
} // namespace ns3
#endif /* INT_VALUE_H */

View File

@@ -59,4 +59,27 @@ UintValue::operator PValue () const
return PValue::Create<UintValue> (*this);
}
Ptr<AttributeChecker> MakeUintChecker (uint64_t min, uint64_t max)
{
struct Checker : public AttributeChecker
{
Checker (uint64_t minValue, uint64_t maxValue)
: m_minValue (minValue),
m_maxValue (maxValue) {}
virtual bool Check (PValue value) const {
const UintValue *v = value.DynCast<const UintValue *> ();
if (v == 0)
{
return false;
}
return v->Get () >= m_minValue && v->Get () <= m_maxValue;
}
uint64_t m_minValue;
uint64_t m_maxValue;
} *checker = new Checker (min, max);
return Ptr<AttributeChecker> (checker, false);
}
} // namespace ns3

View File

@@ -33,8 +33,8 @@ Ptr<ParamSpec> MakeUintParamSpec (T1 a1, T2 a2);
template <typename T>
Ptr<AttributeChecker> MakeUintChecker (void);
template <typename T>
Ptr<AttributeChecker> MakeUintChecker (T min, T max);
Ptr<AttributeChecker> MakeUintChecker (uint64_t min, uint64_t max);
} // namespace ns3
@@ -59,27 +59,6 @@ Ptr<AttributeChecker> MakeUintChecker (void)
return MakeUintChecker (std::numeric_limits<T>::min (),
std::numeric_limits<T>::max ());
}
template <typename T>
Ptr<AttributeChecker> MakeUintChecker (T min, T max)
{
struct Checker : public AttributeChecker
{
Checker (uint64_t minValue, uint64_t maxValue)
: m_minValue (minValue),
m_maxValue (maxValue) {}
virtual bool Check (PValue value) const {
const UintValue *v = value.DynCast<const UintValue *> ();
if (v == 0)
{
return false;
}
return v->Get () >= m_minValue && v->Get () <= m_maxValue;
}
uint64_t m_minValue;
uint64_t m_maxValue;
} *checker = new Checker (min, max);
return Ptr<AttributeChecker> (checker, false);
}
} // namespace ns3