Jpp
15.0.5
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
software
JLang
JSharedCounter.hh
Go to the documentation of this file.
1
#ifndef __JLANG__JSHAREDCOUNTER__
2
#define __JLANG__JSHAREDCOUNTER__
3
4
#include <cstdlib>
5
6
/**
7
* \author mdejong
8
*/
9
10
namespace
JLANG {}
11
namespace
JPP {
using namespace
JLANG; }
12
13
namespace
JLANG {
14
15
16
/**
17
* Shared counter.
18
*/
19
class
JSharedCounter
20
{
21
public
:
22
/**
23
* Default constructor.
24
*/
25
JSharedCounter
() :
26
counter
(NULL)
27
{}
28
29
30
/**
31
* Initialise counter.
32
*/
33
void
initialise
()
34
{
35
detach
();
36
37
counter
=
new
int(1);
38
}
39
40
41
/**
42
* Attach this counter to given shared counter object.
43
*
44
* \param object shared counter
45
*/
46
void
attach
(
const
JSharedCounter
&
object
)
47
{
48
detach
();
49
50
counter
=
object
.counter;
51
52
if
(
counter
!= NULL) {
53
++(*counter);
54
}
55
}
56
57
58
/**
59
* Detach.
60
*
61
* \return true if counter at zero; else false
62
*/
63
bool
detach
()
64
{
65
if
(
counter
!= NULL) {
66
67
if
(--(*
counter
) == 0) {
68
69
delete
counter
;
70
71
counter
= NULL;
72
73
return
true
;
74
}
75
76
counter
= NULL;
77
}
78
79
return
false
;
80
}
81
82
83
/**
84
* Get count
85
*
86
* \return count
87
*/
88
const
int
getCount
()
89
{
90
return
(
counter
!= NULL ? *
counter
: 0);
91
}
92
93
protected
:
94
int
*
counter
;
95
};
96
}
97
98
#endif
JLANG::JSharedCounter
Shared counter.
Definition:
JSharedCounter.hh:19
JLANG::JSharedCounter::counter
int * counter
Definition:
JSharedCounter.hh:94
JLANG::JSharedCounter::attach
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
Definition:
JSharedCounter.hh:46
JLANG::JSharedCounter::JSharedCounter
JSharedCounter()
Default constructor.
Definition:
JSharedCounter.hh:25
JLANG::JSharedCounter::initialise
void initialise()
Initialise counter.
Definition:
JSharedCounter.hh:33
JLANG::JSharedCounter::detach
bool detach()
Detach.
Definition:
JSharedCounter.hh:63
JLANG::JSharedCounter::getCount
const int getCount()
Get count.
Definition:
JSharedCounter.hh:88
Generated by
1.8.5