Skip to content

Commit 922adf0

Browse files
committed
Small shared n-way pointer
This replaces small_shared_two_way_ptrt with small_shared_n_way_ptrt. The new shared pointer type allows more than two types for the managed objects. This can be useful e.g. for implementing graph data structures with sharing where there are more than two different node types.
1 parent 80c47c9 commit 922adf0

File tree

6 files changed

+603
-424
lines changed

6 files changed

+603
-424
lines changed

src/util/sharing_node.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Author: Daniel Poetzl
3535

3636
#include "invariant.h"
3737
#include "make_unique.h"
38+
#include "small_shared_n_way_ptr.h"
3839
#include "small_shared_ptr.h"
39-
#include "small_shared_two_way_ptr.h"
4040

4141
#ifdef SN_INTERNAL_CHECKS
4242
#define SN_ASSERT(b) INVARIANT(b, "Sharing node internal invariant")
@@ -70,7 +70,7 @@ const T *as_const(T *t)
7070

7171
// Inner nodes (internal nodes or container nodes)
7272

73-
typedef small_shared_two_way_pointeet<unsigned> d_baset;
73+
typedef small_shared_n_way_pointee_baset<2, unsigned> d_baset;
7474

7575
SN_TYPE_PAR_DECL class sharing_node_innert;
7676

@@ -105,7 +105,7 @@ class sharing_node_baset
105105
SN_TYPE_PAR_DEF class sharing_node_innert : public sharing_node_baset
106106
{
107107
public:
108-
typedef small_shared_two_way_ptrt<SN_PTR_TYPE_ARGS> datat;
108+
typedef small_shared_n_way_ptrt<SN_PTR_TYPE_ARGS> datat;
109109
typedef typename datat::use_countt use_countt;
110110

111111
typedef d_internalt<SN_TYPE_ARGS> d_it;
@@ -155,12 +155,12 @@ SN_TYPE_PAR_DEF class sharing_node_innert : public sharing_node_baset
155155

156156
bool is_internal() const
157157
{
158-
return data.is_derived_u();
158+
return data.template is_derived<0>();
159159
}
160160

161161
bool is_container() const
162162
{
163-
return data.is_derived_v();
163+
return data.template is_derived<1>();
164164
}
165165

166166
bool is_defined_internal() const
@@ -177,14 +177,14 @@ SN_TYPE_PAR_DEF class sharing_node_innert : public sharing_node_baset
177177
{
178178
SN_ASSERT(!empty());
179179

180-
return *data.get_derived_u();
180+
return *data.template get_derived<0>();
181181
}
182182

183183
const d_ct &read_container() const
184184
{
185185
SN_ASSERT(!empty());
186186

187-
return *data.get_derived_v();
187+
return *data.template get_derived<1>();
188188
}
189189

190190
// Accessors
@@ -334,32 +334,34 @@ SN_TYPE_PAR_DEF class sharing_node_innert : public sharing_node_baset
334334
{
335335
if(!data)
336336
{
337-
data = make_shared_derived_u<SN_PTR_TYPE_ARGS>();
337+
data = make_shared_2<0, SN_PTR_TYPE_ARGS>();
338338
}
339339
else if(data.use_count() > 1)
340340
{
341-
data = make_shared_derived_u<SN_PTR_TYPE_ARGS>(*data.get_derived_u());
341+
data =
342+
make_shared_2<0, SN_PTR_TYPE_ARGS>(*data.template get_derived<0>());
342343
}
343344

344345
SN_ASSERT(data.use_count() == 1);
345346

346-
return *data.get_derived_u();
347+
return *data.template get_derived<0>();
347348
}
348349

349350
d_ct &write_container()
350351
{
351352
if(!data)
352353
{
353-
data = make_shared_derived_v<SN_PTR_TYPE_ARGS>();
354+
data = make_shared_2<1, SN_PTR_TYPE_ARGS>();
354355
}
355356
else if(data.use_count() > 1)
356357
{
357-
data = make_shared_derived_v<SN_PTR_TYPE_ARGS>(*data.get_derived_v());
358+
data =
359+
make_shared_2<1, SN_PTR_TYPE_ARGS>(*data.template get_derived<1>());
358360
}
359361

360362
SN_ASSERT(data.use_count() == 1);
361363

362-
return *data.get_derived_v();
364+
return *data.template get_derived<1>();
363365
}
364366

365367
datat data;

0 commit comments

Comments
 (0)