File tree Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ namespace jni
30
30
private:
31
31
UntaggedType* array = nullptr ;
32
32
33
+ template < class T , class D > friend class UniquePointerlike ;
34
+
35
+ void reset (UntaggedType* a) { array = a; }
36
+
33
37
public:
34
38
explicit Array (std::nullptr_t = nullptr )
35
39
{}
@@ -42,6 +46,13 @@ namespace jni
42
46
: array(&a)
43
47
{}
44
48
49
+ Array (const Array& a)
50
+ : array(a.array)
51
+ {}
52
+
53
+ // Not reassignable; it would break UniquePointerlike's abstraction.
54
+ Array& operator =(const Array&) = delete ;
55
+
45
56
explicit operator bool () const { return array; }
46
57
47
58
operator UntaggedType*() const { return array; }
@@ -103,6 +114,10 @@ namespace jni
103
114
private:
104
115
UntaggedType* array = nullptr ;
105
116
117
+ template < class T , class D > friend class UniquePointerlike ;
118
+
119
+ void reset (UntaggedType* a) { array = a; }
120
+
106
121
public:
107
122
explicit Array (std::nullptr_t = nullptr )
108
123
{}
@@ -115,6 +130,13 @@ namespace jni
115
130
: array(&a)
116
131
{}
117
132
133
+ Array (const Array& a)
134
+ : array(a.array)
135
+ {}
136
+
137
+ // Not reassignable; it would break UniquePointerlike's abstraction.
138
+ Array& operator =(const Array&) = delete ;
139
+
118
140
explicit operator bool () const { return array; }
119
141
120
142
operator UntaggedType*() const { return array; }
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ namespace jni
25
25
private:
26
26
jclass* clazz = nullptr ;
27
27
28
+ template < class T , class D > friend class UniquePointerlike ;
29
+
30
+ void reset (jclass* c) { clazz = c; }
31
+
28
32
public:
29
33
using TagType = TheTag;
30
34
@@ -35,6 +39,13 @@ namespace jni
35
39
: clazz(&c)
36
40
{}
37
41
42
+ Class (const Class& c)
43
+ : clazz(c.clazz)
44
+ {}
45
+
46
+ // Not reassignable; it would break UniquePointerlike's abstraction.
47
+ Class& operator =(const Class&) = delete ;
48
+
38
49
explicit operator bool () const { return clazz; }
39
50
40
51
operator jclass&() const { return *clazz; }
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ namespace jni
39
39
private:
40
40
UntaggedObjectType* obj = nullptr ;
41
41
42
+ template < class T , class D > friend class UniquePointerlike ;
43
+
44
+ void reset (UntaggedObjectType* o) { obj = o; }
45
+
42
46
public:
43
47
explicit Object (std::nullptr_t = nullptr )
44
48
{}
@@ -51,11 +55,18 @@ namespace jni
51
55
: obj(&o)
52
56
{}
53
57
58
+ Object (const Object& o)
59
+ : obj(o.obj)
60
+ {}
61
+
54
62
template < class Tag >
55
63
Object (const Object<Tag>& o, std::enable_if_t < std::is_convertible<Tag, TagType>::value >* = nullptr )
56
64
: obj(o.Get())
57
65
{}
58
66
67
+ // Not reassignable; it would break UniquePointerlike's abstraction.
68
+ Object& operator =(const Object&) = delete ;
69
+
59
70
explicit operator bool () const { return obj; }
60
71
61
72
operator UntaggedObjectType*() const { return obj; }
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ namespace jni
56
56
void reset (T&& t = T())
57
57
{
58
58
T current = pointerlike;
59
- pointerlike = std::move (t );
59
+ pointerlike. reset (t. Get () );
60
60
if (current)
61
61
{
62
62
get_deleter ()(current.Get ());
@@ -66,7 +66,7 @@ namespace jni
66
66
T release ()
67
67
{
68
68
T current = pointerlike;
69
- pointerlike = T ( );
69
+ pointerlike. reset ( nullptr );
70
70
return current;
71
71
}
72
72
Original file line number Diff line number Diff line change @@ -125,7 +125,6 @@ int main()
125
125
126
126
jni::Object<Derived> derived;
127
127
jni::Object<Base> base (derived);
128
- base = derived;
129
128
(void )[] () -> jni::Object<Base> { return jni::Object<Derived>(); };
130
129
(void )[] () -> jni::Object<> { return jni::String (); };
131
130
You can’t perform that action at this time.
0 commit comments