Skip to content

Commit bd8a506

Browse files
committed
simplify code
1 parent 6ffebe8 commit bd8a506

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

Kernel/Abstractions/blackbox.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class blackbox_rep {
2424
};
2525

2626
class blackbox : public counted_ptr<blackbox_rep, true> {
27-
using counted_ptr<blackbox_rep, true>::counted_ptr;
27+
using base::counted_ptr;
2828
template <typename T> friend blackbox close_box (const T&);
2929
};
3030

@@ -121,7 +121,7 @@ type_box (blackbox bb) {
121121
template <class T>
122122
blackbox
123123
close_box (const T& data) {
124-
return blackbox (make_derived<whitebox_rep<T>, blackbox_rep> (data));
124+
return blackbox (blackbox::make<whitebox_rep<T>> (data));
125125
}
126126

127127
/**

Kernel/Abstractions/sharedptr.hpp

+12-19
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
#include "fast_alloc.hpp"
55
#include <utility>
66

7-
template <typename T> struct ref_counter_base {
8-
9-
virtual void inc_count ()= 0;
10-
virtual void dec_count ()= 0;
11-
virtual T* get () = 0;
7+
struct ref_counter_base {
8+
virtual void inc_count ()= 0;
9+
virtual void dec_count ()= 0;
10+
virtual void* get () = 0;
1211
};
1312

14-
template <typename T> struct ref_counter : ref_counter_base<T> {
13+
template <typename T> struct ref_counter : ref_counter_base {
1514
/// @brief the reference count of the object
1615
int ref_count;
1716
T content;
@@ -26,24 +25,18 @@ template <typename T> struct ref_counter : ref_counter_base<T> {
2625
tm_delete (this);
2726
}
2827
}
29-
T* get () { return &content; }
28+
void* get () { return &content; }
3029
};
31-
32-
template <typename Stored, typename Regard_As= Stored, typename... Params>
33-
inline ref_counter_base<Regard_As>*
34-
make_derived (Params&&... p) {
35-
return reinterpret_cast<ref_counter_base<Regard_As>*> (
36-
tm_new<ref_counter<Stored>> (std::forward<Params> (p)...));
37-
}
38-
3930
template <typename T, bool nullable= false> class counted_ptr {
4031

4132
protected:
42-
using counter_t= ref_counter_base<T>;
33+
using counter_t= ref_counter_base;
4334
using base = counted_ptr<T, nullable>;
44-
explicit counted_ptr (counter_t* c) : counter (c), rep (c->get ()) {}
45-
template <typename... Params> static counter_t* make (Params&&... p) {
46-
return tm_new<ref_counter<T>> (std::forward<Params> (p)...);
35+
explicit counted_ptr (counter_t* c)
36+
: counter (c), rep (static_cast<T*> (c->get ())) {}
37+
template <typename Stored= T, typename... Params>
38+
static counter_t* make (Params&&... p) {
39+
return tm_new<ref_counter<Stored>> (std::forward<Params> (p)...);
4740
}
4841

4942
private:

0 commit comments

Comments
 (0)