src/core/object.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 17 Apr 2008 15:50:49 -0700
changeset 2972 d76553495b91
parent 2938 621b23d5be5b
parent 2902 9c2cfada5e72
child 3033 5daf048843a6
permissions -rw-r--r--
merge with HEAD
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
 */
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    21
#include "object.h"
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "assert.h"
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "singleton.h"
2438
e2ac9f9aeeb9 value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    24
#include "attribute.h"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1420
diff changeset
    25
#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
    26
#include "string.h"
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include <vector>
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    28
#include <sstream>
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1420
diff changeset
    30
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
    31
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
namespace ns3 {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
2233
b359c83c5fbe add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2232
diff changeset
    34
/*********************************************************************
b359c83c5fbe add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2232
diff changeset
    35
 *         The Object implementation
b359c83c5fbe add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2232
diff changeset
    36
 *********************************************************************/
b359c83c5fbe add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2232
diff changeset
    37
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
    38
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
    39
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    40
Object::AggregateIterator::AggregateIterator ()
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    41
  : m_first (0),
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    42
    m_current (0)
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    43
{}
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    44
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    45
bool 
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    46
Object::AggregateIterator::HasNext (void) const
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
  if (m_current != 0 && m_current->m_next != PeekPointer (m_first))
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    49
    {
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    50
      return true;
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    51
    }
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    52
  return false;
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
{
2938
621b23d5be5b iterate over the _aggregated_ objects: this does not include the initial pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2937
diff changeset
    57
  m_current = m_current->m_next;
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    58
  return m_current;
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    59
}
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    60
Object::AggregateIterator::AggregateIterator (Ptr<const Object> first)
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    61
  : m_first (first),
2938
621b23d5be5b iterate over the _aggregated_ objects: this does not include the initial pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2937
diff changeset
    62
    m_current (first)
2937
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
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    65
2250
18f432098389 InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2247
diff changeset
    66
TypeId 
2634
44a92f1d3728 introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2633
diff changeset
    67
Object::GetInstanceTypeId (void) const
44a92f1d3728 introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2633
diff changeset
    68
{
2636
fe664ae9aa8b return the _current_ tid, not the Object tid.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2635
diff changeset
    69
  return m_tid;
2634
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
44a92f1d3728 introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2633
diff changeset
    72
TypeId 
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    73
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
    74
{
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2636
diff changeset
    75
  static TypeId tid = TypeId ("ns3::Object")
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2636
diff changeset
    76
    .SetParent<ObjectBase> ()
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2636
diff changeset
    77
    ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    78
  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
    79
}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    82
Object::Object ()
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
  : m_count (1),
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    84
    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
    85
    m_disposed (false),
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
    86
    m_next (this)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
{}
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    88
Object::~Object () 
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    89
{
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    90
  m_next = 0;
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    91
}
2667
2324032b8f90 Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2637
diff changeset
    92
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
    93
  : m_count (1),
2324032b8f90 Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2637
diff changeset
    94
    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
    95
    m_disposed (false),
2324032b8f90 Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2637
diff changeset
    96
    m_next (this)
2324032b8f90 Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2637
diff changeset
    97
{}
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    98
void
2459
91662d921a83 Attributes -> AttributeList
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2458
diff changeset
    99
Object::Construct (const AttributeList &attributes)
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   100
{
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2636
diff changeset
   101
  ConstructSelf (attributes);
2569
d5cff2968984 make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
   102
}
2463
c77e43117673 actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2460
diff changeset
   103
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   104
Ptr<Object>
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   105
Object::DoGetObject (TypeId tid) const
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
{
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
   107
  NS_ASSERT (CheckLoose ());
709
b5c7825babf3 make QueryInterface const
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 708
diff changeset
   108
  const Object *currentObject = this;
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   109
  do {
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   110
    NS_ASSERT (currentObject != 0);
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   111
    TypeId cur = currentObject->m_tid;
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   112
    while (cur != tid && cur != Object::GetTypeId ())
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   113
      {
2235
fb93067a3c2e rewrite interface id metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2234
diff changeset
   114
        cur = cur.GetParent ();
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   115
      }
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   116
    if (cur == tid)
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   117
      {
709
b5c7825babf3 make QueryInterface const
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 708
diff changeset
   118
        return const_cast<Object *> (currentObject);
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   119
      }
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   120
    currentObject = currentObject->m_next;
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   121
  } while (currentObject != this);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
  return 0;
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
void 
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   125
Object::Dispose (void)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
{
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   127
  Object *current = this;
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   128
  do {
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   129
    NS_ASSERT (current != 0);
713
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   130
    NS_ASSERT (!current->m_disposed);
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   131
    current->DoDispose ();
713
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   132
    current->m_disposed = true;
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   133
    current = current->m_next;
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   134
  } while (current != this);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
void 
2258
666099a753e0 AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   137
Object::AggregateObject (Ptr<Object> o)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
{
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   139
  NS_ASSERT (!m_disposed);
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   140
  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
   141
  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
   142
  NS_ASSERT (o->CheckLoose ());
2902
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   143
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   144
  if (DoGetObject (o->m_tid))
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   145
    {
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   146
      NS_FATAL_ERROR ("Object::AggregateObject(): "
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   147
       "Multiple aggregation of objects of type " << o->m_tid.GetName ());
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   148
    }
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   149
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   150
  Object *other = PeekPointer (o);
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   151
  Object *next = m_next;
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   152
  m_next = other->m_next;
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   153
  other->m_next = next;
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
   154
  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
   155
  NS_ASSERT (o->CheckLoose ());
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   158
Object::AggregateIterator 
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   159
Object::GetAggregateIterator (void) const
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   160
{
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   161
  return AggregateIterator (this);
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   162
}
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   163
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
void 
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   165
Object::SetTypeId (TypeId tid)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
  NS_ASSERT (Check ());
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   168
  m_tid = tid;
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
void
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   172
Object::DoDispose (void)
713
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   173
{
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   174
  NS_ASSERT (!m_disposed);
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   175
}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
1336
de5a133ece8a add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 732
diff changeset
   177
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
bool 
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   179
Object::Check (void) const
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
{
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   181
  return (m_count > 0);
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   182
}
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   183
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
   184
/* 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
   185
 * 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
   186
 * 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
   187
 * 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
   188
 * 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
   189
 * 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
   190
 */
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
   191
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
   192
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
   193
{
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
   194
  uint32_t 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
   195
  const Object *current = this;
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
   196
  do
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
    {
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
      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
   199
      current = current->m_next;
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
   200
    }
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
   201
  while (current != this);
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
   202
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
   203
  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
   204
}
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
   205
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   206
void
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   207
Object::MaybeDelete (void) const
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   208
{
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   209
  // 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
   210
  // Object has a non-zero count.
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   211
  const Object *current = this;
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   212
  do {
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   213
    NS_ASSERT (current != 0);
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   214
    if (current->m_count != 0)
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   215
      {
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   216
        return;
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   217
      }
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   218
    current = current->m_next;
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   219
  } while (current != this);
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   220
2529
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   221
  // Ensure we are disposed.
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   222
  Object *tmp = const_cast<Object *> (this);
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   223
  const Object *end = this;
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   224
  do {
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   225
    NS_ASSERT (current != 0);
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   226
    Object *next = tmp->m_next;
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   227
    if (!tmp->m_disposed)
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   228
      {
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   229
        tmp->DoDispose ();
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   230
      }
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   231
    tmp = next;
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   232
  } while (tmp != end);
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   233
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   234
  // all attached objects have a zero count so, 
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   235
  // we can delete all attached objects.
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   236
  current = this;
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   237
  do {
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   238
    NS_ASSERT (current != 0);
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   239
    Object *next = current->m_next;
702
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   240
    delete current;
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   241
    current = next;
829df6703988 yet another optimization to cut even more on memory allocations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 701
diff changeset
   242
  } while (current != end);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   244
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   245
} // namespace ns3
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   246
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   247
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
#ifdef RUN_SELF_TESTS
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
#include "test.h"
2631
365595f1f9a8 replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   251
#include "object-factory.h"
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
namespace {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   255
class BaseA : public ns3::Object
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
public:
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   258
  static ns3::TypeId GetTypeId (void) {
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   259
    static ns3::TypeId tid = ns3::TypeId ("BaseA")
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   260
      .SetParent (Object::GetTypeId ())
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2594
diff changeset
   261
      .HideFromDocumentation ()
2237
7745a8c76396 add 'factory' support to InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2235
diff changeset
   262
      .AddConstructor<BaseA> ();
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   263
    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
   264
  }
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
  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
   266
  {}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
  virtual void Dispose (void) {}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
};
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
class DerivedA : public BaseA
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
public:
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   273
  static ns3::TypeId GetTypeId (void) {
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   274
    static ns3::TypeId tid = ns3::TypeId ("DerivedA")
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   275
      .SetParent (BaseA::GetTypeId ())
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2594
diff changeset
   276
      .HideFromDocumentation ()
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   277
      .AddConstructor<DerivedA> ();
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   278
    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
   279
  }
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   280
  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
   281
  {}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   282
  virtual void Dispose (void) {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   283
    BaseA::Dispose ();
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   284
  }
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
};
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   287
class BaseB : public ns3::Object
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
public:
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   290
  static ns3::TypeId GetTypeId (void) {
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   291
    static ns3::TypeId tid = ns3::TypeId ("BaseB")
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   292
      .SetParent (Object::GetTypeId ())
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2594
diff changeset
   293
      .HideFromDocumentation ()
2237
7745a8c76396 add 'factory' support to InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2235
diff changeset
   294
      .AddConstructor<BaseB> ();
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   295
    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
   296
  }
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   297
  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
   298
  {}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   299
  virtual void Dispose (void) {}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
};
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
class DerivedB : public BaseB
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   304
public:
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   305
  static ns3::TypeId GetTypeId (void) {
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   306
    static ns3::TypeId tid = ns3::TypeId ("DerivedB")
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   307
      .SetParent (BaseB::GetTypeId ())
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2594
diff changeset
   308
      .HideFromDocumentation ()
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   309
      .AddConstructor<DerivedB> ();
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   310
    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
   311
  }
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   312
  DerivedB ()
2243
9573a034177a check constructor with reference arguments
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2241
diff changeset
   313
  {}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
  virtual void Dispose (void) {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
    BaseB::Dispose ();
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
  }
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   317
};
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
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
   319
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
   320
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
   321
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
   322
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
   323
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   324
} // namespace anonymous
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   325
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
namespace ns3 {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   327
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   328
class ObjectTest : public Test
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   330
public:
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   331
  ObjectTest ();
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   332
  virtual bool RunTests (void);
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   333
};
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   335
ObjectTest::ObjectTest ()
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   336
  : Test ("Object")
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
{}
1351
0a6aaa6acbd3 test object-based tracing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1349
diff changeset
   338
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   339
bool 
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   340
ObjectTest::RunTests (void)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   341
{
1349
11562f6b73aa rewrite Object tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1346
diff changeset
   342
  bool result = true;
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   343
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
   344
  Ptr<BaseA> baseA = CreateObject<BaseA> ();
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   345
  NS_TEST_ASSERT_EQUAL (baseA->GetObject<BaseA> (), baseA);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   346
  NS_TEST_ASSERT_EQUAL (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   347
  NS_TEST_ASSERT_EQUAL (baseA->GetObject<DerivedA> (), 0);
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   348
  baseA = CreateObject<DerivedA> ();
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   349
  NS_TEST_ASSERT_EQUAL (baseA->GetObject<BaseA> (), baseA);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   350
  NS_TEST_ASSERT_EQUAL (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   351
  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<DerivedA> (), 0);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   352
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
   353
  baseA = CreateObject<BaseA> ();
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1781
diff changeset
   354
  Ptr<BaseB> baseB = CreateObject<BaseB> ();
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   355
  Ptr<BaseB> baseBCopy = baseB;
2258
666099a753e0 AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   356
  baseA->AggregateObject (baseB);
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   357
  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<BaseA> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   358
  NS_TEST_ASSERT_EQUAL (baseA->GetObject<DerivedA> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   359
  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<BaseB> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   360
  NS_TEST_ASSERT_EQUAL (baseA->GetObject<DerivedB> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   361
  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<BaseB> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   362
  NS_TEST_ASSERT_EQUAL (baseB->GetObject<DerivedB> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   363
  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<BaseA> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   364
  NS_TEST_ASSERT_EQUAL (baseB->GetObject<DerivedA> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   365
  NS_TEST_ASSERT_UNEQUAL (baseBCopy->GetObject<BaseA> (), 0);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   366
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   367
  baseA = CreateObject<DerivedA> ();
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   368
  baseB = CreateObject<DerivedB> ();
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   369
  baseBCopy = baseB;
2258
666099a753e0 AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   370
  baseA->AggregateObject (baseB);
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   371
  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<DerivedB> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   372
  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<BaseB> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   373
  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<DerivedA> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   374
  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<BaseA> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   375
  NS_TEST_ASSERT_UNEQUAL (baseBCopy->GetObject<DerivedA> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   376
  NS_TEST_ASSERT_UNEQUAL (baseBCopy->GetObject<BaseA> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   377
  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<DerivedB> (), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   378
  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<BaseB> (), 0)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   379
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
   380
  baseA = CreateObject<BaseA> ();
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1781
diff changeset
   381
  baseB = CreateObject<BaseB> ();
2258
666099a753e0 AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   382
  baseA->AggregateObject (baseB);
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   383
  baseA = 0;
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   384
  baseA = baseB->GetObject<BaseA> ();
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   385
1351
0a6aaa6acbd3 test object-based tracing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1349
diff changeset
   386
2250
18f432098389 InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2247
diff changeset
   387
  // Test the object creation code of TypeId
2631
365595f1f9a8 replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   388
  ObjectFactory factory;
365595f1f9a8 replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   389
  factory.SetTypeId (BaseA::GetTypeId ());
365595f1f9a8 replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   390
  Ptr<Object> a = factory.Create ();
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   391
  NS_TEST_ASSERT_EQUAL (a->GetObject<BaseA> (), a);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   392
  NS_TEST_ASSERT_EQUAL (a->GetObject<BaseA> (DerivedA::GetTypeId ()), 0);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   393
  NS_TEST_ASSERT_EQUAL (a->GetObject<DerivedA> (), 0);
2631
365595f1f9a8 replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   394
  factory.SetTypeId (DerivedA::GetTypeId ());
365595f1f9a8 replace TypeId::CreateObject with TypeId::GetConstructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   395
  a = factory.Create ();
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   396
  NS_TEST_ASSERT_EQUAL (a->GetObject<BaseA> (), a);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   397
  NS_TEST_ASSERT_EQUAL (a->GetObject<BaseA> (DerivedA::GetTypeId ()), a);
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   398
  NS_TEST_ASSERT_UNEQUAL (a->GetObject<DerivedA> (), 0);
2237
7745a8c76396 add 'factory' support to InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2235
diff changeset
   399
7745a8c76396 add 'factory' support to InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2235
diff changeset
   400
1349
11562f6b73aa rewrite Object tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1346
diff changeset
   401
  return result;
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   402
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   403
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   404
static ObjectTest g_interfaceObjectTests;
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   405
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   406
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   407
} // namespace ns3
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   408
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   409
#endif /* RUN_SELF_TESTS */
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   410
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   411