xot 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/{ChangeLog → README.md} +0 -0
- data/Rakefile +7 -6
- data/VERSION +1 -1
- data/ext/xot/extconf.rb +10 -49
- data/ext/xot/tester.cpp +93 -0
- data/include/xot.h +4 -1
- data/include/xot/exception.h +70 -0
- data/include/xot/ref.h +171 -41
- data/include/xot/string.h +35 -16
- data/include/xot/time.h +17 -0
- data/include/xot/util.h +26 -0
- data/lib/xot.rb +3 -2
- data/lib/xot/bit_flag.rb +52 -0
- data/lib/xot/extconf.rb +59 -0
- data/lib/xot/invoker.rb +48 -0
- data/lib/xot/module.rb +11 -7
- data/lib/xot/rake.rb +99 -14
- data/lib/xot/setter.rb +5 -6
- data/lib/xot/test.rb +20 -0
- data/src/debug.cpp +5 -1
- data/src/exception.cpp +89 -0
- data/src/string.cpp +39 -0
- data/src/time.cpp +24 -0
- data/task/ext.rake +13 -27
- data/task/lib.rake +20 -36
- data/task/mac.rake +45 -0
- data/test/helper.rb +6 -3
- data/test/test_bit_flag.rb +66 -0
- data/test/test_invoker.rb +41 -0
- data/test/test_setter.rb +3 -2
- data/xot.gemspec +3 -4
- metadata +26 -26
- data/.gitignore +0 -14
- data/README +0 -0
- data/lib/xot/load_path.rb +0 -28
- data/src/defs.cpp +0 -6
- data/task/git.rake +0 -32
- data/task/submodule.rake +0 -51
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b300601324c88ccfa6fc6e1c7c2aee5780dab91a
|
4
|
+
data.tar.gz: 3a1084e6aa373e275acdeda17ddc825151266ed4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff596b6f8d92698e58f2aab19c98234251a2bf4ad9489b9f11a04a637d23ac88aee5a7e61c3f2ea90d9c6cefbc9bcf32cdd9d8d512a5da31b156c5c3e45ff7bd
|
7
|
+
data.tar.gz: ea6adff9f5dba95b7403da54c0e6c7f075c82d1e0c2d8dbad987a7c426dac7eaaf9a5626118e9c6490113c855fedd71825521203aaf224c5d173fa95ddc862bb
|
data/{ChangeLog → README.md}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
%w[.]
|
5
|
+
.map {|s| File.expand_path "../#{s}/lib", __FILE__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
7
|
|
8
8
|
require 'xot/rake'
|
9
9
|
require 'xot/module'
|
@@ -11,8 +11,9 @@ require 'xot/module'
|
|
11
11
|
include Xot::Rake
|
12
12
|
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
MODULES = [Xot].map {|m| m.const_get :Module}
|
15
|
+
MODULE = MODULES.last
|
16
|
+
DLNAME = 'tester'
|
16
17
|
|
17
18
|
|
18
19
|
task :default => :build
|
@@ -22,4 +23,4 @@ task :build => :lib
|
|
22
23
|
empty_task :test
|
23
24
|
|
24
25
|
|
25
|
-
|
26
|
+
MODULES.each {|m| m.load_tasks :lib, :ext, :test, :gem}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/ext/xot/extconf.rb
CHANGED
@@ -1,59 +1,20 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
%w[.]
|
5
|
+
.map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
7
|
|
8
8
|
require 'mkmf'
|
9
|
-
require 'xot/
|
9
|
+
require 'xot/extconf'
|
10
10
|
require 'xot/module'
|
11
11
|
|
12
|
-
include Xot::Rake
|
13
|
-
|
14
|
-
|
15
|
-
debug = env :DEBUG, false
|
16
|
-
|
17
|
-
|
18
|
-
DEFS = []
|
19
|
-
INCDIRS = %w[
|
20
|
-
/opt/local/include
|
21
|
-
/opt/include
|
22
|
-
]
|
23
|
-
LIBDIRS = []
|
24
|
-
|
25
|
-
HEADERS = %w[
|
26
|
-
boost/noncopyable.hpp
|
27
|
-
ruby.h
|
28
|
-
xot.h
|
29
|
-
]
|
30
|
-
LIBS = %w[
|
31
|
-
stdc++
|
32
|
-
xot
|
33
|
-
]
|
34
|
-
|
35
12
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
DEFS << $~[0].upcase if RUBY_PLATFORM =~ /mswin|ming|cygwin|darwin/i
|
13
|
+
Xot::ExtConf.new Xot do
|
14
|
+
setup do
|
15
|
+
headers << 'boost/noncopyable.hpp' << 'ruby.h'
|
16
|
+
end
|
41
17
|
|
42
|
-
|
43
|
-
|
44
|
-
$LDFLAGS << LIBDIRS.map {|s| " -L#{s}"}.join
|
45
|
-
$CFLAGS << ' --stdlib=libc++' if clang?
|
46
|
-
|
47
|
-
RbConfig::CONFIG.each do |key, val|
|
48
|
-
{'gcc' => 'g++', 'clang' => 'clang++'}.each {|from, to| val.gsub! from, to}
|
18
|
+
dir_config 'boost'
|
19
|
+
create_makefile 'xot/tester'
|
49
20
|
end
|
50
|
-
|
51
|
-
|
52
|
-
dir_config 'boost'
|
53
|
-
dir_config 'xot', Xot.root_dir
|
54
|
-
|
55
|
-
exit 1 unless HEADERS.all? {|s| have_header(s)}
|
56
|
-
exit 1 unless LIBS.all? {|s| have_library(s)}
|
57
|
-
|
58
|
-
|
59
|
-
create_makefile 'xot/tester'
|
data/ext/xot/tester.cpp
CHANGED
@@ -1,9 +1,102 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
|
3
3
|
|
4
|
+
#include "xot.h"
|
5
|
+
|
6
|
+
|
7
|
+
template <typename EXCEPTION>
|
8
|
+
static bool
|
9
|
+
test_exception (bool should_catch = true)
|
10
|
+
{
|
11
|
+
try
|
12
|
+
{
|
13
|
+
throw EXCEPTION("");
|
14
|
+
}
|
15
|
+
catch (EXCEPTION& e)
|
16
|
+
{
|
17
|
+
if (!should_catch) return false;
|
18
|
+
}
|
19
|
+
catch (...)
|
20
|
+
{
|
21
|
+
if (should_catch) return false;
|
22
|
+
}
|
23
|
+
|
24
|
+
Xot::String s = "Exception Message";
|
25
|
+
EXCEPTION e(s);
|
26
|
+
if (e.what() != s) return false;
|
27
|
+
|
28
|
+
return true;
|
29
|
+
}
|
30
|
+
|
31
|
+
static bool
|
32
|
+
test_exception ()
|
33
|
+
{
|
34
|
+
if (!test_exception<Xot::XotError>()) return false;
|
35
|
+
if (!test_exception<Xot::InvalidStateError>()) return false;
|
36
|
+
if (!test_exception<Xot::SystemError>()) return false;
|
37
|
+
if (!test_exception<Xot::NotImplementedError>()) return false;
|
38
|
+
if (!test_exception<std::invalid_argument>()) return false;
|
39
|
+
if (!test_exception<std::out_of_range>()) return false;
|
40
|
+
return true;
|
41
|
+
}
|
42
|
+
|
43
|
+
struct RefObj : public Xot::RefCountable<> {};
|
44
|
+
|
45
|
+
static bool
|
46
|
+
test_ref ()
|
47
|
+
{
|
48
|
+
if (!(Xot::Ref<RefObj>(NULL) == Xot::Ref<RefObj>(NULL))) return false;
|
49
|
+
if (!(Xot::Ref<RefObj>(NULL) != Xot::Ref<RefObj>(new RefObj))) return false;
|
50
|
+
|
51
|
+
if (!(Xot::Ref<RefObj>(NULL) == Xot::Ref<const RefObj>(NULL))) return false;
|
52
|
+
if (!(Xot::Ref<RefObj>(NULL) != Xot::Ref<const RefObj>(new RefObj))) return false;
|
53
|
+
|
54
|
+
if (!(Xot::Ref<const RefObj>(NULL) == Xot::Ref<RefObj>(NULL))) return false;
|
55
|
+
if (!(Xot::Ref<const RefObj>(NULL) != Xot::Ref<RefObj>(new RefObj))) return false;
|
56
|
+
|
57
|
+
if (!(Xot::Ref<const RefObj>(NULL) == Xot::Ref<const RefObj>(NULL))) return false;
|
58
|
+
if (!(Xot::Ref<const RefObj>(NULL) != Xot::Ref<const RefObj>(new RefObj))) return false;
|
59
|
+
|
60
|
+
if (!(Xot::Ref<RefObj>(NULL) == (RefObj*) NULL)) return false;
|
61
|
+
if (!(Xot::Ref<RefObj>(NULL) != new RefObj)) return false;
|
62
|
+
return true;
|
63
|
+
}
|
64
|
+
|
65
|
+
static bool
|
66
|
+
test_util ()
|
67
|
+
{
|
68
|
+
if (!(Xot::clip(10, 100, 50) == 50)) return false;
|
69
|
+
if (!(Xot::clip(10, 100, 10) == 10)) return false;
|
70
|
+
if (!(Xot::clip(10, 100, 100) == 100)) return false;
|
71
|
+
if (!(Xot::clip(10, 100, 0) == 10)) return false;
|
72
|
+
if (!(Xot::clip(10, 100, 200) == 100)) return false;
|
73
|
+
|
74
|
+
int value;
|
75
|
+
int* p = &value;
|
76
|
+
if (!(Xot::get_pointer_flag(p) == false)) return false;
|
77
|
+
|
78
|
+
p = Xot::set_pointer_flag(p);
|
79
|
+
if (!(Xot::get_pointer_flag(p) == true)) return false;
|
80
|
+
|
81
|
+
p = Xot::set_pointer_flag(p, false);
|
82
|
+
if (!(Xot::get_pointer_flag(p) == false)) return false;
|
83
|
+
|
84
|
+
p = Xot::set_pointer_flag(p, true);
|
85
|
+
if (!(Xot::get_pointer_flag(p) == true)) return false;
|
86
|
+
|
87
|
+
if (!( p != &value)) return false;
|
88
|
+
if (!(Xot::set_pointer_flag(p, false) == &value)) return false;
|
89
|
+
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
|
93
|
+
|
4
94
|
static VALUE
|
5
95
|
test_native (VALUE self)
|
6
96
|
{
|
97
|
+
if (!test_exception()) return false;
|
98
|
+
if (!test_ref()) return false;
|
99
|
+
if (!test_util()) return false;
|
7
100
|
return true;
|
8
101
|
}
|
9
102
|
|
data/include/xot.h
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __XOT_EXCEPTION_H__
|
4
|
+
#define __XOT_EXCEPTION_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <stdexcept>
|
8
|
+
#include <xot/string.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Xot
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
class XotError : public std::runtime_error
|
16
|
+
{
|
17
|
+
typedef std::runtime_error Super;
|
18
|
+
public: XotError (const char* str = NULL);
|
19
|
+
};
|
20
|
+
|
21
|
+
|
22
|
+
class InvalidStateError : public XotError
|
23
|
+
{
|
24
|
+
typedef XotError Super;
|
25
|
+
public: InvalidStateError (const char* str = NULL);
|
26
|
+
};
|
27
|
+
|
28
|
+
|
29
|
+
class SystemError : public XotError
|
30
|
+
{
|
31
|
+
typedef XotError Super;
|
32
|
+
public: SystemError (const char* str = NULL);
|
33
|
+
};
|
34
|
+
|
35
|
+
|
36
|
+
class NotImplementedError : public XotError
|
37
|
+
{
|
38
|
+
typedef XotError Super;
|
39
|
+
public: NotImplementedError (const char* str = NULL);
|
40
|
+
};
|
41
|
+
|
42
|
+
|
43
|
+
String error_text (const char* file, int line, const char* str);
|
44
|
+
|
45
|
+
|
46
|
+
namespace ErrorFunctions
|
47
|
+
{
|
48
|
+
|
49
|
+
void xot_error (const char* file, int line, const char* format = NULL, ...);
|
50
|
+
|
51
|
+
void argument_error (const char* file, int line, const char* format = NULL, ...);
|
52
|
+
|
53
|
+
void index_error (const char* file, int line, const char* format = NULL, ...);
|
54
|
+
|
55
|
+
void invalid_state_error (const char* file, int line, const char* format = NULL, ...);
|
56
|
+
|
57
|
+
void system_error (const char* file, int line, const char* format = NULL, ...);
|
58
|
+
|
59
|
+
void not_implemented_error (const char* file, int line, const char* format = NULL, ...);
|
60
|
+
|
61
|
+
}// ErrorFunctions
|
62
|
+
|
63
|
+
|
64
|
+
using namespace ErrorFunctions;
|
65
|
+
|
66
|
+
|
67
|
+
}// Xot
|
68
|
+
|
69
|
+
|
70
|
+
#endif//EOH
|
data/include/xot/ref.h
CHANGED
@@ -4,10 +4,18 @@
|
|
4
4
|
#define __XOT_REF_H__
|
5
5
|
|
6
6
|
|
7
|
+
#ifdef check // by OSX's AssertMacros.h
|
8
|
+
#undef check
|
9
|
+
#endif
|
10
|
+
|
11
|
+
#include <limits.h>
|
7
12
|
#include <assert.h>
|
8
13
|
#include <typeinfo>
|
9
14
|
#include <boost/noncopyable.hpp>
|
15
|
+
#include <boost/type_traits.hpp>
|
16
|
+
#include <boost/utility/enable_if.hpp>
|
10
17
|
#include <xot/defs.h>
|
18
|
+
#include <xot/exception.h>
|
11
19
|
#include <xot/debug.h>
|
12
20
|
|
13
21
|
|
@@ -22,32 +30,32 @@ namespace Xot
|
|
22
30
|
|
23
31
|
|
24
32
|
template <typename SuperClass = EmptyClass>
|
25
|
-
class RefCountable : public SuperClass
|
33
|
+
class RefCountable : public SuperClass, public boost::noncopyable
|
26
34
|
{
|
27
35
|
|
28
36
|
public:
|
29
37
|
|
30
|
-
virtual void retain ()
|
38
|
+
virtual void retain (void* data = NULL) const
|
31
39
|
{
|
32
|
-
|
40
|
+
refc_update_count(+1);
|
33
41
|
|
34
42
|
#ifdef XOT_REF_DEBUG
|
35
43
|
doutln(
|
36
44
|
"%s: %d -> %d",
|
37
|
-
typeid(this).name(),
|
45
|
+
typeid(this).name(), refc_count() - 1, refc_count());
|
38
46
|
#endif
|
39
47
|
}
|
40
48
|
|
41
|
-
virtual void release ()
|
49
|
+
virtual void release (void* data = NULL) const
|
42
50
|
{
|
43
|
-
assert(
|
44
|
-
bool del = !
|
51
|
+
assert(refc_count() >= 0);
|
52
|
+
bool del = !refc_retained() || refc_update_count(-1) == 0;
|
45
53
|
|
46
54
|
#ifdef XOT_REF_DEBUG
|
47
55
|
doutln(
|
48
56
|
"%s: %d -> %d, refcount:%s, delete:%s",
|
49
|
-
typeid(this).name(),
|
50
|
-
|
57
|
+
typeid(this).name(), refc_count() + 1, refc_count(),
|
58
|
+
refc_retained() ? "yes" : "no", del ? "yes" : "no");
|
51
59
|
#endif
|
52
60
|
|
53
61
|
if (del) delete this;
|
@@ -56,7 +64,6 @@ namespace Xot
|
|
56
64
|
protected:
|
57
65
|
|
58
66
|
RefCountable ()
|
59
|
-
: refcount(0)
|
60
67
|
{
|
61
68
|
}
|
62
69
|
|
@@ -64,44 +71,78 @@ namespace Xot
|
|
64
71
|
{
|
65
72
|
}
|
66
73
|
|
67
|
-
|
74
|
+
virtual int refc_count () const
|
75
|
+
{
|
76
|
+
return refc.count;
|
77
|
+
}
|
68
78
|
|
69
|
-
|
79
|
+
virtual bool refc_retained () const
|
80
|
+
{
|
81
|
+
return refc.aux & 0x1;
|
82
|
+
}
|
70
83
|
|
71
|
-
|
84
|
+
virtual int refc_update_count (int add) const
|
72
85
|
{
|
73
|
-
|
86
|
+
assert(add != 0);
|
87
|
+
if (add >= 0) refc.aux |= 0x1;// bit for retained flag.
|
88
|
+
|
89
|
+
int c = refc.count + add;
|
90
|
+
if (c < 0)
|
91
|
+
invalid_state_error(__FILE__, __LINE__);
|
92
|
+
if (c > USHRT_MAX)
|
93
|
+
xot_error(__FILE__, __LINE__, "refc.count overflow.");
|
94
|
+
|
95
|
+
return refc.count = c;
|
74
96
|
}
|
75
97
|
|
76
|
-
|
98
|
+
virtual ushort refc_aux () const
|
77
99
|
{
|
78
|
-
return
|
100
|
+
return refc.aux >> 1;
|
79
101
|
}
|
80
102
|
|
81
|
-
|
103
|
+
virtual void refc_set_aux (ushort aux) const
|
82
104
|
{
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
105
|
+
if ((0x1 << 15) & aux)
|
106
|
+
argument_error(__FILE__, __LINE__);
|
107
|
+
|
108
|
+
refc.aux = (refc.aux & 0x1) | (aux << 1);
|
87
109
|
}
|
88
110
|
|
89
|
-
|
111
|
+
private:
|
90
112
|
|
91
|
-
|
113
|
+
mutable struct Data
|
114
|
+
{
|
115
|
+
|
116
|
+
ushort count, aux;
|
117
|
+
|
118
|
+
Data () : count(0), aux(0) {}
|
119
|
+
|
120
|
+
} refc;
|
92
121
|
|
93
122
|
};// RefCountable
|
94
123
|
|
95
124
|
|
96
|
-
template <typename T>
|
125
|
+
template <typename T, typename = void>
|
97
126
|
class Ref
|
98
127
|
{
|
99
128
|
|
100
129
|
typedef Ref<T> This;
|
101
130
|
|
131
|
+
typedef T Value;
|
132
|
+
|
133
|
+
typedef const T ConstValue;
|
134
|
+
|
135
|
+
typedef T& Reference;
|
136
|
+
|
137
|
+
typedef const T& ConstReference;
|
138
|
+
|
139
|
+
typedef T* Pointer;
|
140
|
+
|
141
|
+
typedef const T* ConstPointer;
|
142
|
+
|
102
143
|
public:
|
103
144
|
|
104
|
-
Ref (
|
145
|
+
Ref (Pointer ptr = NULL)
|
105
146
|
: ptr(ptr)
|
106
147
|
{
|
107
148
|
if (ptr) ptr->retain();
|
@@ -113,13 +154,13 @@ namespace Xot
|
|
113
154
|
if (ptr) ptr->retain();
|
114
155
|
}
|
115
156
|
|
116
|
-
|
157
|
+
This& operator = (Pointer ptr)
|
117
158
|
{
|
118
159
|
reset(ptr);
|
119
160
|
return *this;
|
120
161
|
}
|
121
162
|
|
122
|
-
|
163
|
+
This& operator = (const This& obj)
|
123
164
|
{
|
124
165
|
if (&obj == this) return *this;
|
125
166
|
reset(obj.ptr);
|
@@ -131,7 +172,7 @@ namespace Xot
|
|
131
172
|
if (ptr) ptr->release();
|
132
173
|
}
|
133
174
|
|
134
|
-
void reset (
|
175
|
+
void reset (Pointer ptr = NULL)
|
135
176
|
{
|
136
177
|
if (this->ptr == ptr) return;
|
137
178
|
if (this->ptr) this->ptr->release();
|
@@ -139,41 +180,130 @@ namespace Xot
|
|
139
180
|
if (this->ptr) this->ptr->retain();
|
140
181
|
}
|
141
182
|
|
142
|
-
|
183
|
+
Pointer get () {return ptr;}
|
184
|
+
|
185
|
+
ConstPointer get () const {return ptr;}
|
186
|
+
|
187
|
+
Pointer operator -> () {return get();}
|
188
|
+
|
189
|
+
ConstPointer operator -> () const {return get();}
|
190
|
+
|
191
|
+
Reference operator * () {return *get();}
|
192
|
+
|
193
|
+
ConstReference operator * () const {return *get();}
|
194
|
+
|
195
|
+
operator Pointer () {return get();}
|
196
|
+
|
197
|
+
operator ConstPointer () const {return get();}
|
198
|
+
|
199
|
+
bool operator == (Pointer ptr) const {return this->ptr == ptr;}
|
200
|
+
|
201
|
+
bool operator != (Pointer ptr) const {return !operator==(ptr);}
|
202
|
+
|
203
|
+
bool operator == (ConstPointer ptr) const {return this->ptr == ptr;}
|
204
|
+
|
205
|
+
bool operator != (ConstPointer ptr) const {return !operator==(ptr);}
|
206
|
+
|
207
|
+
bool operator == (const This& obj) const {return ptr == obj.ptr;}
|
208
|
+
|
209
|
+
bool operator != (const This& obj) const {return !operator==(obj);}
|
210
|
+
|
211
|
+
bool operator < (const This& obj) const {return ptr < obj.ptr;}
|
212
|
+
|
213
|
+
operator bool () const {return ptr != NULL;}
|
214
|
+
|
215
|
+
bool operator ! () const {return !operator bool();}
|
216
|
+
|
217
|
+
private:
|
218
|
+
|
219
|
+
Pointer ptr;
|
143
220
|
|
144
|
-
|
221
|
+
};// Ref
|
222
|
+
|
223
|
+
|
224
|
+
template <typename T>
|
225
|
+
class Ref<T, typename boost::enable_if<boost::is_const<T> >::type>
|
226
|
+
{
|
227
|
+
|
228
|
+
typedef Ref<T> This;
|
229
|
+
|
230
|
+
typedef typename boost::remove_const<T>::type Value;
|
231
|
+
|
232
|
+
typedef T ConstValue;
|
233
|
+
|
234
|
+
typedef Value& Reference;
|
235
|
+
|
236
|
+
typedef const Value& ConstReference;
|
237
|
+
|
238
|
+
typedef Value* Pointer;
|
239
|
+
|
240
|
+
typedef const Value* ConstPointer;
|
241
|
+
|
242
|
+
public:
|
243
|
+
|
244
|
+
Ref (ConstPointer ptr = NULL)
|
245
|
+
: ptr(ptr)
|
246
|
+
{
|
247
|
+
if (ptr) ptr->retain();
|
248
|
+
}
|
249
|
+
|
250
|
+
Ref (const This& obj)
|
251
|
+
: ptr(obj.ptr)
|
252
|
+
{
|
253
|
+
if (ptr) ptr->retain();
|
254
|
+
}
|
145
255
|
|
146
|
-
|
256
|
+
This& operator = (ConstPointer ptr)
|
257
|
+
{
|
258
|
+
reset(ptr);
|
259
|
+
return *this;
|
260
|
+
}
|
147
261
|
|
148
|
-
|
262
|
+
This& operator = (const This& obj)
|
263
|
+
{
|
264
|
+
if (&obj == this) return *this;
|
265
|
+
reset(obj.ptr);
|
266
|
+
return *this;
|
267
|
+
}
|
149
268
|
|
150
|
-
|
269
|
+
~Ref ()
|
270
|
+
{
|
271
|
+
if (ptr) ptr->release();
|
272
|
+
}
|
151
273
|
|
152
|
-
|
274
|
+
void reset (ConstPointer ptr = NULL)
|
275
|
+
{
|
276
|
+
if (this->ptr == ptr) return;
|
277
|
+
if (this->ptr) this->ptr->release();
|
278
|
+
this->ptr = ptr;
|
279
|
+
if (this->ptr) this->ptr->retain();
|
280
|
+
}
|
153
281
|
|
154
|
-
|
282
|
+
ConstPointer get () const {return ptr;}
|
155
283
|
|
156
|
-
operator
|
284
|
+
ConstPointer operator -> () const {return get();}
|
157
285
|
|
158
|
-
|
286
|
+
ConstReference operator * () const {return *get();}
|
159
287
|
|
160
|
-
|
288
|
+
operator ConstPointer () const {return get();}
|
161
289
|
|
162
|
-
bool operator == (
|
290
|
+
bool operator == (ConstPointer ptr) const {return this->ptr == ptr;}
|
163
291
|
|
164
|
-
bool operator != (
|
292
|
+
bool operator != (ConstPointer ptr) const {return !operator==(ptr);}
|
165
293
|
|
166
294
|
bool operator == (const This& obj) const {return ptr == obj.ptr;}
|
167
295
|
|
168
296
|
bool operator != (const This& obj) const {return !operator==(obj);}
|
169
297
|
|
298
|
+
bool operator < (const This& obj) const {return ptr < obj.ptr;}
|
299
|
+
|
170
300
|
operator bool () const {return ptr != NULL;}
|
171
301
|
|
172
302
|
bool operator ! () const {return !operator bool();}
|
173
303
|
|
174
304
|
private:
|
175
305
|
|
176
|
-
|
306
|
+
ConstPointer ptr;
|
177
307
|
|
178
308
|
};// Ref
|
179
309
|
|