author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 24 Mar 2008 13:04:55 -0700 | |
changeset 2716 | 2319c4bde708 |
parent 2637 | ac94e4889027 |
child 2718 | 9fe723baa16b |
permissions | -rw-r--r-- |
2370
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
#ifndef OBJECT_BASE_H |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
#define OBJECT_BASE_H |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
|
2633
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
4 |
#include "type-id.h" |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
5 |
#include "callback.h" |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
6 |
#include "attribute-list.h" |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
7 |
#include <string> |
2633
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
8 |
|
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
9 |
/** |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
10 |
* This macro should be invoked once for every class which |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
11 |
* defines a new GetTypeId method. |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
12 |
*/ |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
13 |
#define NS_OBJECT_ENSURE_REGISTERED(type) \ |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
14 |
static struct X##type##RegistrationClass \ |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
15 |
{ \ |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
16 |
X##type##RegistrationClass () { \ |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
17 |
ns3::TypeId tid = type::GetTypeId (); \ |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
18 |
tid.GetParent (); \ |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
19 |
} \ |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
20 |
} x_##type##RegistrationVariable |
a0639de8cd8b
split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2370
diff
changeset
|
21 |
|
2370
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
namespace ns3 { |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
|
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
/** |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
* This base class is really used only to make sure that |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
* every subclass has RTTI information and that they all |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
* share a single base class to allow us to make type |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
* checks across all these types. |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
*/ |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
class ObjectBase |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
31 |
{ |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
public: |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
33 |
static TypeId GetTypeId (void); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
34 |
|
2370
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
virtual ~ObjectBase (); |
2716
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
36 |
|
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
37 |
/** |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
38 |
* \returns the TypeId associated to the most-derived type |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
39 |
* of this instance. |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
40 |
* |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
41 |
* This method is typically implemented by ns3::Object::GetInstanceTypeId |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
42 |
* but some classes which derive from ns3::ObjectBase directly |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
43 |
* have to implement it themselves. |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
44 |
*/ |
2634
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
45 |
virtual TypeId GetInstanceTypeId (void) const = 0; |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
46 |
|
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
47 |
/** |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
48 |
* \param name the name of the attribute to set |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
49 |
* \param value the name of the attribute to set |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
50 |
* |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
51 |
* Set a single attribute. This cannot fail: if the input is invalid, |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
52 |
* it will crash immediately. |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
53 |
*/ |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
54 |
void SetAttribute (std::string name, Attribute value); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
55 |
/** |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
56 |
* \param name the name of the attribute to set |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
57 |
* \param value the name of the attribute to set |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
58 |
* \returns true if the requested attribute exists and could be set, |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
59 |
* false otherwise. |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
60 |
*/ |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
61 |
bool SetAttributeFailSafe (std::string name, Attribute value); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
62 |
/** |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
63 |
* \param name the name of the attribute to read |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
64 |
* \returns true if the requested attribute was found, false otherwise. |
2716
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
65 |
* |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
66 |
* If the input attribute name does not exist, this method crashes. |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
67 |
*/ |
2716
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
68 |
std::string GetAttributeAsString (std::string name) const; |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
69 |
/** |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
70 |
* \param name the name of the attribute to read |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
71 |
* \returns the attribute read. |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
72 |
* |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
73 |
* If the input attribute name does not exist, this method crashes. |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
74 |
*/ |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
75 |
Attribute GetAttribute (std::string name) const; |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
76 |
|
2716
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
77 |
/** |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
78 |
* \param name the name of the attribute to read |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
79 |
* \param value the string where the result value should be stored |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
80 |
* \returns true if the requested attribute was found, false otherwise. |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
81 |
*/ |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
82 |
bool GetAttributeAsStringFailSafe (std::string name, std::string &value) const; |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
83 |
/** |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
84 |
* \param name the name of the attribute to read |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
85 |
* \param attribute the attribute where the result value should be stored |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
86 |
* \returns true if the requested attribute was found, false otherwise. |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
87 |
* |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
88 |
* If the input attribute name does not exist, this method crashes. |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
89 |
*/ |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
90 |
bool GetAttributeFailSafe (std::string name, Attribute &attribute) const; |
2319c4bde708
use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
91 |
|
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
92 |
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
93 |
bool TraceConnectWithoutContext (std::string name, std::string context, const CallbackBase &cb); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
94 |
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
95 |
bool TraceDisconnectWithoutContext (std::string name, std::string context, const CallbackBase &cb); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
96 |
|
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
97 |
protected: |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
98 |
virtual void NotifyConstructionCompleted (void); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
99 |
/** |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
100 |
* \param attributes the attribute values used to initialize |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
101 |
* the member variables of this object's instance. |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
102 |
* |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
103 |
* Invoked from subclasses to initialize all of their |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
104 |
* attribute members. |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
105 |
*/ |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
106 |
void ConstructSelf (const AttributeList &attributes); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
107 |
|
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
108 |
private: |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
109 |
bool DoSet (Ptr<const AttributeAccessor> spec, Attribute intialValue, |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
110 |
Ptr<const AttributeChecker> checker, Attribute value); |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2634
diff
changeset
|
111 |
|
2370
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
112 |
}; |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
113 |
|
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
114 |
} // namespace ns3 |
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
115 |
|
5f7ad186b798
introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
116 |
#endif /* OBJECT_BASE_H */ |