author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Sun, 02 Mar 2008 21:00:37 +0100 | |
changeset 2531 | b451b5fc8b57 |
parent 2522 | 7c9d1c314beb |
child 2555 | 469bcb4d0010 |
permissions | -rw-r--r-- |
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 |
} |
7c9d1c314beb
report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
31 |
if (!m_parameters.SetWithTid (m_tid, name, value)) |
7c9d1c314beb
report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
32 |
{ |
7c9d1c314beb
report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
33 |
NS_FATAL_ERROR ("Error setting attribute name="<<name); |
7c9d1c314beb
report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
34 |
} |
2395
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
} |
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 |
TypeId |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
38 |
ObjectFactory::GetTypeId (void) const |
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 |
return m_tid; |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
41 |
} |
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> |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
44 |
ObjectFactory::Create (void) const |
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 |
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
|
47 |
return object; |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
48 |
} |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
49 |
|
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
50 |
} // namespace ns3 |