00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "integer.h"
00021 #include "fatal-error.h"
00022 #include <sstream>
00023
00024 namespace ns3 {
00025
00026 ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (int64_t, Integer);
00027
00028 namespace internal {
00029
00030 Ptr<const AttributeChecker>
00031 MakeIntegerChecker (int64_t min, int64_t max, std::string name)
00032 {
00033 struct IntegerChecker : public AttributeChecker
00034 {
00035 IntegerChecker (int64_t minValue, int64_t maxValue, std::string name)
00036 : m_minValue (minValue),
00037 m_maxValue (maxValue),
00038 m_name (name) {}
00039 virtual bool Check (const AttributeValue &value) const {
00040 const IntegerValue *v = dynamic_cast<const IntegerValue *> (&value);
00041 if (v == 0)
00042 {
00043 return false;
00044 }
00045 return v->Get () >= m_minValue && v->Get () <= m_maxValue;
00046 }
00047 virtual std::string GetValueTypeName (void) const {
00048 return "ns3::IntegerValue";
00049 }
00050 virtual bool HasUnderlyingTypeInformation (void) const {
00051 return true;
00052 }
00053 virtual std::string GetUnderlyingTypeInformation (void) const {
00054 std::ostringstream oss;
00055 oss << m_name << " " << m_minValue << ":" << m_maxValue;
00056 return oss.str ();
00057 }
00058 virtual Ptr<AttributeValue> Create (void) const {
00059 return ns3::Create<IntegerValue> ();
00060 }
00061 virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const {
00062 const IntegerValue *source = dynamic_cast<const IntegerValue *> (&src);
00063 IntegerValue *destination = dynamic_cast<IntegerValue *> (&dst);
00064 if (source == 0 || destination == 0)
00065 {
00066 return false;
00067 }
00068 *destination = *source;
00069 return true;
00070 }
00071 int64_t m_minValue;
00072 int64_t m_maxValue;
00073 std::string m_name;
00074 } *checker = new IntegerChecker (min, max, name);
00075 return Ptr<AttributeChecker> (checker, false);
00076 }
00077
00078 }
00079
00080 }