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