Add sufficient information to AttributeChecker to generate nice-looking documentation.

This commit is contained in:
Mathieu Lacage
2008-03-12 11:17:16 -07:00
parent 5a7be54e31
commit 250eed3667
15 changed files with 214 additions and 60 deletions

View File

@@ -26,6 +26,39 @@
#include <sstream>
#include "fatal-error.h"
namespace ns3 {
template <typename T, typename BASE>
Ptr<AttributeChecker>
MakeSimpleAttributeChecker (std::string name)
{
struct SimpleAttributeChecker : public BASE
{
virtual bool Check (Attribute value) const {
return value.DynCast<const T *> () != 0;
}
virtual std::string GetType (void) const {
return m_type;
}
virtual bool HasTypeConstraints (void) const {
return false;
}
virtual std::string GetTypeConstraints (void) const {
return "";
}
virtual Attribute Create (void) const {
return Attribute::Create<T> ();
}
std::string m_type;
} *checker = new SimpleAttributeChecker ();
checker->m_type = name;
return Ptr<AttributeChecker> (checker, false);
}
}
/**
* \defgroup AttributeHelper
*
@@ -188,7 +221,7 @@
#define ATTRIBUTE_CHECKER_IMPLEMENT(type) \
Ptr<const AttributeChecker> Make##type##Checker (void) \
{ \
return MakeSimpleAttributeChecker<type##Value,type##Checker> (); \
return MakeSimpleAttributeChecker<type##Value,type##Checker> (#type); \
} \
/**

View File

@@ -118,7 +118,7 @@ public:
.AddAttribute ("TestInt16WithBounds", "help text",
Integer (-2),
MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
MakeIntegerChecker (-5, 10))
MakeIntegerChecker<int16_t> (-5, 10))
.AddAttribute ("TestInt16SetGet", "help text",
Integer (6),
MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,

View File

@@ -216,6 +216,9 @@ public:
* false otherwise.
*/
virtual bool Check (Attribute value) const = 0;
virtual std::string GetType (void) const = 0;
virtual bool HasTypeConstraints (void) const = 0;
virtual std::string GetTypeConstraints (void) const = 0;
/**
* \returns a new instance of an AttributeValue (wrapper in an Attribute
* instance) which matches the type of the underlying attribute.
@@ -228,10 +231,6 @@ private:
mutable uint32_t m_count;
};
template <typename T, typename BASE>
Ptr<AttributeChecker>
MakeSimpleAttributeChecker (void);
template <typename T, typename U>
Ptr<const AttributeAccessor>
MakePtrAccessor (Ptr<U> T::*memberVariable);
@@ -323,6 +322,16 @@ class APtrChecker : public PtrChecker
}
return true;
}
virtual std::string GetType (void) const {
// XXX: we should be able to return better information
return "Ptr<>";
}
virtual bool HasTypeConstraints (void) const {
return false;
}
virtual std::string GetTypeConstraints (void) const {
return "";
}
virtual Attribute Create (void) const {
return Attribute::Create<PtrValue<T> > ();
}
@@ -488,23 +497,6 @@ MakePtrChecker (void)
return Create<internal::APtrChecker<T> > ();
}
template <typename T, typename BASE>
Ptr<AttributeChecker>
MakeSimpleAttributeChecker (void)
{
struct SimpleAttributeChecker : public BASE
{
virtual bool Check (Attribute value) const {
return value.DynCast<const T *> () != 0;
}
virtual Attribute Create (void) const {
return Attribute::Create<T> ();
}
} *checker = new SimpleAttributeChecker ();
return Ptr<AttributeChecker> (checker, false);
}
} // namespace ns3
#endif /* ATTRIBUTE_H */

View File

@@ -56,15 +56,18 @@ std::istream & operator >> (std::istream &is, Double &value)
}
ATTRIBUTE_VALUE_IMPLEMENT (Double);
ATTRIBUTE_CONVERTER_IMPLEMENT (Double);
ATTRIBUTE_CONVERTER_IMPLEMENT (Double);
Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max)
namespace internal {
Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max, std::string name)
{
struct Checker : public AttributeChecker
{
Checker (double minValue, double maxValue)
Checker (double minValue, double maxValue, std::string name)
: m_minValue (minValue),
m_maxValue (maxValue) {}
m_maxValue (maxValue),
m_name (name) {}
virtual bool Check (Attribute value) const {
const DoubleValue *v = value.DynCast<const DoubleValue *> ();
if (v == 0)
@@ -73,14 +76,27 @@ Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max)
}
return v->Get () >= m_minValue && v->Get () <= m_maxValue;
}
virtual std::string GetType (void) const {
return m_name;
}
virtual bool HasTypeConstraints (void) const {
return true;
}
virtual std::string GetTypeConstraints (void) const {
std::ostringstream oss;
oss << m_minValue << ":" << m_maxValue;
return oss.str ();
}
virtual Attribute Create (void) const {
return Attribute::Create<DoubleValue> ();
}
double m_minValue;
double m_maxValue;
} *checker = new Checker (min, max);
std::string m_name;
} *checker = new Checker (min, max, name);
return Ptr<const AttributeChecker> (checker, false);
}
} // namespace internal
} // namespace ns3

View File

@@ -60,25 +60,44 @@ Ptr<const AttributeChecker> MakeDoubleChecker (void);
template <typename T>
Ptr<const AttributeChecker> MakeDoubleChecker (double min);
template <typename T>
Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max);
} // namespace ns3
#include "type-name.h"
namespace ns3 {
namespace internal {
Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max, std::string name);
} // namespace internal
template <typename T>
Ptr<const AttributeChecker> MakeDoubleChecker (void)
{
return MakeDoubleChecker (-std::numeric_limits<T>::max (),
std::numeric_limits<T>::max ());
return internal::MakeDoubleChecker (-std::numeric_limits<T>::max (),
std::numeric_limits<T>::max (),
TypeNameGet<T> ());
}
template <typename T>
Ptr<const AttributeChecker> MakeDoubleChecker (double min)
{
return MakeDoubleChecker (min,
std::numeric_limits<T>::max ());
return internal::MakeDoubleChecker (min,
std::numeric_limits<T>::max (),
TypeNameGet<T> ());
}
template <typename T>
Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max)
{
return internal::MakeDoubleChecker (min,
max,
TypeNameGet<T> ());
}
} // namespace ns3

View File

@@ -124,6 +124,31 @@ EnumChecker::Check (Attribute value) const
}
return false;
}
std::string
EnumChecker::GetType (void) const
{
return "Enum";
}
bool
EnumChecker::HasTypeConstraints (void) const
{
return true;
}
std::string
EnumChecker::GetTypeConstraints (void) const
{
std::ostringstream oss;
for (ValueSet::const_iterator i = m_valueSet.begin (); i != m_valueSet.end ();)
{
oss << i->second;
i++;
if (i != m_valueSet.end ())
{
oss << "|";
}
}
return oss.str ();
}
Attribute
EnumChecker::Create (void) const
{

View File

@@ -59,6 +59,9 @@ public:
void Add (int v, std::string name);
virtual bool Check (Attribute value) const;
virtual std::string GetType (void) const;
virtual bool HasTypeConstraints (void) const;
virtual std::string GetTypeConstraints (void) const;
virtual Attribute Create (void) const;
private:

View File

@@ -62,15 +62,17 @@ std::istream &operator >> (std::istream &is, Integer &integer)
ATTRIBUTE_CONVERTER_IMPLEMENT (Integer);
namespace internal {
Ptr<const AttributeChecker>
MakeIntegerChecker (int64_t min, int64_t max)
MakeIntegerChecker (int64_t min, int64_t max, std::string name)
{
struct IntegerChecker : public AttributeChecker
{
IntegerChecker (int64_t minValue, int64_t maxValue)
IntegerChecker (int64_t minValue, int64_t maxValue, std::string name)
: m_minValue (minValue),
m_maxValue (maxValue) {}
m_maxValue (maxValue),
m_name (name) {}
virtual bool Check (Attribute value) const {
const IntegerValue *v = value.DynCast<const IntegerValue *> ();
if (v == 0)
@@ -79,14 +81,27 @@ MakeIntegerChecker (int64_t min, int64_t max)
}
return v->Get ().Get () >= m_minValue && v->Get ().Get() <= m_maxValue;
}
virtual std::string GetType (void) const {
return m_name;
}
virtual bool HasTypeConstraints (void) const {
return true;
}
virtual std::string GetTypeConstraints (void) const {
std::ostringstream oss;
oss << m_minValue << ":" << m_maxValue;
return oss.str ();
}
virtual Attribute Create (void) const {
return Attribute::Create<IntegerValue> ();
}
int64_t m_minValue;
int64_t m_maxValue;
} *checker = new IntegerChecker (min, max);
std::string m_name;
} *checker = new IntegerChecker (min, max, name);
return Ptr<AttributeChecker> (checker, false);
}
} // namespace internal
} // namespace ns3

View File

@@ -59,26 +59,45 @@ Ptr<const AttributeChecker> MakeIntegerChecker (void);
template <typename T>
Ptr<const AttributeChecker> MakeIntegerChecker (int64_t min);
template <typename T>
Ptr<const AttributeChecker> MakeIntegerChecker (int64_t min, int64_t max);
} // namespace ns3
#include "type-name.h"
namespace ns3 {
namespace internal {
Ptr<const AttributeChecker> MakeIntegerChecker (int64_t min, int64_t max, std::string name);
} // internal
template <typename T>
Ptr<const AttributeChecker>
MakeIntegerChecker (int64_t min, int64_t max)
{
return internal::MakeIntegerChecker (min,
max, TypeNameGet<T> ());
}
template <typename T>
Ptr<const AttributeChecker>
MakeIntegerChecker (int64_t min)
{
return MakeIntegerChecker (min,
std::numeric_limits<T>::max ());
return internal::MakeIntegerChecker (min,
std::numeric_limits<T>::max (),
TypeNameGet<T> ());
}
template <typename T>
Ptr<const AttributeChecker>
MakeIntegerChecker (void)
{
return MakeIntegerChecker (std::numeric_limits<T>::min (),
std::numeric_limits<T>::max ());
return internal::MakeIntegerChecker (std::numeric_limits<T>::min (),
std::numeric_limits<T>::max (),
TypeNameGet<T> ());
}
} // namespace ns3

View File

@@ -101,10 +101,7 @@ ObjectVectorAccessor::Get (const ObjectBase * object, Attribute value) const
}
return true;
}
Ptr<const AttributeChecker>
MakeObjectVectorChecker (void)
{
return MakeSimpleAttributeChecker<ObjectVectorValue,ObjectVectorChecker> ();
}
ATTRIBUTE_CHECKER_IMPLEMENT (ObjectVector);
} // name

View File

@@ -5,6 +5,7 @@
#include "object.h"
#include "ptr.h"
#include "attribute.h"
#include "attribute-helper.h"
namespace ns3 {
@@ -34,16 +35,15 @@ MakeObjectVectorAccessor (U T::*memberVector);
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectVectorAccessor (Ptr<U> (T::*get) (INDEX) const,
INDEX (T::*getN) (void) const);
INDEX (T::*getN) (void) const);
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectVectorAccessor (INDEX (T::*getN) (void) const,
Ptr<U> (T::*get) (INDEX) const);
Ptr<U> (T::*get) (INDEX) const);
class ObjectVectorChecker : public AttributeChecker {};
Ptr<const AttributeChecker> MakeObjectVectorChecker (void);
ATTRIBUTE_CHECKER_DEFINE (ObjectVector);
} // namespace ns3

View File

@@ -58,14 +58,16 @@ std::istream & operator >> (std::istream &is, Uinteger &uinteger)
ATTRIBUTE_CONVERTER_IMPLEMENT(Uinteger);
ATTRIBUTE_VALUE_IMPLEMENT(Uinteger);
namespace internal {
Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max)
Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max, std::string name)
{
struct Checker : public AttributeChecker
{
Checker (uint64_t minValue, uint64_t maxValue)
Checker (uint64_t minValue, uint64_t maxValue, std::string name)
: m_minValue (minValue),
m_maxValue (maxValue) {}
m_maxValue (maxValue),
m_name (name) {}
virtual bool Check (Attribute value) const {
const UintegerValue *v = value.DynCast<const UintegerValue *> ();
if (v == 0)
@@ -74,14 +76,27 @@ Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max)
}
return v->Get ().Get () >= m_minValue && v->Get ().Get () <= m_maxValue;
}
virtual std::string GetType (void) const {
return m_name;
}
virtual bool HasTypeConstraints (void) const {
return true;
}
virtual std::string GetTypeConstraints (void) const {
std::ostringstream oss;
oss << m_minValue << ":" << m_maxValue;
return oss.str ();
}
virtual Attribute Create (void) const {
return Attribute::Create<UintegerValue> ();
}
uint64_t m_minValue;
uint64_t m_maxValue;
} *checker = new Checker (min, max);
std::string m_name;
} *checker = new Checker (min, max, name);
return Ptr<const AttributeChecker> (checker, false);
}
} // namespace internal
} // namespace ns3

View File

@@ -61,24 +61,44 @@ Ptr<const AttributeChecker> MakeUintegerChecker (void);
template <typename T>
Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min);
template <typename T>
Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max);
} // namespace ns3
#include "type-name.h"
namespace ns3 {
namespace internal {
Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max, std::string name);
} // namespace internal
template <typename T>
Ptr<const AttributeChecker> MakeUintegerChecker (void)
{
return MakeUintegerChecker (std::numeric_limits<T>::min (),
std::numeric_limits<T>::max ());
return internal::MakeUintegerChecker (std::numeric_limits<T>::min (),
std::numeric_limits<T>::max (),
TypeNameGet<T> ());
}
template <typename T>
Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min)
{
return MakeUintegerChecker (min,
std::numeric_limits<T>::max ());
return internal::MakeUintegerChecker (min,
std::numeric_limits<T>::max (),
TypeNameGet<T> ());
}
template <typename T>
Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max)
{
return internal::MakeUintegerChecker (min,
max,
TypeNameGet<T> ());
}
} // namespace ns3

View File

@@ -45,12 +45,12 @@ AmrrWifiManager::GetTypeId (void)
"Ratio of minimum erronous transmissions needed to switch to a lower rate",
Double (1.0/3.0),
MakeDoubleAccessor (&AmrrWifiManager::m_failureRatio),
MakeDoubleChecker (0.0, 1.0))
MakeDoubleChecker<double> (0.0, 1.0))
.AddAttribute ("SuccessRatio",
"Ratio of maximum erronous transmissions needed to switch to a higher rate",
Double (1.0/10.0),
MakeDoubleAccessor (&AmrrWifiManager::m_successRatio),
MakeDoubleChecker (0.0, 1.0))
MakeDoubleChecker<double> (0.0, 1.0))
.AddAttribute ("MaxSuccessThreshold",
"Maximum number of consecutive success periods needed to switch to a higher rate",
Uinteger (10),

View File

@@ -88,7 +88,7 @@ WifiMac::GetTypeId (void)
.AddAttribute ("MaxMsduSize", "XXX",
Uinteger (2304),
MakeUintegerAccessor (&WifiMac::m_maxMsduSize),
MakeUintegerChecker (1,2304))
MakeUintegerChecker<uint16_t> (1,2304))
.AddAttribute ("Ssid", "XXX",
Ssid ("default"),
MakeSsidAccessor (&WifiMac::GetSsid,