src/core/object-vector.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 2965 4b28e9740e3b
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
     1 #include "object-vector.h"
     2 
     3 namespace ns3 {
     4 
     5 ObjectVectorValue::ObjectVectorValue ()
     6 {}
     7 
     8 ObjectVectorValue::Iterator 
     9 ObjectVectorValue::Begin (void) const
    10 {
    11   return m_objects.begin ();
    12 }
    13 ObjectVectorValue::Iterator 
    14 ObjectVectorValue::End (void) const
    15 {
    16   return m_objects.end ();
    17 }
    18 uint32_t 
    19 ObjectVectorValue::GetN (void) const
    20 {
    21   return m_objects.size ();
    22 }
    23 Ptr<Object> 
    24 ObjectVectorValue::Get (uint32_t i) const
    25 {
    26   return m_objects[i];
    27 }
    28 
    29 Ptr<AttributeValue>
    30 ObjectVectorValue::Copy (void) const
    31 {
    32   return ns3::Create<ObjectVectorValue> (*this);
    33 }
    34 std::string 
    35 ObjectVectorValue::SerializeToString (Ptr<const AttributeChecker> checker) const
    36 {
    37   std::ostringstream oss;
    38   for (uint32_t i = 0; i < m_objects.size (); ++i)
    39     {
    40       oss << m_objects[i];
    41       if (i != m_objects.size () - 1)
    42 	{
    43 	  oss << " ";
    44 	}
    45     }
    46   return oss.str ();
    47 }
    48 bool 
    49 ObjectVectorValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
    50 {
    51   NS_FATAL_ERROR ("cannot deserialize a vector of object pointers.");
    52   return true;
    53 }
    54 
    55 bool 
    56 ObjectVectorAccessor::Set (ObjectBase * object, const AttributeValue & value) const
    57 {
    58   // not allowed.
    59   return false;
    60 }
    61 bool 
    62 ObjectVectorAccessor::Get (const ObjectBase * object, AttributeValue &value) const
    63 {
    64   ObjectVectorValue *v = dynamic_cast<ObjectVectorValue *> (&value);
    65   if (v == 0)
    66     {
    67       return false;
    68     }
    69   v->m_objects.clear ();
    70   uint32_t n;
    71   bool ok = DoGetN (object, &n);
    72   if (!ok)
    73     {
    74       return false;
    75     }
    76   for (uint32_t i = 0; i < n; i++)
    77     {
    78       Ptr<Object> o = DoGet (object, i);
    79       v->m_objects.push_back (o);
    80     }
    81   return true;
    82 }
    83 bool 
    84 ObjectVectorAccessor::HasGetter (void) const
    85 {
    86   return true;
    87 }
    88 bool 
    89 ObjectVectorAccessor::HasSetter (void) const
    90 {
    91   return false;
    92 }
    93 
    94 } // name