author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Wed, 11 Jun 2008 16:18:38 -0700 | |
changeset 3891 | 590b21d7fcdd |
parent 2965 | 4b28e9740e3b |
permissions | -rw-r--r-- |
2586
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
2 |
/* |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
3 |
* Copyright (c) 2008 INRIA |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
4 |
* |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
7 |
* published by the Free Software Foundation; |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
8 |
* |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
12 |
* GNU General Public License for more details. |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
13 |
* |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
17 |
* |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
18 |
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
50d78910a997
add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2583
diff
changeset
|
19 |
*/ |
2395
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
#include "object-factory.h" |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
#include <sstream> |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
|
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
namespace ns3 { |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
|
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
ObjectFactory::ObjectFactory () |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
{} |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
|
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
void |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
ObjectFactory::SetTypeId (TypeId tid) |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
{ |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
31 |
m_tid = tid; |
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 |
void |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
ObjectFactory::SetTypeId (std::string tid) |
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 |
m_tid = TypeId::LookupByName (tid); |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
37 |
} |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
{ |
c35c4f282206
add an extra overload of SetTypeId to avoid overload resolution confusions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2433
diff
changeset
|
41 |
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
|
42 |
} |
c35c4f282206
add an extra overload of SetTypeId to avoid overload resolution confusions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2433
diff
changeset
|
43 |
void |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2956
diff
changeset
|
44 |
ObjectFactory::Set (std::string name, const AttributeValue &value) |
2395
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
45 |
{ |
2522
7c9d1c314beb
report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
46 |
if (name == "") |
7c9d1c314beb
report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
47 |
{ |
7c9d1c314beb
report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
48 |
return; |
7c9d1c314beb
report attribute setting errors as early as possible.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
49 |
} |
2583
c09faa6c90bf
doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2582
diff
changeset
|
50 |
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
|
51 |
} |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
52 |
|
3891
590b21d7fcdd
add missing Setter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2965
diff
changeset
|
53 |
void |
590b21d7fcdd
add missing Setter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2965
diff
changeset
|
54 |
ObjectFactory::Set (const AttributeList &list) |
590b21d7fcdd
add missing Setter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2965
diff
changeset
|
55 |
{ |
590b21d7fcdd
add missing Setter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2965
diff
changeset
|
56 |
m_parameters = list; |
590b21d7fcdd
add missing Setter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2965
diff
changeset
|
57 |
} |
590b21d7fcdd
add missing Setter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2965
diff
changeset
|
58 |
|
2395
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
59 |
TypeId |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
60 |
ObjectFactory::GetTypeId (void) const |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
61 |
{ |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
62 |
return m_tid; |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
63 |
} |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
64 |
|
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
Ptr<Object> |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
ObjectFactory::Create (void) const |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
{ |
2631
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2586
diff
changeset
|
68 |
Callback<ObjectBase *> cb = m_tid.GetConstructor (); |
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2586
diff
changeset
|
69 |
ObjectBase *base = cb (); |
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2586
diff
changeset
|
70 |
Object *derived = dynamic_cast<Object *> (base); |
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2586
diff
changeset
|
71 |
derived->SetTypeId (m_tid); |
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2586
diff
changeset
|
72 |
derived->Construct (m_parameters); |
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2586
diff
changeset
|
73 |
Ptr<Object> object = Ptr<Object> (derived, false); |
2395
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
74 |
return object; |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
75 |
} |
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
76 |
|
2555
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
77 |
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
|
78 |
{ |
2952
d5047d6ce4ce
implement operator << for ObjectFactory.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2631
diff
changeset
|
79 |
os << factory.m_tid.GetName () << "[" << factory.m_parameters.SerializeToString () << "]"; |
2555
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
80 |
return os; |
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
81 |
} |
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
82 |
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
|
83 |
{ |
2956
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
84 |
std::string v; |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
85 |
is >> v; |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
86 |
std::string::size_type lbracket, rbracket; |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
87 |
lbracket = v.find ("["); |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
88 |
rbracket = v.find ("]"); |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
89 |
NS_ASSERT (lbracket != std::string::npos); |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
90 |
NS_ASSERT (rbracket != std::string::npos); |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
91 |
std::string tid = v.substr (0, lbracket); |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
92 |
std::string parameters = v.substr (lbracket+1,rbracket-(lbracket+1)); |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
93 |
factory.SetTypeId (tid); |
1c1345207c74
implement operator >>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2952
diff
changeset
|
94 |
factory.m_parameters.DeserializeFromString (parameters); |
2555
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
95 |
return is; |
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
96 |
} |
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
97 |
|
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
98 |
|
2582
3e28107b870f
rename old VALUE leftovers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2555
diff
changeset
|
99 |
ATTRIBUTE_HELPER_CPP (ObjectFactory); |
2555
469bcb4d0010
give Attribute power to ObjectFactory class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2522
diff
changeset
|
100 |
|
2395
ffd1c96afe4b
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
101 |
} // namespace ns3 |