src/core/object-vector.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 11 Apr 2008 11:25:21 -0700
changeset 2950 9e20fb862cd8
parent 2947 b0fec3381418
child 2965 4b28e9740e3b
permissions -rw-r--r--
add AttributeAccessor::HasGetter/HasSetter and implement it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
#include "object-vector.h"
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
namespace ns3 {
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
ObjectVector::ObjectVector ()
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
{}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
ObjectVector::Iterator 
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
ObjectVector::Begin (void) const
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
{
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
  return m_objects.begin ();
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
ObjectVector::Iterator 
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
ObjectVector::End (void) const
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
{
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
  return m_objects.end ();
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
uint32_t 
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
ObjectVector::GetN (void) const
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
{
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
  return m_objects.size ();
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
Ptr<Object> 
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
ObjectVector::Get (uint32_t i) const
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
{
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
  return m_objects[i];
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    29
ObjectVector::ObjectVector (Attribute value)
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
{
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
  const ObjectVectorValue *v = value.DynCast<const ObjectVectorValue *> ();
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
  if (v == 0)
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
    {
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
      NS_FATAL_ERROR ("Expected value of type ObjectVectorValue.");
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
    }
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
  *this = v->Get ();
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    39
ObjectVector::operator Attribute () const
2424
217a447122a6 split initial value from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2423
diff changeset
    40
{
2947
b0fec3381418 get rid of scary implementation details of Attribute.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
    41
  return Attribute (ns3::Create<ObjectVectorValue> ());
2424
217a447122a6 split initial value from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2423
diff changeset
    42
}
217a447122a6 split initial value from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2423
diff changeset
    43
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
ObjectVectorValue::ObjectVectorValue ()
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
  : m_vector ()
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
{}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
ObjectVectorValue::ObjectVectorValue (const ObjectVector &vector)
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
  : m_vector (vector)
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
{}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
ObjectVector 
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
ObjectVectorValue::Get (void) const
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
{
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
  return m_vector;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    58
Attribute 
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
ObjectVectorValue::Copy (void) const
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
{
2947
b0fec3381418 get rid of scary implementation details of Attribute.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
    61
  return Attribute (ns3::Create<ObjectVectorValue> (*this));
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
std::string 
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    64
ObjectVectorValue::SerializeToString (Ptr<const AttributeChecker> checker) const
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
{
2407
a39f985b9936 add XXX markers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2405
diff changeset
    66
  // XXX
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
  return "";
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
bool 
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    70
ObjectVectorValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
{
2407
a39f985b9936 add XXX markers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2405
diff changeset
    72
  // XXX ?? Can we implement this correctly ?? I doubt it very much.
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
  return true;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
bool 
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    77
ObjectVectorAccessor::Set (ObjectBase * object, Attribute value) const
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
{
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
  // not allowed.
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
  return false;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
}
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
bool 
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    83
ObjectVectorAccessor::Get (const ObjectBase * object, Attribute value) const
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
{
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
  ObjectVectorValue *v = value.DynCast<ObjectVectorValue *> ();
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
  if (v == 0)
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
    {
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
      return false;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
    }
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
  v->m_vector.m_objects.clear ();
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
  uint32_t n;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
  bool ok = DoGetN (object, &n);
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
  if (!ok)
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
    {
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
      return false;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
    }
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
  for (uint32_t i = 0; i < n; i++)
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
    {
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
      Ptr<Object> o = DoGet (object, i);
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
      v->m_vector.m_objects.push_back (o);
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
    }
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
  return true;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
}
2950
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   104
bool 
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   105
ObjectVectorAccessor::HasGetter (void) const
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   106
{
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   107
  return true;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   108
}
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   109
bool 
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   110
ObjectVectorAccessor::HasSetter (void) const
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   111
{
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   112
  return false;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   113
}
2599
fcc1728eb669 Add sufficient information to AttributeChecker to generate nice-looking doxygen documentation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2473
diff changeset
   114
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
} // name