A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
object.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 INRIA, Gustavo Carneiro
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Gustavo Carneiro <gjcarneiro@gmail.com>,
19
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
*/
21
#ifndef OBJECT_H
22
#define OBJECT_H
23
24
#include <stdint.h>
25
#include <string>
26
#include <vector>
27
#include "
ptr.h
"
28
#include "
attribute.h
"
29
#include "
object-base.h
"
30
#include "
attribute-construction-list.h
"
31
#include "
simple-ref-count.h
"
32
33
34
namespace
ns3 {
35
36
class
Object;
37
class
AttributeAccessor;
38
class
AttributeValue;
39
class
TraceSourceAccessor;
40
41
struct
ObjectDeleter
42
{
43
inline
static
void
Delete
(
Object
*
object
);
44
};
45
63
class
Object
:
public
SimpleRefCount
<Object,ObjectBase,ObjectDeleter>
64
{
65
public
:
69
static
TypeId
GetTypeId
(
void
);
70
79
class
AggregateIterator
80
{
81
public
:
82
AggregateIterator
();
83
88
bool
HasNext
(
void
)
const
;
89
93
Ptr<const Object>
Next
(
void
);
94
private
:
95
friend
class
Object
;
96
AggregateIterator
(
Ptr<const Object>
object
);
97
Ptr<const Object>
m_object
;
98
uint32_t
m_current
;
99
};
100
101
Object
();
102
virtual
~Object
();
103
104
/*
105
* Implement the GetInstanceTypeId method defined in ObjectBase.
106
*/
107
virtual
TypeId
GetInstanceTypeId
(
void
)
const
;
108
112
template
<
typename
T>
113
inline
Ptr<T>
GetObject
(
void
)
const
;
118
template
<
typename
T>
119
Ptr<T>
GetObject
(
TypeId
tid)
const
;
132
void
Dispose
(
void
);
146
void
AggregateObject
(
Ptr<Object>
other);
147
156
AggregateIterator
GetAggregateIterator
(
void
)
const
;
157
166
void
Initialize
(
void
);
167
168
protected
:
176
virtual
void
NotifyNewAggregate
(
void
);
186
virtual
void
DoInitialize
(
void
);
200
virtual
void
DoDispose
(
void
);
218
Object
(
const
Object
&o);
219
private
:
220
221
template
<
typename
T>
222
friend
Ptr<T>
CopyObject
(
Ptr<T>
object
);
223
template
<
typename
T>
224
friend
Ptr<T>
CopyObject
(
Ptr<const T>
object
);
225
template
<
typename
T>
226
friend
Ptr<T>
CompleteConstruct
(T *
object
);
227
228
friend
class
ObjectFactory
;
229
friend
class
AggregateIterator
;
230
friend
struct
ObjectDeleter
;
231
242
struct
Aggregates
{
243
uint32_t
n
;
244
Object
*
buffer
[1];
245
};
246
253
Ptr<Object>
DoGetObject
(
TypeId
tid)
const
;
257
bool
Check
(
void
)
const
;
268
bool
CheckLoose
(
void
)
const
;
276
void
SetTypeId
(
TypeId
tid);
285
void
Construct
(
const
AttributeConstructionList
&attributes);
286
293
void
UpdateSortedArray
(
struct
Aggregates
*aggregates, uint32_t i)
const
;
300
void
DoDelete
(
void
);
301
305
TypeId
m_tid
;
310
bool
m_disposed
;
315
bool
m_initialized
;
322
struct
Aggregates
*
m_aggregates
;
329
uint32_t
m_getObjectCount
;
330
};
331
339
template
<
typename
T>
340
Ptr<T>
CopyObject
(
Ptr<const T>
object
);
341
template
<
typename
T>
342
Ptr<T>
CopyObject
(
Ptr<T>
object
);
343
344
}
// namespace ns3
345
346
namespace
ns3 {
347
348
void
349
ObjectDeleter::Delete
(
Object
*
object
)
350
{
351
object
->DoDelete ();
352
}
353
354
/*************************************************************************
355
* The Object implementation which depends on templates
356
*************************************************************************/
357
358
template
<
typename
T>
359
Ptr<T>
360
Object::GetObject
()
const
361
{
362
// This is an optimization: if the cast works (which is likely),
363
// things will be pretty fast.
364
T *result =
dynamic_cast<
T *
>
(
m_aggregates
->
buffer
[0]);
365
if
(result != 0)
366
{
367
return
Ptr<T>
(result);
368
}
369
// if the cast does not work, we try to do a full type check.
370
Ptr<Object>
found =
DoGetObject
(T::GetTypeId ());
371
if
(found != 0)
372
{
373
return
Ptr<T>
(
static_cast<
T *
>
(
PeekPointer
(found)));
374
}
375
return
0;
376
}
377
378
template
<
typename
T>
379
Ptr<T>
380
Object::GetObject
(
TypeId
tid)
const
381
{
382
Ptr<Object>
found =
DoGetObject
(tid);
383
if
(found != 0)
384
{
385
return
Ptr<T>
(
static_cast<
T *
>
(
PeekPointer
(found)));
386
}
387
return
0;
388
}
389
390
/*************************************************************************
391
* The helper functions which need templates.
392
*************************************************************************/
393
394
template
<
typename
T>
395
Ptr<T>
CopyObject
(
Ptr<T>
object
)
396
{
397
Ptr<T>
p =
Ptr<T>
(
new
T (*
PeekPointer
(
object
)),
false
);
398
NS_ASSERT
(p->GetInstanceTypeId () ==
object
->GetInstanceTypeId ());
399
return
p;
400
}
401
402
template
<
typename
T>
403
Ptr<T>
CopyObject
(Ptr<const T>
object
)
404
{
405
Ptr<T> p = Ptr<T> (
new
T (*
PeekPointer
(
object
)),
false
);
406
NS_ASSERT
(p->GetInstanceTypeId () ==
object
->GetInstanceTypeId ());
407
return
p;
408
}
409
410
template
<
typename
T>
411
Ptr<T>
CompleteConstruct
(T *p)
412
{
413
p->SetTypeId (T::GetTypeId ());
414
p->Object::Construct (
AttributeConstructionList
());
415
return
Ptr<T>
(p,
false
);
416
}
417
418
template
<
typename
T>
419
Ptr<T>
CreateObject
(
void
)
420
{
421
return
CompleteConstruct
(
new
T ());
422
}
423
424
template
<
typename
T,
typename
T1>
425
Ptr<T>
CreateObject
(T1 a1)
426
{
427
return
CompleteConstruct
(
new
T (a1));
428
}
429
430
template
<
typename
T,
typename
T1,
typename
T2>
431
Ptr<T>
CreateObject
(T1 a1, T2 a2)
432
{
433
return
CompleteConstruct
(
new
T (a1,a2));
434
}
435
436
template
<
typename
T,
typename
T1,
typename
T2,
typename
T3>
437
Ptr<T>
CreateObject
(T1 a1, T2 a2, T3 a3)
438
{
439
return
CompleteConstruct
(
new
T (a1,a2,a3));
440
}
441
442
template
<
typename
T,
typename
T1,
typename
T2,
typename
T3,
typename
T4>
443
Ptr<T>
CreateObject
(T1 a1, T2 a2, T3 a3, T4 a4)
444
{
445
return
CompleteConstruct
(
new
T (a1,a2,a3,a4));
446
}
447
448
template
<
typename
T,
typename
T1,
typename
T2,
typename
T3,
typename
T4,
typename
T5>
449
Ptr<T>
CreateObject
(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
450
{
451
return
CompleteConstruct
(
new
T (a1,a2,a3,a4,a5));
452
}
453
454
template
<
typename
T,
typename
T1,
typename
T2,
typename
T3,
typename
T4,
typename
T5,
typename
T6>
455
Ptr<T>
CreateObject
(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
456
{
457
return
CompleteConstruct
(
new
T (a1,a2,a3,a4,a5,a6));
458
}
459
460
template
<
typename
T,
typename
T1,
typename
T2,
typename
T3,
typename
T4,
typename
T5,
typename
T6,
typename
T7>
461
Ptr<T>
CreateObject
(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
462
{
463
return
CompleteConstruct
(
new
T (a1,a2,a3,a4,a5,a6,a7));
464
}
465
466
467
}
// namespace ns3
468
469
#endif
/* OBJECT_H */
470
src
core
model
object.h
Generated on Fri Aug 30 2013 01:42:47 for ns-3 by
1.8.1.2