src/core/object-factory.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 10 Mar 2008 13:09:32 -0700
changeset 2583 c09faa6c90bf
parent 2582 3e28107b870f
child 2586 50d78910a997
permissions -rw-r--r--
doxygen doc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2395
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
#include "object-factory.h"
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
#include <sstream>
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
namespace ns3 {
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
ObjectFactory::ObjectFactory ()
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
{}
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
void 
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
ObjectFactory::SetTypeId (TypeId tid)
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
{
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
  m_tid = tid;
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
}
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
void 
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
ObjectFactory::SetTypeId (std::string tid)
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
{
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
  m_tid = TypeId::LookupByName (tid);
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
}
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
void 
2488
c35c4f282206 add an extra overload of SetTypeId to avoid overload resolution confusions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    20
ObjectFactory::SetTypeId (const char *tid)
c35c4f282206 add an extra overload of SetTypeId to avoid overload resolution confusions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    21
{
c35c4f282206 add an extra overload of SetTypeId to avoid overload resolution confusions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    22
  m_tid = TypeId::LookupByName (tid);
c35c4f282206 add an extra overload of SetTypeId to avoid overload resolution confusions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    23
}
c35c4f282206 add an extra overload of SetTypeId to avoid overload resolution confusions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    24
void 
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2395
diff changeset
    25
ObjectFactory::Set (std::string name, Attribute value)
2395
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
{
2522
7c9d1c314beb report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    27
  if (name == "")
7c9d1c314beb report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    28
    {
7c9d1c314beb report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    29
      return;
7c9d1c314beb report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    30
    }
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2582
diff changeset
    31
  m_parameters.SetWithTid (m_tid, name, value);
2395
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
}
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
TypeId 
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
ObjectFactory::GetTypeId (void) const
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
{
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
  return m_tid;
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
}
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
Ptr<Object> 
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
ObjectFactory::Create (void) const
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
{
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
  Ptr<Object> object = m_tid.CreateObject (m_parameters);
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
  return object;
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
}
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
2555
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    47
std::ostream & operator << (std::ostream &os, const ObjectFactory &factory)
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    48
{
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2582
diff changeset
    49
  // XXX
2555
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    50
  return os;
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    51
}
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    52
std::istream & operator >> (std::istream &is, ObjectFactory &factory)
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    53
{
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2582
diff changeset
    54
  // XXX
2555
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    55
  return is;
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    56
}
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    57
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    58
2582
3e28107b870f rename old VALUE leftovers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2555
diff changeset
    59
ATTRIBUTE_HELPER_CPP (ObjectFactory);
2555
469bcb4d0010 give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2522
diff changeset
    60
2395
ffd1c96afe4b a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
} // namespace ns3