main page
modules
namespaces
classes
files
Gecode home
Generated on Fri Jan 10 2020 11:38:25 for Gecode by
doxygen
1.8.16
gecode
kernel
shared-object.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2017
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
namespace
Gecode
{
35
46
class
SharedHandle
{
47
public
:
53
class
GECODE_KERNEL_EXPORT
Object
:
public
HeapAllocated
{
54
friend
class
SharedHandle
;
55
private
:
57
Support::RefCount
rc
;
58
public
:
60
Object
(
void
);
62
virtual
~
Object
(
void
);
63
};
64
private
:
66
Object
* o;
68
void
subscribe
(
void
);
70
void
cancel
(
void
);
71
public
:
73
SharedHandle
(
void
);
75
SharedHandle
(
SharedHandle::Object
* so);
77
SharedHandle
(
const
SharedHandle
& sh);
79
SharedHandle
&
operator =
(
const
SharedHandle
& sh);
81
~SharedHandle
(
void
);
83
explicit
operator
bool(
void
)
const
;
84
protected
:
86
SharedHandle::Object
*
object
(
void
)
const
;
88
void
object
(
SharedHandle::Object
*
n
);
89
};
90
91
92
forceinline
93
SharedHandle::Object::Object
(
void
)
94
:
rc
(0) {}
95
forceinline
96
SharedHandle::Object::~Object
(
void
) {
97
assert(!
rc
);
98
}
99
100
101
forceinline
SharedHandle::Object
*
102
SharedHandle::object
(
void
)
const
{
103
return
o;
104
}
105
forceinline
void
106
SharedHandle::subscribe
(
void
) {
107
if
(o !=
nullptr
) o->rc.
inc
();
108
}
109
forceinline
void
110
SharedHandle::cancel
(
void
) {
111
if
((o !=
nullptr
) && o->rc.
dec
())
112
delete
o;
113
o=
nullptr
;
114
}
115
forceinline
void
116
SharedHandle::object
(
SharedHandle::Object
*
n
) {
117
if
(
n
!= o) {
118
cancel
(); o=
n
;
subscribe
();
119
}
120
}
121
forceinline
122
SharedHandle::SharedHandle
(
void
) : o(nullptr) {}
123
forceinline
124
SharedHandle::SharedHandle
(
SharedHandle::Object
* so) : o(so) {
125
subscribe
();
126
}
127
forceinline
128
SharedHandle::SharedHandle
(
const
SharedHandle
& sh) : o(sh.o) {
129
subscribe
();
130
}
131
forceinline
SharedHandle
&
132
SharedHandle::operator =
(
const
SharedHandle
& sh) {
133
if
(&sh !=
this
) {
134
cancel
(); o=sh.o;
subscribe
();
135
}
136
return
*
this
;
137
}
138
forceinline
139
SharedHandle::operator bool(
void
)
const
{
140
return
o !=
nullptr
;
141
}
142
forceinline
143
SharedHandle::~SharedHandle
(
void
) {
144
cancel
();
145
}
146
147
}
148
149
// STATISTICS: kernel-memory
Gecode::SharedHandle::Object::Object
Object(void)
Initialize.
Definition:
shared-object.hpp:93
Gecode::SharedHandle::object
SharedHandle::Object * object(void) const
Access to the shared object.
Definition:
shared-object.hpp:102
Gecode::SharedHandle::Object
The shared object.
Definition:
shared-object.hpp:53
Test::Int::Extensional::rc
RegSimpleC rc
Definition:
extensional.cpp:799
Gecode
Gecode toplevel namespace
Gecode::Support::RefCount::dec
bool dec(void)
Decrement counter and return true if it hits zero.
Definition:
ref-count.hpp:63
Gecode::Support::RefCount
A class for thread-safe reference counting.
Definition:
ref-count.hpp:39
GECODE_KERNEL_EXPORT
#define GECODE_KERNEL_EXPORT
Definition:
kernel.hh:70
Gecode::HeapAllocated
Base class for heap allocated objects.
Definition:
heap.hpp:340
Gecode::Support::RefCount::inc
void inc(void)
Increment counter.
Definition:
ref-count.hpp:59
Gecode::Int::Count::cancel
void cancel(Space &home, Propagator &p, IntSet &y)
Definition:
rel.hpp:81
Gecode::SharedHandle::~SharedHandle
~SharedHandle(void)
Destructor that maintains reference count.
Definition:
shared-object.hpp:143
Gecode::SharedHandle::Object::~Object
virtual ~Object(void)
Delete shared object.
Definition:
shared-object.hpp:96
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::SharedHandle::operator=
SharedHandle & operator=(const SharedHandle &sh)
Assignment operator maintaining reference count.
Definition:
shared-object.hpp:132
Gecode::SharedHandle
The shared handle.
Definition:
shared-object.hpp:46
Gecode::Int::Count::subscribe
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition:
rel.hpp:71
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::SharedHandle::SharedHandle
SharedHandle(void)
Create shared handle with no object pointing to.
Definition:
shared-object.hpp:122