add ObjectVector::GetItemTypeId
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed Apr 09 14:58:52 2008 -0700 (22 months ago)
changeset 2933c7983cfa2cb3
parent 2932 db96af55f46e
child 2934 5bdc12f09798
add ObjectVector::GetItemTypeId
src/core/attribute-test.cc
src/core/config.cc
src/core/object-vector.cc
src/core/object-vector.h
src/internet-node/ipv4-l3-protocol.cc
src/internet-node/ipv4-l4-demux.cc
src/node/node-list.cc
src/node/node.cc
     1.1 --- a/src/core/attribute-test.cc	Wed Apr 09 14:28:16 2008 -0700
     1.2 +++ b/src/core/attribute-test.cc	Wed Apr 09 14:58:52 2008 -0700
     1.3 @@ -143,12 +143,12 @@
     1.4        .AddAttribute ("TestVector1", "help text",
     1.5  		     ObjectVector (),
     1.6  		     MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
     1.7 -		     MakeObjectVectorChecker ())
     1.8 +		     MakeObjectVectorChecker<Derived> ())
     1.9        .AddAttribute ("TestVector2", "help text",
    1.10  		     ObjectVector (),
    1.11  		     MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
    1.12  						&AttributeObjectTest::DoGetVector),
    1.13 -		     MakeObjectVectorChecker ())
    1.14 +		     MakeObjectVectorChecker<Derived> ())
    1.15        .AddAttribute ("IntegerTraceSource1", "help text",
    1.16  		     Integer (-2),
    1.17  		     MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
     2.1 --- a/src/core/config.cc	Wed Apr 09 14:28:16 2008 -0700
     2.2 +++ b/src/core/config.cc	Wed Apr 09 14:58:52 2008 -0700
     2.3 @@ -512,11 +512,11 @@
     2.4      .AddAttribute ("NodesA", "",
     2.5  		   ObjectVector (),
     2.6  		   MakeObjectVectorAccessor (&MyNode::m_nodesA),
     2.7 -		   MakeObjectVectorChecker ())
     2.8 +		   MakeObjectVectorChecker<MyNode> ())
     2.9      .AddAttribute ("NodesB", "",
    2.10  		   ObjectVector (),
    2.11  		   MakeObjectVectorAccessor (&MyNode::m_nodesB),
    2.12 -		   MakeObjectVectorChecker ())
    2.13 +		   MakeObjectVectorChecker<MyNode> ())
    2.14      .AddAttribute ("NodeA", "",
    2.15                     Pointer (),
    2.16  		   MakePointerAccessor (&MyNode::m_nodeA),
     3.1 --- a/src/core/object-vector.cc	Wed Apr 09 14:28:16 2008 -0700
     3.2 +++ b/src/core/object-vector.cc	Wed Apr 09 14:58:52 2008 -0700
     3.3 @@ -102,6 +102,4 @@
     3.4    return true;
     3.5  }
     3.6  
     3.7 -ATTRIBUTE_CHECKER_IMPLEMENT (ObjectVector);
     3.8 -
     3.9  } // name
     4.1 --- a/src/core/object-vector.h	Wed Apr 09 14:28:16 2008 -0700
     4.2 +++ b/src/core/object-vector.h	Wed Apr 09 14:58:52 2008 -0700
     4.3 @@ -5,7 +5,6 @@
     4.4  #include "object.h"
     4.5  #include "ptr.h"
     4.6  #include "attribute.h"
     4.7 -#include "attribute-helper.h"
     4.8  
     4.9  namespace ns3 {
    4.10  
    4.11 @@ -48,8 +47,14 @@
    4.12  MakeObjectVectorAccessor (INDEX (T::*getN) (void) const,
    4.13  			  Ptr<U> (T::*get) (INDEX) const);
    4.14  
    4.15 +class ObjectVectorChecker : public AttributeChecker
    4.16 +{
    4.17 +public:
    4.18 +  virtual TypeId GetItemTypeId (void) const = 0;
    4.19 +};
    4.20  
    4.21 -ATTRIBUTE_CHECKER_DEFINE (ObjectVector);
    4.22 +template <typename T>
    4.23 +Ptr<const AttributeChecker> MakeObjectVectorChecker (void);
    4.24  
    4.25  } // namespace ns3
    4.26  
    4.27 @@ -72,6 +77,36 @@
    4.28    ObjectVector m_vector;
    4.29  };
    4.30  
    4.31 +
    4.32 +namespace internal {
    4.33 +
    4.34 +template <typename T>
    4.35 +class AnObjectVectorChecker : public ObjectVectorChecker
    4.36 +{
    4.37 +public:
    4.38 +  virtual TypeId GetItemTypeId (void) const {
    4.39 +    return T::GetTypeId ();
    4.40 +  }
    4.41 +  virtual bool Check (Attribute value) const {
    4.42 +    return value.DynCast<const ObjectVectorValue *> () != 0;
    4.43 +  }
    4.44 +  virtual std::string GetType (void) const {
    4.45 +    return "ns3::ObjectVector";
    4.46 +  }
    4.47 +  virtual bool HasTypeConstraints (void) const {
    4.48 +    return true;
    4.49 +  }
    4.50 +  virtual std::string GetTypeConstraints (void) const {
    4.51 +    return T::GetTypeId ().GetName ();
    4.52 +  }
    4.53 +  virtual Attribute Create (void) const {
    4.54 +    return Attribute::Create<ObjectVectorValue> ();
    4.55 +  }
    4.56 +};
    4.57 +
    4.58 +} // namespace internal
    4.59 +
    4.60 +
    4.61  class ObjectVectorAccessor : public AttributeAccessor
    4.62  {
    4.63  public:
    4.64 @@ -156,6 +191,13 @@
    4.65    return MakeObjectVectorAccessor (get, getN);
    4.66  }
    4.67  
    4.68 +template <typename T>
    4.69 +Ptr<const AttributeChecker> MakeObjectVectorChecker (void)
    4.70 +{
    4.71 +  return Create<internal::AnObjectVectorChecker<T> > ();
    4.72 +}
    4.73 +
    4.74 +
    4.75  } // namespace ns3
    4.76  
    4.77  #endif /* OBJECT_VECTOR_H */
     5.1 --- a/src/internet-node/ipv4-l3-protocol.cc	Wed Apr 09 14:28:16 2008 -0700
     5.2 +++ b/src/internet-node/ipv4-l3-protocol.cc	Wed Apr 09 14:58:52 2008 -0700
     5.3 @@ -64,7 +64,7 @@
     5.4      .AddAttribute ("InterfaceList", "The set of Ipv4 interfaces associated to this Ipv4 stack.",
     5.5                     ObjectVector (),
     5.6                     MakeObjectVectorAccessor (&Ipv4L3Protocol::m_interfaces),
     5.7 -                   MakeObjectVectorChecker ())
     5.8 +                   MakeObjectVectorChecker<Ipv4Interface> ())
     5.9      ;
    5.10    return tid;
    5.11  }
     6.1 --- a/src/internet-node/ipv4-l4-demux.cc	Wed Apr 09 14:28:16 2008 -0700
     6.2 +++ b/src/internet-node/ipv4-l4-demux.cc	Wed Apr 09 14:58:52 2008 -0700
     6.3 @@ -39,7 +39,7 @@
     6.4      .AddAttribute ("Protocols", "The set of protocols registered with this demux.",
     6.5                     ObjectVector (),
     6.6                     MakeObjectVectorAccessor (&Ipv4L4Demux::m_protocols),
     6.7 -                   MakeObjectVectorChecker ())
     6.8 +                   MakeObjectVectorChecker<Ipv4L4Protocol> ())
     6.9      ;
    6.10    return tid;
    6.11  }
     7.1 --- a/src/node/node-list.cc	Wed Apr 09 14:28:16 2008 -0700
     7.2 +++ b/src/node/node-list.cc	Wed Apr 09 14:58:52 2008 -0700
     7.3 @@ -63,7 +63,7 @@
     7.4      .AddAttribute ("NodeList", "The list of all nodes created during the simulation.",
     7.5                     ObjectVector (),
     7.6                     MakeObjectVectorAccessor (&NodeListPriv::m_nodes),
     7.7 -                   MakeObjectVectorChecker ())
     7.8 +                   MakeObjectVectorChecker<Node> ())
     7.9      ;
    7.10    return tid;
    7.11  }
     8.1 --- a/src/node/node.cc	Wed Apr 09 14:28:16 2008 -0700
     8.2 +++ b/src/node/node.cc	Wed Apr 09 14:58:52 2008 -0700
     8.3 @@ -39,11 +39,11 @@
     8.4      .AddAttribute ("DeviceList", "The list of devices associated to this Node.",
     8.5                     ObjectVector (),
     8.6                     MakeObjectVectorAccessor (&Node::m_devices),
     8.7 -                   MakeObjectVectorChecker ())
     8.8 +                   MakeObjectVectorChecker<NetDevice> ())
     8.9      .AddAttribute ("ApplicationList", "The list of applications associated to this Node.",
    8.10                     ObjectVector (),
    8.11                     MakeObjectVectorAccessor (&Node::m_applications),
    8.12 -                   MakeObjectVectorChecker ())
    8.13 +                   MakeObjectVectorChecker<Application> ())
    8.14      .AddAttribute ("Id", "The id (unique integer) of this Node.",
    8.15                     TypeId::ATTR_GET, // allow only getting it.
    8.16                     Uinteger (0),