00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef OBJECT_H
00022 #define OBJECT_H
00023
00024 #include <stdint.h>
00025 #include <string>
00026 #include <vector>
00027 #include "ptr.h"
00028 #include "attribute.h"
00029 #include "object-base.h"
00030 #include "attribute-list.h"
00031
00032
00033 namespace ns3 {
00034
00035 class Object;
00036 class AttributeAccessor;
00037 class AttributeValue;
00038 class AttributeList;
00039 class TraceSourceAccessor;
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 class Object : public ObjectBase
00059 {
00060 public:
00061 static TypeId GetTypeId (void);
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 class AggregateIterator
00072 {
00073 public:
00074 AggregateIterator ();
00075
00076
00077
00078
00079
00080 bool HasNext (void) const;
00081
00082
00083
00084
00085 Ptr<const Object> Next (void);
00086 private:
00087 friend class Object;
00088 AggregateIterator (Ptr<const Object> first);
00089 Ptr<const Object> m_first;
00090 Ptr<const Object> m_current;
00091 };
00092
00093 Object ();
00094 virtual ~Object ();
00095
00096
00097
00098
00099 virtual TypeId GetInstanceTypeId (void) const;
00100
00101
00102
00103
00104
00105
00106
00107 inline void Ref (void) const;
00108
00109
00110
00111
00112
00113
00114 inline void Unref (void) const;
00115
00116
00117
00118
00119 uint32_t GetReferenceCount (void) const;
00120
00121
00122
00123
00124 template <typename T>
00125 Ptr<T> GetObject (void) const;
00126
00127
00128
00129
00130 template <typename T>
00131 Ptr<T> GetObject (TypeId tid) const;
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 void Dispose (void);
00143
00144
00145
00146
00147
00148
00149
00150 void AggregateObject (Ptr<Object> other);
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 AggregateIterator GetAggregateIterator (void) const;
00161
00162 protected:
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 virtual void DoDispose (void);
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 Object (const Object &o);
00193 private:
00194
00195 template <typename T>
00196 friend Ptr<T> CreateObject (const AttributeList &attributes);
00197 template <typename T>
00198 friend Ptr<T> CopyObject (Ptr<T> object);
00199 template <typename T>
00200 friend Ptr<T> CopyObject (Ptr<const T> object);
00201
00202
00203
00204 friend void PythonCompleteConstruct (Ptr<Object> object, TypeId typeId, const AttributeList &attributes);
00205
00206 friend class ObjectFactory;
00207 friend class AggregateIterator;
00208
00209 Ptr<Object> DoGetObject (TypeId tid) const;
00210 bool Check (void) const;
00211 bool CheckLoose (void) const;
00212
00213
00214
00215
00216
00217
00218 void MaybeDelete (void) const;
00219
00220
00221
00222
00223
00224
00225
00226 void SetTypeId (TypeId tid);
00227
00228
00229
00230
00231
00232
00233
00234
00235 void Construct (const AttributeList &attributes);
00236
00237
00238
00239
00240
00241
00242
00243
00244 mutable uint32_t m_count;
00245
00246
00247
00248 TypeId m_tid;
00249
00250
00251
00252
00253 bool m_disposed;
00254
00255
00256
00257
00258
00259
00260
00261 Object *m_next;
00262 };
00263
00264
00265
00266
00267
00268
00269
00270
00271 template <typename T>
00272 Ptr<T> CopyObject (Ptr<const T> object);
00273 template <typename T>
00274 Ptr<T> CopyObject (Ptr<T> object);
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 template <typename T>
00286 Ptr<T> CreateObject (const AttributeList &attributes);
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 template <typename T>
00313 Ptr<T>
00314 CreateObject (std::string n1 = "", const AttributeValue & v1 = EmptyAttributeValue (),
00315 std::string n2 = "", const AttributeValue & v2 = EmptyAttributeValue (),
00316 std::string n3 = "", const AttributeValue & v3 = EmptyAttributeValue (),
00317 std::string n4 = "", const AttributeValue & v4 = EmptyAttributeValue (),
00318 std::string n5 = "", const AttributeValue & v5 = EmptyAttributeValue (),
00319 std::string n6 = "", const AttributeValue & v6 = EmptyAttributeValue (),
00320 std::string n7 = "", const AttributeValue & v7 = EmptyAttributeValue (),
00321 std::string n8 = "", const AttributeValue & v8 = EmptyAttributeValue (),
00322 std::string n9 = "", const AttributeValue & v9 = EmptyAttributeValue ());
00323
00324
00325
00326 }
00327
00328 namespace ns3 {
00329
00330
00331
00332
00333
00334 void
00335 Object::Ref (void) const
00336 {
00337 m_count++;
00338 }
00339 void
00340 Object::Unref (void) const
00341 {
00342 NS_ASSERT (Check ());
00343 m_count--;
00344 if (m_count == 0)
00345 {
00346 MaybeDelete ();
00347 }
00348 }
00349
00350 template <typename T>
00351 Ptr<T>
00352 Object::GetObject () const
00353 {
00354 Ptr<Object> found = DoGetObject (T::GetTypeId ());
00355 if (found != 0)
00356 {
00357 return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
00358 }
00359 return 0;
00360 }
00361
00362 template <typename T>
00363 Ptr<T>
00364 Object::GetObject (TypeId tid) const
00365 {
00366 Ptr<Object> found = DoGetObject (tid);
00367 if (found != 0)
00368 {
00369 return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
00370 }
00371 return 0;
00372 }
00373
00374
00375
00376
00377
00378 template <typename T>
00379 Ptr<T> CopyObject (Ptr<T> object)
00380 {
00381 Ptr<T> p = Ptr<T> (new T (*PeekPointer (object)), false);
00382 NS_ASSERT (p->GetInstanceTypeId () == object->GetInstanceTypeId ());
00383 return p;
00384 }
00385
00386 template <typename T>
00387 Ptr<T> CopyObject (Ptr<const T> object)
00388 {
00389 Ptr<T> p = Ptr<T> (new T (*PeekPointer (object)), false);
00390 NS_ASSERT (p->GetInstanceTypeId () == object->GetInstanceTypeId ());
00391 return p;
00392 }
00393
00394
00395 template <typename T>
00396 Ptr<T> CreateObject (const AttributeList &attributes)
00397 {
00398 Ptr<T> p = Ptr<T> (new T (), false);
00399 p->SetTypeId (T::GetTypeId ());
00400 p->Object::Construct (attributes);
00401 return p;
00402 }
00403
00404 template <typename T>
00405 Ptr<T>
00406 CreateObject (std::string n1 = "", const AttributeValue & v1 = EmptyAttributeValue (),
00407 std::string n2 = "", const AttributeValue & v2 = EmptyAttributeValue (),
00408 std::string n3 = "", const AttributeValue & v3 = EmptyAttributeValue (),
00409 std::string n4 = "", const AttributeValue & v4 = EmptyAttributeValue (),
00410 std::string n5 = "", const AttributeValue & v5 = EmptyAttributeValue (),
00411 std::string n6 = "", const AttributeValue & v6 = EmptyAttributeValue (),
00412 std::string n7 = "", const AttributeValue & v7 = EmptyAttributeValue (),
00413 std::string n8 = "", const AttributeValue & v8 = EmptyAttributeValue (),
00414 std::string n9 = "", const AttributeValue & v9 = EmptyAttributeValue ())
00415 {
00416 AttributeList attributes;
00417 if (n1 == "")
00418 {
00419 goto end;
00420 }
00421 attributes.SetWithTid (T::GetTypeId (), n1, v1);
00422 if (n2 == "")
00423 {
00424 goto end;
00425 }
00426 attributes.SetWithTid (T::GetTypeId (), n2, v2);
00427 if (n3 == "")
00428 {
00429 goto end;
00430 }
00431 attributes.SetWithTid (T::GetTypeId (), n3, v3);
00432 if (n4 == "")
00433 {
00434 goto end;
00435 }
00436 attributes.SetWithTid (T::GetTypeId (), n4, v4);
00437 if (n5 == "")
00438 {
00439 goto end;
00440 }
00441 attributes.SetWithTid (T::GetTypeId (), n5, v5);
00442 if (n6 == "")
00443 {
00444 goto end;
00445 }
00446 attributes.SetWithTid (T::GetTypeId (), n6, v6);
00447 if (n7 == "")
00448 {
00449 goto end;
00450 }
00451 attributes.SetWithTid (T::GetTypeId (), n7, v7);
00452 if (n8 == "")
00453 {
00454 goto end;
00455 }
00456 attributes.SetWithTid (T::GetTypeId (), n8, v8);
00457 if (n9 == "")
00458 {
00459 goto end;
00460 }
00461 attributes.SetWithTid (T::GetTypeId (), n9, v9);
00462 end:
00463 return CreateObject<T> (attributes);
00464 }
00465
00466 }
00467
00468 #endif
00469