File: RefCountedVehicle.cxx

package info (click to toggle)
mummy 1.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,628 kB
  • ctags: 1,000
  • sloc: cpp: 10,667; cs: 1,107; makefile: 22; xml: 8; sh: 5
file content (149 lines) | stat: -rw-r--r-- 3,264 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "RefCountedVehicle.h"
#include <iostream>

RefCountedVehicle* RefCountedVehicle::Create()
{
  RefCountedVehicle* rcv = new RefCountedVehicle;
  rcv->IncrRefCount(0);
  return rcv;
}

void RefCountedVehicle::Destroy()
{
  this->DecrRefCount(0);
}

void RefCountedVehicle::IncrRefCount(void*)
{
  ++m_RefCount;
}

void RefCountedVehicle::DecrRefCount(void*)
{
  --m_RefCount;
  if (0 == m_RefCount)
  {
    delete this;
  }
}

unsigned int RefCountedVehicle::GetRefCount() const
{
  return m_RefCount;
}

const RefCountedVehicle* RefCountedVehicle::GetThisVehicle() const
{
  ++m_CallCounter;

  // Alternate between returning valid pointers and NULL pointers
  // for complete branch coverage in the export layer... (Call multiple
  // times sequentially from the wrapped side for complete coverage...)
  //
  if (0 != m_CallCounter%2)
    {
    return 0;
    }

  return this;
}

RefCountedVehicle* RefCountedVehicle::GetThatVehicle() const
{
  ++m_CallCounter;

  // Alternate between returning valid pointers and NULL pointers
  // for complete branch coverage in the export layer... (Call multiple
  // times sequentially from the wrapped side for complete coverage...)
  //
  if (0 != m_CallCounter%2)
    {
    return 0;
    }

  return RefCountedVehicle::Create();
}

RefCountedVehicle* RefCountedVehicle::GetTheOtherVehicle() const
{
  ++m_CallCounter;

  // Alternate between returning valid pointers and NULL pointers
  // for complete branch coverage in the export layer... (Call multiple
  // times sequentially from the wrapped side for complete coverage...)
  //
  if (0 != m_CallCounter%2)
    {
    return 0;
    }

  if (0 == m_OtherVehicle)
  {
    m_OtherVehicle = RefCountedVehicle::Create();
  }

  return m_OtherVehicle;
}

//----------------------------------------------------------------------------
// These methods are non-iwhCounted-hint methods that are aliases for the
// iwhCounted-hint method GetThatVehicle... We achieve the same effect
// as having the hint without modifying the C++ header or source by
// adding the method names to the MummySettings.xml countedMethodsRegex
// attribute...
RefCountedVehicle* RefCountedVehicle::GetThatVehicleAlias() const
{
  return this->GetThatVehicle();
}

RefCountedVehicle* RefCountedVehicle::GetThatVehicleByAnyOtherName() const
{
  return this->GetThatVehicle();
}

//----------------------------------------------------------------------------
//RefCountedVehicle* RefCountedVehicle::GetNoHint() const
//{
//  return 0;
//}

//void RefCountedVehicle::SetThis()
//{
//}

int RefCountedVehicle::NumberOfConstructorCalls = 0;
int RefCountedVehicle::NumberOfDestructorCalls = 0;

RefCountedVehicle::RefCountedVehicle()
{
  ++NumberOfConstructorCalls;

  m_RefCount = 0;
  m_OtherVehicle = 0;
  m_CallCounter = 0;
}

RefCountedVehicle::~RefCountedVehicle()
{
  ++NumberOfDestructorCalls;

  if (m_OtherVehicle)
  {
    m_OtherVehicle->Destroy();
  }
}

void RefCountedVehicle::Check()
{
  if (NumberOfConstructorCalls != NumberOfDestructorCalls)
    {
    std::cerr << "error: RefCountedVehicle::Check ctor/dtor mismatch - mem leak?" << std::endl;
    }
}

// Intentional no-op.
// Exists only to test BTX/ETX style exclusion.
//
void RefCountedVehicle::MethodExcludedByBTXETX()
{
}