Eclipse SUMO - Simulation of Urban MObility
GNEReferenceCounter.h
Go to the documentation of this file.
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3
// Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials
5
// are made available under the terms of the Eclipse Public License v2.0
6
// which accompanies this distribution, and is available at
7
// http://www.eclipse.org/legal/epl-v20.html
8
// SPDX-License-Identifier: EPL-2.0
9
/****************************************************************************/
15
// A class that counts references to itself
16
// We may wish to keep references to junctions/nodes either in the network or in the undoList
17
// to clean up properly we have to resort to reference counting
18
/****************************************************************************/
19
#ifndef GNEReferenceCounter_h
20
#define GNEReferenceCounter_h
21
22
23
// ===========================================================================
24
// included modules
25
// ===========================================================================
26
#include <
config.h
>
27
28
#include <
utils/common/MsgHandler.h
>
29
#include <
utils/common/StdDefs.h
>
30
31
32
// ===========================================================================
33
// class definitions
34
// ===========================================================================
38
class
GNEReferenceCounter
{
39
public
:
41
GNEReferenceCounter
():
myCount
(0) {}
42
44
~GNEReferenceCounter
() {
45
// If myCount is different of 0, means that references weren't removed correctly
46
if
(
myCount
!= 0) {
47
// cannot print id here, it already got destructed
48
WRITE_ERROR
(
"Attempt to delete instance of GNEReferenceCounter with count "
+
toString
(
myCount
));
49
}
50
}
51
53
void
decRef
(
const
std::string& debugMsg =
""
) {
54
// debugMsg only used for print debugging
55
#ifdef _DEBUG_REFERENCECOUNTER
56
std::cout <<
"decRef ("
+
toString
(
myCount
) +
") for "
+
getID
() +
": "
<< debugMsg <<
"\n"
;
57
#else
58
UNUSED_PARAMETER
(debugMsg);
59
#endif
60
// write error if decrement results into a negative count
61
if
(
myCount
< 1) {
62
WRITE_ERROR
(
"Attempt to decrement references below zero for instance of GNEReferenceCounter"
);
63
}
64
myCount
--;
65
}
66
68
void
incRef
(
const
std::string& debugMsg =
""
) {
69
// debugMsg only used for print debugging
70
#ifdef _DEBUG_REFERENCECOUNTER
71
std::cout <<
"incRef ("
+
toString
(
myCount
) +
") for "
+
getID
() +
": "
<< debugMsg <<
"\n"
;
72
#else
73
UNUSED_PARAMETER
(debugMsg);
74
#endif
75
myCount
++;
76
}
77
79
bool
unreferenced
() {
80
return
myCount
== 0;
81
}
82
84
virtual
const
std::string
getID
()
const
= 0;
85
86
87
private
:
89
int
myCount
;
90
91
};
92
93
94
#endif
95
96
/****************************************************************************/
97
UNUSED_PARAMETER
#define UNUSED_PARAMETER(x)
Definition:
StdDefs.h:32
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition:
GNEReferenceCounter.h:79
MsgHandler.h
GNEReferenceCounter::getID
virtual const std::string getID() const =0
return ID of object
GNEReferenceCounter::myCount
int myCount
reference counter
Definition:
GNEReferenceCounter.h:89
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition:
GNEReferenceCounter.h:53
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition:
ToString.h:48
GNEReferenceCounter::GNEReferenceCounter
GNEReferenceCounter()
Definition:
GNEReferenceCounter.h:41
GNEReferenceCounter::incRef
void incRef(const std::string &debugMsg="")
Increarse reference.
Definition:
GNEReferenceCounter.h:68
GNEReferenceCounter
Definition:
GNEReferenceCounter.h:38
config.h
StdDefs.h
GNEReferenceCounter::~GNEReferenceCounter
~GNEReferenceCounter()
Definition:
GNEReferenceCounter.h:44
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition:
MsgHandler.h:245
src
netedit
GNEReferenceCounter.h
Generated on Wed Jan 15 2020 15:04:13 for Eclipse SUMO - Simulation of Urban MObility by
1.8.16