1
/***************************************************************************
2
* (c) J�rgen Riegel (juergen.riegel@web.de) 2002 *
4
* This file is part of the FreeCAD CAx development system. *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU Library General Public License (LGPL) *
8
* as published by the Free Software Foundation; either version 2 of *
9
* the License, or (at your option) any later version. *
10
* for detail see the LICENCE text file. *
12
* FreeCAD is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU Library General Public License for more details. *
17
* You should have received a copy of the GNU Library General Public *
18
* License along with FreeCAD; if not, write to the Free Software *
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22
* Juergen Riegel 2002 *
23
***************************************************************************/
29
// Std. configurations
40
* Implementation of the reference counting pattern.
41
* Only able to instantiate with a class inheriting
48
//**************************************************************************
49
// construction & destruction
51
/** Pointer and default constructor */
52
Reference() : _toHandle(0) {
55
Reference(T* p) : _toHandle(p) {
60
/** Copy constructor */
61
Reference(const Reference<T>& p) : _toHandle(p._toHandle) {
67
* Release the reference counter which causes,
68
* in case of the last one, the referenced object to
76
//**************************************************************************
77
// operator implementation
79
/** Assign operator from a pointer */
80
Reference <T>& operator=(T* p) {
81
// check if we want to reassign the same object
92
/** Assign operator from a handle */
93
Reference <T>& operator=(const Reference<T>& p) {
94
// check if we want to reassign the same object
95
if (_toHandle == p._toHandle)
99
_toHandle = p._toHandle;
105
/** Dereference operator */
106
T& operator*() const {
110
/** Dereference operator */
111
T* operator->() const {
115
operator T*() const {
119
/** Lower operator, needed for sorting in maps and sets */
120
bool operator<(const Reference<T>& p) const {
121
return _toHandle < p._toHandle;
124
/** Equal operator */
125
bool operator==(const Reference<T>& p) const {
126
return _toHandle == p._toHandle;
129
bool operator!=(const Reference<T>& p) const {
130
return _toHandle != p._toHandle;
134
//**************************************************************************
135
// checking on the state
137
/// Test if it handles something
138
bool isValid(void) const {
139
return _toHandle != 0;
142
/// Test if it does not handle anything
143
bool isNull(void) const {
144
return _toHandle == 0;
147
/// Get number of references on the object, including this one
148
long getRefCount(void) const {
150
return _toHandle->getRefCount();
155
T *_toHandle; /** the pointer to the handled object */
160
* Implementation of the reference counting pattern.
162
class BaseExport Handled
171
long getRefCount(void) const {
174
const Handled& operator = (const Handled&);
182
#endif // BASE_HANDLE_H