Add sufficient information to AttributeChecker to generate nice-looking doxygen documentation.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 12 Mar 2008 11:35:00 -0700
changeset 2599 fcc1728eb669
parent 2598 8248bc4b4e85
child 2600 6c389d0c717d
Add sufficient information to AttributeChecker to generate nice-looking doxygen documentation.
src/core/attribute-helper.h
src/core/attribute-test.cc
src/core/attribute.h
src/core/double.cc
src/core/double.h
src/core/enum.cc
src/core/enum.h
src/core/integer.cc
src/core/integer.h
src/core/object-vector.cc
src/core/object-vector.h
src/core/uinteger.cc
src/core/uinteger.h
src/devices/wifi/amrr-wifi-manager.cc
src/devices/wifi/wifi-mac.cc
--- a/src/core/attribute-helper.h	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/attribute-helper.h	Wed Mar 12 11:35:00 2008 -0700
@@ -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);	\
   }									\
 
 /**
--- a/src/core/attribute-test.cc	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/attribute-test.cc	Wed Mar 12 11:35:00 2008 -0700
@@ -118,7 +118,7 @@
       .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,
--- a/src/core/attribute.h	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/attribute.h	Wed Mar 12 11:35:00 2008 -0700
@@ -216,6 +216,9 @@
    *          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 @@
   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 @@
       }
     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 @@
   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 */
--- a/src/core/double.cc	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/double.cc	Wed Mar 12 11:35:00 2008 -0700
@@ -56,15 +56,18 @@
 }
 
 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 @@
 	}
       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
--- a/src/core/double.h	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/double.h	Wed Mar 12 11:35:00 2008 -0700
@@ -60,25 +60,44 @@
 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
--- a/src/core/enum.cc	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/enum.cc	Wed Mar 12 11:35:00 2008 -0700
@@ -124,6 +124,31 @@
     }
   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
 {
--- a/src/core/enum.h	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/enum.h	Wed Mar 12 11:35:00 2008 -0700
@@ -59,6 +59,9 @@
   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:
--- a/src/core/integer.cc	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/integer.cc	Wed Mar 12 11:35:00 2008 -0700
@@ -62,15 +62,17 @@
 
 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 @@
 	}
       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
--- a/src/core/integer.h	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/integer.h	Wed Mar 12 11:35:00 2008 -0700
@@ -59,26 +59,45 @@
 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
--- a/src/core/object-vector.cc	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/object-vector.cc	Wed Mar 12 11:35:00 2008 -0700
@@ -101,10 +101,7 @@
     }
   return true;
 }
-Ptr<const AttributeChecker> 
-MakeObjectVectorChecker (void)
-{
-  return MakeSimpleAttributeChecker<ObjectVectorValue,ObjectVectorChecker> ();
-}
+
+ATTRIBUTE_CHECKER_IMPLEMENT (ObjectVector);
 
 } // name
--- a/src/core/object-vector.h	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/object-vector.h	Wed Mar 12 11:35:00 2008 -0700
@@ -5,6 +5,7 @@
 #include "object.h"
 #include "ptr.h"
 #include "attribute.h"
+#include "attribute-helper.h"
 
 namespace ns3 {
 
@@ -34,16 +35,15 @@
 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
 
--- a/src/core/uinteger.cc	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/uinteger.cc	Wed Mar 12 11:35:00 2008 -0700
@@ -58,14 +58,16 @@
 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 @@
 	}
       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
--- a/src/core/uinteger.h	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/core/uinteger.h	Wed Mar 12 11:35:00 2008 -0700
@@ -61,24 +61,44 @@
 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
--- a/src/devices/wifi/amrr-wifi-manager.cc	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/devices/wifi/amrr-wifi-manager.cc	Wed Mar 12 11:35:00 2008 -0700
@@ -45,12 +45,12 @@
                    "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),
--- a/src/devices/wifi/wifi-mac.cc	Wed Mar 12 10:18:14 2008 -0700
+++ b/src/devices/wifi/wifi-mac.cc	Wed Mar 12 11:35:00 2008 -0700
@@ -88,7 +88,7 @@
     .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,