author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 05 Nov 2009 21:04:05 +0100 | |
changeset 5479 | b1f7a3a87887 |
parent 5474 | c409fe8019c9 |
child 5486 | 9bf34ba759a3 |
permissions | -rw-r--r-- |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2007 INRIA, Gustavo Carneiro |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* Authors: Gustavo Carneiro <gjcarneiro@gmail.com>, |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
*/ |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
21 |
#include "test.h" |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
22 |
#include "object.h" |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
23 |
#include "object-factory.h" |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
#include "assert.h" |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
#include "singleton.h" |
2438
e2ac9f9aeeb9
value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2436
diff
changeset
|
26 |
#include "attribute.h" |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1420
diff
changeset
|
27 |
#include "log.h" |
2502
50d0da37f02f
introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2489
diff
changeset
|
28 |
#include "string.h" |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
#include <vector> |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
30 |
#include <sstream> |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
31 |
#include <stdlib.h> |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
32 |
#include <string.h> |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1420
diff
changeset
|
34 |
NS_LOG_COMPONENT_DEFINE ("Object"); |
1374
77468496f7e0
avoid problems with recursive use of Object::DoCollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1372
diff
changeset
|
35 |
|
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
36 |
namespace ns3 { |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
37 |
|
2233
b359c83c5fbe
add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
38 |
/********************************************************************* |
b359c83c5fbe
add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
39 |
* The Object implementation |
b359c83c5fbe
add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
40 |
*********************************************************************/ |
b359c83c5fbe
add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
41 |
|
2247
56b3591fa3b0
use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2243
diff
changeset
|
42 |
NS_OBJECT_ENSURE_REGISTERED (Object); |
56b3591fa3b0
use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2243
diff
changeset
|
43 |
|
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
44 |
Object::AggregateIterator::AggregateIterator () |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
45 |
: m_object (0), |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
46 |
m_current (0) |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
47 |
{} |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
48 |
|
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
49 |
bool |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
50 |
Object::AggregateIterator::HasNext (void) const |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
51 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
52 |
return m_current < m_object->m_aggregates->n; |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
53 |
} |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
54 |
Ptr<const Object> |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
55 |
Object::AggregateIterator::Next (void) |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
56 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
57 |
return m_object->m_aggregates->buffer[m_current]; |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
58 |
} |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
59 |
Object::AggregateIterator::AggregateIterator (Ptr<const Object> object) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
60 |
: m_object (object), |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
61 |
m_current (0) |
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
62 |
{} |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
63 |
|
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
64 |
|
2250
18f432098389
InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2247
diff
changeset
|
65 |
TypeId |
2634
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
66 |
Object::GetInstanceTypeId (void) const |
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
67 |
{ |
2636
fe664ae9aa8b
return the _current_ tid, not the Object tid.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2635
diff
changeset
|
68 |
return m_tid; |
2634
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
69 |
} |
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
70 |
|
44a92f1d3728
introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2633
diff
changeset
|
71 |
TypeId |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
72 |
Object::GetTypeId (void) |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
73 |
{ |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2636
diff
changeset
|
74 |
static TypeId tid = TypeId ("ns3::Object") |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2636
diff
changeset
|
75 |
.SetParent<ObjectBase> () |
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2636
diff
changeset
|
76 |
; |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
77 |
return tid; |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
78 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
79 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
80 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
81 |
Object::Object () |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
82 |
: m_count (1), |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
83 |
m_tid (Object::GetTypeId ()), |
713
c3c745a80610
add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
712
diff
changeset
|
84 |
m_disposed (false), |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
85 |
m_aggregates ((struct Aggregates *)malloc (sizeof (struct Aggregates))), |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
86 |
m_getObjectCount (0) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
87 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
88 |
m_aggregates->n = 1; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
89 |
m_aggregates->buffer[0] = this; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
90 |
} |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
91 |
Object::~Object () |
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
92 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
93 |
// remove this object from the aggregate list |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
94 |
uint32_t n = m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
95 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
96 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
97 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
98 |
if (current == this) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
99 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
100 |
memmove (&m_aggregates->buffer[i], |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
101 |
&m_aggregates->buffer[i+1], |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
102 |
sizeof (Object *)*(m_aggregates->n - (i+1))); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
103 |
m_aggregates->n--; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
104 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
105 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
106 |
// finally, if all objects have been removed from the list, |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
107 |
// delete the aggregate list |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
108 |
if (m_aggregates->n == 0) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
109 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
110 |
free (m_aggregates); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
111 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
112 |
m_aggregates = 0; |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
113 |
} |
2667
2324032b8f90
Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
114 |
Object::Object (const Object &o) |
2324032b8f90
Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
115 |
: m_count (1), |
2324032b8f90
Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
116 |
m_tid (o.m_tid), |
2324032b8f90
Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2637
diff
changeset
|
117 |
m_disposed (false), |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
118 |
m_aggregates ((struct Aggregates *)malloc (sizeof (struct Aggregates))), |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
119 |
m_getObjectCount (0) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
120 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
121 |
m_aggregates->n = 1; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
122 |
m_aggregates->buffer[0] = this; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
123 |
} |
3394
1680d5004ee8
add Object::GetReferenceCount
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3033
diff
changeset
|
124 |
uint32_t |
1680d5004ee8
add Object::GetReferenceCount
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3033
diff
changeset
|
125 |
Object::GetReferenceCount (void) const |
1680d5004ee8
add Object::GetReferenceCount
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3033
diff
changeset
|
126 |
{ |
1680d5004ee8
add Object::GetReferenceCount
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3033
diff
changeset
|
127 |
return m_count; |
1680d5004ee8
add Object::GetReferenceCount
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3033
diff
changeset
|
128 |
} |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
129 |
void |
2459
91662d921a83
Attributes -> AttributeList
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2458
diff
changeset
|
130 |
Object::Construct (const AttributeList &attributes) |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
131 |
{ |
2637
ac94e4889027
move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2636
diff
changeset
|
132 |
ConstructSelf (attributes); |
2569
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2542
diff
changeset
|
133 |
} |
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2460
diff
changeset
|
134 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
135 |
Ptr<Object> |
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
136 |
Object::DoGetObject (TypeId tid) const |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
137 |
{ |
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
138 |
NS_ASSERT (CheckLoose ()); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
139 |
|
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
140 |
uint32_t n = m_aggregates->n; |
3871
c6f693de286d
5% cpu optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3397
diff
changeset
|
141 |
TypeId objectTid = Object::GetTypeId (); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
142 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
143 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
144 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
145 |
TypeId cur = current->GetInstanceTypeId (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
146 |
while (cur != tid && cur != objectTid) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
147 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
148 |
cur = cur.GetParent (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
149 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
150 |
if (cur == tid) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
151 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
152 |
// This is an attempt to 'cache' the result of this lookup. |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
153 |
// the idea is that if we perform a lookup for a TypeId on this object, |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
154 |
// we are likely to perform the same lookup later so, we make sure |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
155 |
// that the aggregate array is sorted by the number of accesses |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
156 |
// to each object. |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
157 |
|
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
158 |
// first, increment the access count |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
159 |
current->m_getObjectCount++; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
160 |
// then, update the sort |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
161 |
UpdateSortedArray (m_aggregates, i); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
162 |
// finally, return the match |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
163 |
return const_cast<Object *> (current); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
164 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
165 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
166 |
return 0; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
167 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
168 |
void |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
169 |
Object::Dispose (void) |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
170 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
171 |
uint32_t n = m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
172 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
173 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
174 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
175 |
NS_ASSERT (!current->m_disposed); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
176 |
current->DoDispose (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
177 |
current->m_disposed = true; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
178 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
179 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
180 |
void |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
181 |
Object::UpdateSortedArray (struct Aggregates *aggregates, uint32_t j) const |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
182 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
183 |
while (j > 0 && |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
184 |
aggregates->buffer[j]->m_getObjectCount > aggregates->buffer[j-1]->m_getObjectCount) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
185 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
186 |
Object *tmp = aggregates->buffer[j-1]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
187 |
aggregates->buffer[j-1] = aggregates->buffer[j]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
188 |
aggregates->buffer[j] = tmp; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
189 |
j--; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
190 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
191 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
192 |
void |
2258
666099a753e0
AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
193 |
Object::AggregateObject (Ptr<Object> o) |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
194 |
{ |
718 | 195 |
NS_ASSERT (!m_disposed); |
196 |
NS_ASSERT (!o->m_disposed); |
|
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
197 |
NS_ASSERT (CheckLoose ()); |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
198 |
NS_ASSERT (o->CheckLoose ()); |
2902
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
199 |
|
3397
cad55f67f3fc
avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3394
diff
changeset
|
200 |
if (DoGetObject (o->GetInstanceTypeId ())) |
2902
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
201 |
{ |
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
202 |
NS_FATAL_ERROR ("Object::AggregateObject(): " |
3397
cad55f67f3fc
avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3394
diff
changeset
|
203 |
"Multiple aggregation of objects of type " << |
cad55f67f3fc
avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3394
diff
changeset
|
204 |
o->GetInstanceTypeId ().GetName ()); |
2902
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
205 |
} |
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2717
diff
changeset
|
206 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
207 |
Object *other = PeekPointer (o); |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
208 |
// first create the new aggregate buffer. |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
209 |
uint32_t total = m_aggregates->n + other->m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
210 |
struct Aggregates *aggregates = |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
211 |
(struct Aggregates *)malloc (sizeof(struct Aggregates)+(total-1)*sizeof(Object*)); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
212 |
aggregates->n = total; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
213 |
memcpy (&aggregates->buffer[0], |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
214 |
&m_aggregates->buffer[0], |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
215 |
m_aggregates->n*sizeof(Object*)); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
216 |
// append the other aggregates in the new buffer |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
217 |
for (uint32_t i = 0; i < other->m_aggregates->n; i++) |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
218 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
219 |
aggregates->buffer[m_aggregates->n+i] = other->m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
220 |
UpdateSortedArray (aggregates, m_aggregates->n + i); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
221 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
222 |
|
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
223 |
// free both aggregate buffers |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
224 |
free (m_aggregates); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
225 |
free (other->m_aggregates); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
226 |
|
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
227 |
// Then, assign that buffer to every object |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
228 |
uint32_t n = aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
229 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
230 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
231 |
Object *current = aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
232 |
current->m_aggregates = aggregates; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
233 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
234 |
// Finally, call NotifyNewAggregate in the listed chain |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
235 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
236 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
237 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
238 |
current->NotifyNewAggregate (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
239 |
} |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
240 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
241 |
/** |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
242 |
* This function must be implemented in the stack that needs to notify |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
243 |
* other stacks connected to the node of their presence in the node. |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
244 |
*/ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
245 |
void |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
246 |
Object::NotifyNewAggregate () |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
247 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
3871
diff
changeset
|
248 |
|
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
249 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
250 |
|
2937
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
251 |
Object::AggregateIterator |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
252 |
Object::GetAggregateIterator (void) const |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
253 |
{ |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
254 |
return AggregateIterator (this); |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
255 |
} |
fc048c358357
iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2717
diff
changeset
|
256 |
|
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
257 |
void |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
258 |
Object::SetTypeId (TypeId tid) |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
259 |
{ |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
260 |
NS_ASSERT (Check ()); |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
261 |
m_tid = tid; |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
262 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
263 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
264 |
void |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
265 |
Object::DoDispose (void) |
713
c3c745a80610
add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
712
diff
changeset
|
266 |
{ |
c3c745a80610
add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
712
diff
changeset
|
267 |
NS_ASSERT (!m_disposed); |
c3c745a80610
add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
712
diff
changeset
|
268 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
269 |
|
1336
de5a133ece8a
add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
732
diff
changeset
|
270 |
|
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
271 |
bool |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
272 |
Object::Check (void) const |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
273 |
{ |
701
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
274 |
return (m_count > 0); |
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
275 |
} |
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
276 |
|
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
277 |
/* In some cases, when an event is scheduled against a subclass of |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
278 |
* Object, and if no one owns a reference directly to this object, the |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
279 |
* object is alive, has a refcount of zero and the method ran when the |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
280 |
* event expires runs against the raw pointer which means that we are |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
281 |
* manipulating an object with a refcount of zero. So, instead we |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
282 |
* check the aggregate reference count. |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
283 |
*/ |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
284 |
bool |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
285 |
Object::CheckLoose (void) const |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
286 |
{ |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
287 |
uint32_t refcount = 0; |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
288 |
uint32_t n = m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
289 |
for (uint32_t i = 0; i < n; i++) |
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
290 |
{ |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
291 |
Object *current = m_aggregates->buffer[i]; |
1534
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
292 |
refcount += current->m_count; |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
293 |
} |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
294 |
return (refcount > 0); |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
295 |
} |
6b7a4e88c422
Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1504
diff
changeset
|
296 |
|
701
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
297 |
void |
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
298 |
Object::MaybeDelete (void) const |
701
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
299 |
{ |
702
829df6703988
yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
701
diff
changeset
|
300 |
// First, check if any of the attached |
829df6703988
yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
701
diff
changeset
|
301 |
// Object has a non-zero count. |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
302 |
uint32_t n = m_aggregates->n; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
303 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
304 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
305 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
306 |
if (current->m_count != 0) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
307 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
308 |
return; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
309 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
310 |
} |
702
829df6703988
yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
701
diff
changeset
|
311 |
|
2529
d5f8bee5fcbd
ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2523
diff
changeset
|
312 |
// Ensure we are disposed. |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
313 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
314 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
315 |
Object *current = m_aggregates->buffer[i]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
316 |
if (!current->m_disposed) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
317 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
318 |
current->DoDispose (); |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
319 |
} |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
320 |
} |
2529
d5f8bee5fcbd
ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2523
diff
changeset
|
321 |
|
702
829df6703988
yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
701
diff
changeset
|
322 |
// all attached objects have a zero count so, |
5479
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
323 |
// we can delete them all. |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
324 |
struct Aggregates *aggregates = m_aggregates; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
325 |
for (uint32_t i = 0; i < n; i++) |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
326 |
{ |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
327 |
// There is a trick here: each time we call delete below, |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
328 |
// the deleted object is removed from the aggregate buffer |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
329 |
// in the destructor so, the index of the next element to |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
330 |
// lookup is always zero |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
331 |
Object *current = aggregates->buffer[0]; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
332 |
delete current; |
b1f7a3a87887
Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5474
diff
changeset
|
333 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
334 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
335 |
} // namespace ns3 |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
336 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
337 |
namespace { |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
338 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
339 |
class BaseA : public ns3::Object |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
340 |
{ |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
341 |
public: |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
342 |
static ns3::TypeId GetTypeId (void) { |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
343 |
static ns3::TypeId tid = ns3::TypeId ("BaseA") |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
344 |
.SetParent (Object::GetTypeId ()) |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2594
diff
changeset
|
345 |
.HideFromDocumentation () |
2237
7745a8c76396
add 'factory' support to InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2235
diff
changeset
|
346 |
.AddConstructor<BaseA> (); |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
347 |
return tid; |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
348 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
349 |
BaseA () |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1781
diff
changeset
|
350 |
{} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
351 |
virtual void Dispose (void) {} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
352 |
}; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
353 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
354 |
class DerivedA : public BaseA |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
355 |
{ |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
356 |
public: |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
357 |
static ns3::TypeId GetTypeId (void) { |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
358 |
static ns3::TypeId tid = ns3::TypeId ("DerivedA") |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
359 |
.SetParent (BaseA::GetTypeId ()) |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2594
diff
changeset
|
360 |
.HideFromDocumentation () |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
361 |
.AddConstructor<DerivedA> (); |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
362 |
return tid; |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
363 |
} |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
364 |
DerivedA () |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1781
diff
changeset
|
365 |
{} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
366 |
virtual void Dispose (void) { |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
367 |
BaseA::Dispose (); |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
368 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
369 |
}; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
370 |
|
706
8b0bf4623c9d
rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
703
diff
changeset
|
371 |
class BaseB : public ns3::Object |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
372 |
{ |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
373 |
public: |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
374 |
static ns3::TypeId GetTypeId (void) { |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
375 |
static ns3::TypeId tid = ns3::TypeId ("BaseB") |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
376 |
.SetParent (Object::GetTypeId ()) |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2594
diff
changeset
|
377 |
.HideFromDocumentation () |
2237
7745a8c76396
add 'factory' support to InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2235
diff
changeset
|
378 |
.AddConstructor<BaseB> (); |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
379 |
return tid; |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
380 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
381 |
BaseB () |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1781
diff
changeset
|
382 |
{} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
383 |
virtual void Dispose (void) {} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
384 |
}; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
385 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
386 |
class DerivedB : public BaseB |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
387 |
{ |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
388 |
public: |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
389 |
static ns3::TypeId GetTypeId (void) { |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
390 |
static ns3::TypeId tid = ns3::TypeId ("DerivedB") |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
391 |
.SetParent (BaseB::GetTypeId ()) |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2594
diff
changeset
|
392 |
.HideFromDocumentation () |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
393 |
.AddConstructor<DerivedB> (); |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
394 |
return tid; |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
395 |
} |
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
396 |
DerivedB () |
2243
9573a034177a
check constructor with reference arguments
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2241
diff
changeset
|
397 |
{} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
398 |
virtual void Dispose (void) { |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
399 |
BaseB::Dispose (); |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
400 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
401 |
}; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
402 |
|
2247
56b3591fa3b0
use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2243
diff
changeset
|
403 |
NS_OBJECT_ENSURE_REGISTERED (BaseA); |
56b3591fa3b0
use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2243
diff
changeset
|
404 |
NS_OBJECT_ENSURE_REGISTERED (DerivedA); |
56b3591fa3b0
use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2243
diff
changeset
|
405 |
NS_OBJECT_ENSURE_REGISTERED (BaseB); |
56b3591fa3b0
use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2243
diff
changeset
|
406 |
NS_OBJECT_ENSURE_REGISTERED (DerivedB); |
56b3591fa3b0
use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2243
diff
changeset
|
407 |
|
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
408 |
} // namespace anonymous |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
409 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
410 |
namespace ns3 { |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
411 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
412 |
// =========================================================================== |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
413 |
// Test case to make sure that we can make Objects using CreateObject. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
414 |
// =========================================================================== |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
415 |
class CreateObjectTestCase : public TestCase |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
416 |
{ |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
417 |
public: |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
418 |
CreateObjectTestCase (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
419 |
virtual ~CreateObjectTestCase (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
420 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
421 |
private: |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
422 |
virtual bool DoRun (void); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
423 |
}; |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
424 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
425 |
CreateObjectTestCase::CreateObjectTestCase () |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
426 |
: TestCase ("Check CreateObject<Type> template function") |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
427 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
428 |
} |
1351
0a6aaa6acbd3
test object-based tracing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1349
diff
changeset
|
429 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
430 |
CreateObjectTestCase::~CreateObjectTestCase () |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
431 |
{ |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
432 |
} |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
433 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
434 |
bool |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
435 |
CreateObjectTestCase::DoRun (void) |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
436 |
{ |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1781
diff
changeset
|
437 |
Ptr<BaseA> baseA = CreateObject<BaseA> (); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
438 |
NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<BaseA>"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
439 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
440 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
441 |
// Since baseA is a BaseA, we must be able to successfully ask for a BaseA. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
442 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
443 |
NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA, "GetObject() of same type returns different Ptr"); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
444 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
445 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
446 |
// Since BaseA is a BaseA and not a DerivedA, we must not find a DerivedA if we look. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
447 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
448 |
NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0, "GetObject() of unrelated type returns nonzero pointer"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
449 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
450 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
451 |
// Since baseA is not a BaseA, we must not be able to ask for a DerivedA even if we |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
452 |
// try an implied cast back to a BaseA. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
453 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
454 |
NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0, "GetObject() of unrelated returns nonzero Ptr"); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
455 |
|
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
456 |
baseA = CreateObject<DerivedA> (); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
457 |
NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<DerivedA> with implicit cast to BaseA"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
458 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
459 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
460 |
// If we create a DerivedA and cast it to a BaseA, then if we do a GetObject for |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
461 |
// that BaseA we should get the same address (same Object). |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
462 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
463 |
NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA, "Unable to GetObject<BaseA> on BaseA"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
464 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
465 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
466 |
// Since we created a DerivedA and cast it to a BaseA, we should be able to |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
467 |
// get back a DerivedA and it should be the original Ptr. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
468 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
469 |
NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), baseA, "GetObject() of the original type returns different Ptr"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
470 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
471 |
// If we created a DerivedA and cast it to a BaseA, then we GetObject for the |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
472 |
// same DerivedA and cast it back to the same BaseA, we should get the same |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
473 |
// object. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
474 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
475 |
NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA, "GetObject returns different Ptr"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
476 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
477 |
return GetErrorStatus (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
478 |
} |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
479 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
480 |
// =========================================================================== |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
481 |
// Test case to make sure that we can aggregate Objects. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
482 |
// =========================================================================== |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
483 |
class AggregateObjectTestCase : public TestCase |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
484 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
485 |
public: |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
486 |
AggregateObjectTestCase (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
487 |
virtual ~AggregateObjectTestCase (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
488 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
489 |
private: |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
490 |
virtual bool DoRun (void); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
491 |
}; |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
492 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
493 |
AggregateObjectTestCase::AggregateObjectTestCase () |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
494 |
: TestCase ("Check Object aggregation functionality") |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
495 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
496 |
} |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
497 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
498 |
AggregateObjectTestCase::~AggregateObjectTestCase () |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
499 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
500 |
} |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
501 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
502 |
bool |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
503 |
AggregateObjectTestCase::DoRun (void) |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
504 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
505 |
Ptr<BaseA> baseA = CreateObject<BaseA> (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
506 |
NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<BaseA>"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
507 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
508 |
Ptr<BaseB> baseB = CreateObject<BaseB> (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
509 |
NS_TEST_ASSERT_MSG_NE (baseB, 0, "Unable to CreateObject<BaseB>"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
510 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
511 |
Ptr<BaseB> baseBCopy = baseB; |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
512 |
NS_TEST_ASSERT_MSG_NE (baseBCopy, 0, "Unable to copy BaseB"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
513 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
514 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
515 |
// Make an aggregation of a BaseA object and a BaseB object. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
516 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
517 |
baseA->AggregateObject (baseB); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
518 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
519 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
520 |
// We should be able to ask the aggregation (through baseA) for the BaseA part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
521 |
// of the aggregation. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
522 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
523 |
NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseA> (), 0, "Cannot GetObject (through baseA) for BaseA Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
524 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
525 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
526 |
// There is no DerivedA in this picture, so we should not be able to GetObject |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
527 |
// for that type. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
528 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
529 |
NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0, "Unexpectedly found a DerivedA through baseA"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
530 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
531 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
532 |
// We should be able to ask the aggregation (through baseA) for the BaseB part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
533 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
534 |
NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0, "Cannot GetObject (through baseA) for BaseB Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
535 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
536 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
537 |
// There is no DerivedB in this picture, so we should not be able to GetObject |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
538 |
// for that type. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
539 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
540 |
NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedB> (), 0, "Unexpectedly found a DerivedB through baseA"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
541 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
542 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
543 |
// We should be able to ask the aggregation (through baseA) for the BaseB part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
544 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
545 |
NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0, "Cannot GetObject (through baseB) for BaseB Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
546 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
547 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
548 |
// There is no DerivedB in this picture, so we should not be able to GetObject |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
549 |
// for that type. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
550 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
551 |
NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedB> (), 0, "Unexpectedly found a DerivedB through baseB"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
552 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
553 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
554 |
// We should be able to ask the aggregation (through baseB) for the BaseA part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
555 |
// of the aggregation. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
556 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
557 |
NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0, "Cannot GetObject (through baseB) for BaseA Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
558 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
559 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
560 |
// There is no DerivedA in this picture, so we should not be able to GetObject |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
561 |
// for that type. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
562 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
563 |
NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedA> (), 0, "Unexpectedly found a DerivedA through baseB"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
564 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
565 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
566 |
// baseBCopy is a copy of the original Ptr to the Object BaseB. Even though |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
567 |
// we didn't use baseBCopy directly in the aggregations, the object to which |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
568 |
// it points was used, therefore, we should be able to use baseBCopy as if |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
569 |
// it were baseB and get a BaseA out of the aggregation. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
570 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
571 |
NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0, "Cannot GetObject (through baseBCopy) for a BaseA Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
572 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
573 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
574 |
// Now, change the underlying type of the objects to be the derived types. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
575 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
576 |
baseA = CreateObject<DerivedA> (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
577 |
NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<DerivedA> with implicit cast to BaseA"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
578 |
|
2372
bf4efb9359c6
attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
579 |
baseB = CreateObject<DerivedB> (); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
580 |
NS_TEST_ASSERT_MSG_NE (baseB, 0, "Unable to CreateObject<DerivedB> with implicit cast to BaseB"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
581 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
582 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
583 |
// Create an aggregation of two objects, both of the derived types; and leave |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
584 |
// an unaggregated copy of one lying around. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
585 |
// |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
586 |
baseBCopy = baseB; |
2258
666099a753e0
AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
587 |
baseA->AggregateObject (baseB); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
588 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
589 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
590 |
// We should be able to ask the aggregation (through baseA) for the DerivedB part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
591 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
592 |
NS_TEST_ASSERT_MSG_NE (baseA->GetObject<DerivedB> (), 0, "Cannot GetObject (through baseA) for DerivedB Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
593 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
594 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
595 |
// Since the DerivedB is also a BaseB, we should be able to ask the aggregation |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
596 |
// (through baseA) for the BaseB part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
597 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
598 |
NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0, "Cannot GetObject (through baseA) for BaseB Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
599 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
600 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
601 |
// We should be able to ask the aggregation (through baseB) for the DerivedA part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
602 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
603 |
NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedA> (), 0, "Cannot GetObject (through baseB) for DerivedA Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
604 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
605 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
606 |
// Since the DerivedA is also a BaseA, we should be able to ask the aggregation |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
607 |
// (through baseB) for the BaseA part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
608 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
609 |
NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0, "Cannot GetObject (through baseB) for BaseA Object"); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
610 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
611 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
612 |
// baseBCopy is a copy of the original Ptr to the Object BaseB. Even though |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
613 |
// we didn't use baseBCopy directly in the aggregations, the object to which |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
614 |
// it points was used, therefore, we should be able to use baseBCopy as if |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
615 |
// it were baseB (same underlying Object) and get a BaseA and a DerivedA out |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
616 |
// of the aggregation through baseBCopy. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
617 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
618 |
NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0, "Cannot GetObject (through baseBCopy) for a BaseA Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
619 |
NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<DerivedA> (), 0, "Cannot GetObject (through baseBCopy) for a BaseA Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
620 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
621 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
622 |
// Since the Ptr<BaseB> is actually a DerivedB, we should be able to ask the |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
623 |
// aggregation (through baseB) for the DerivedB part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
624 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
625 |
NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedB> (), 0, "Cannot GetObject (through baseB) for DerivedB Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
626 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
627 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
628 |
// Since the DerivedB was cast to a BaseB, we should be able to ask the |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
629 |
// aggregation (through baseB) for the BaseB part |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
630 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
631 |
NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0, "Cannot GetObject (through baseB) for BaseB Object"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
632 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
633 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
634 |
// Make sure reference counting works in the aggregate. Create two Objects |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
635 |
// and aggregate them, then release one of them. The aggregation should |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
636 |
// keep a reference to both and the Object we released should still be there. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
637 |
// |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1781
diff
changeset
|
638 |
baseA = CreateObject<BaseA> (); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
639 |
NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<BaseA>"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
640 |
|
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1781
diff
changeset
|
641 |
baseB = CreateObject<BaseB> (); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
642 |
NS_TEST_ASSERT_MSG_NE (baseB, 0, "Unable to CreateObject<BaseA>"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
643 |
|
2258
666099a753e0
AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
644 |
baseA->AggregateObject (baseB); |
701
aa179c876b22
optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
699
diff
changeset
|
645 |
baseA = 0; |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
646 |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
647 |
baseA = baseB->GetObject<BaseA> (); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
648 |
NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to GetObject on released object"); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
649 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
650 |
return GetErrorStatus (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
651 |
} |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
652 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
653 |
// =========================================================================== |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
654 |
// Test case to make sure that an Object factory can create Objects |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
655 |
// =========================================================================== |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
656 |
class ObjectFactoryTestCase : public TestCase |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
657 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
658 |
public: |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
659 |
ObjectFactoryTestCase (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
660 |
virtual ~ObjectFactoryTestCase (); |
1351
0a6aaa6acbd3
test object-based tracing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1349
diff
changeset
|
661 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
662 |
private: |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
663 |
virtual bool DoRun (void); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
664 |
}; |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
665 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
666 |
ObjectFactoryTestCase::ObjectFactoryTestCase () |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
667 |
: TestCase ("Check ObjectFactory functionality") |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
668 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
669 |
} |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
670 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
671 |
ObjectFactoryTestCase::~ObjectFactoryTestCase () |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
672 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
673 |
} |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
674 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
675 |
bool |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
676 |
ObjectFactoryTestCase::DoRun (void) |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
677 |
{ |
2631
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
678 |
ObjectFactory factory; |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
679 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
680 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
681 |
// Create an Object of type BaseA through an object factory. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
682 |
// |
2631
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
683 |
factory.SetTypeId (BaseA::GetTypeId ()); |
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
684 |
Ptr<Object> a = factory.Create (); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
685 |
NS_TEST_ASSERT_MSG_NE (a, 0, "Unable to factory.Create() a BaseA"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
686 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
687 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
688 |
// What we made should be a BaseA, not have anything to do with a DerivedA |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
689 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
690 |
NS_TEST_ASSERT_MSG_EQ (a->GetObject<BaseA> (DerivedA::GetTypeId ()), 0, "BaseA is unexpectedly a DerivedA also"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
691 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
692 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
693 |
// The BaseA we got should not respond to a GetObject for DerivedA |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
694 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
695 |
NS_TEST_ASSERT_MSG_EQ (a->GetObject<DerivedA> (), 0, "BaseA unexpectedly responds to GetObject for DerivedA"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
696 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
697 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
698 |
// Now tell the factory to make DerivedA Objects and create one with an |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
699 |
// implied cast back to a BaseA |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
700 |
// |
2631
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
701 |
factory.SetTypeId (DerivedA::GetTypeId ()); |
365595f1f9a8
replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
702 |
a = factory.Create (); |
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
703 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
704 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
705 |
// Since the DerivedA has a BaseA part, we should be able to use GetObject to |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
706 |
// dynamically cast back to a BaseA. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
707 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
708 |
NS_TEST_ASSERT_MSG_EQ (a->GetObject<BaseA> (), a, "Unable to use GetObject as dynamic_cast<BaseA>()"); |
2237
7745a8c76396
add 'factory' support to InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2235
diff
changeset
|
709 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
710 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
711 |
// Since a is already a BaseA and is really a DerivedA, we should be able to |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
712 |
// GetObject for the DerivedA and cast it back to a BaseA getting the same |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
713 |
// value that is there. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
714 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
715 |
NS_TEST_ASSERT_MSG_EQ (a->GetObject<BaseA> (DerivedA::GetTypeId ()), a, "GetObject with implied cast returns different Ptr"); |
2237
7745a8c76396
add 'factory' support to InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2235
diff
changeset
|
716 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
717 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
718 |
// Since a declared a BaseA, even if it is really a DerivedA, we should not |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
719 |
// be able to GetOBject for a DerivedA since this would break the type |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
720 |
// declaration. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
721 |
// |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
722 |
NS_TEST_ASSERT_MSG_NE (a->GetObject<DerivedA> (), 0, "Unexpectedly able to work around C++ type system"); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
723 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
724 |
return GetErrorStatus (); |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
725 |
} |
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
726 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
727 |
// =========================================================================== |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
728 |
// The Test Suite that glues the Test Cases together. |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
729 |
// =========================================================================== |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
730 |
class ObjectTestSuite : public TestSuite |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
731 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
732 |
public: |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
733 |
ObjectTestSuite (); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
734 |
}; |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
735 |
|
5296
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
736 |
ObjectTestSuite::ObjectTestSuite () |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
737 |
: TestSuite ("object", BVT) |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
738 |
{ |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
739 |
AddTestCase (new CreateObjectTestCase); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
740 |
AddTestCase (new AggregateObjectTestCase); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
741 |
AddTestCase (new ObjectFactoryTestCase); |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
742 |
} |
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
743 |
|
75d258eaccbd
Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4472
diff
changeset
|
744 |
ObjectTestSuite objectTestSuite; |
699
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
745 |
|
956a76f5fd56
a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
746 |
} // namespace ns3 |