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