xot 0.1.11 → 0.1.16
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 +5 -5
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +8 -13
- data/VERSION +1 -1
- data/ext/xot/extconf.rb +2 -3
- data/ext/xot/tester.cpp +55 -7
- data/include/xot.h +5 -3
- data/include/xot/debug.h +6 -1
- data/include/xot/defs.h +2 -3
- data/include/xot/exception.h +18 -6
- data/include/xot/noncopyable.h +30 -0
- data/include/xot/pimpl.h +10 -18
- data/include/xot/ref.h +25 -58
- data/include/xot/string.h +9 -0
- data/include/xot/time.h +3 -1
- data/include/xot/util.h +68 -13
- data/lib/xot.rb +5 -1
- data/lib/xot/bit_flag.rb +28 -15
- data/lib/xot/bit_flag_accessor.rb +78 -0
- data/lib/xot/bit_util.rb +19 -0
- data/lib/xot/const_symbol_accessor.rb +59 -0
- data/lib/xot/extconf.rb +8 -7
- data/lib/xot/module.rb +4 -19
- data/lib/xot/rake.rb +302 -127
- data/lib/xot/rake/alias_task.rb +34 -0
- data/lib/xot/rake/escalation.rb +32 -0
- data/lib/xot/rake/util.rb +255 -0
- data/lib/xot/setter.rb +2 -1
- data/lib/xot/universal_accessor.rb +40 -0
- data/src/debug.cpp +3 -3
- data/src/string.cpp +33 -2
- data/src/time.cpp +16 -8
- data/test/test_bit_flag.rb +1 -10
- data/test/test_bit_flag_accessor.rb +64 -0
- data/test/test_bit_util.rb +18 -0
- data/test/test_const_symbol_accessor.rb +56 -0
- data/test/test_universal_accessor.rb +51 -0
- data/xot.gemspec +3 -6
- metadata +28 -45
- data/task/ext.rake +0 -76
- data/task/gem.rake +0 -51
- data/task/lib.rake +0 -92
- data/task/mac.rake +0 -45
- data/task/test.rake +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0e6a18a9ea642c4ac20d70096dddf5eadf89e6de95b093940402e5cefa746be3
|
4
|
+
data.tar.gz: b2118e8a68ca94e770ae1ef26f9f60a26f77ccf04e2fc7ba28b7fc89f4da1aa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00c9091d6f2204c2a23d942acd788e157d0b14b1de2b5ea1e378725748cc36f37c46abdbe20a5a75a0070976210ef8f4405d03b356be26d53095d5c8010aa8fa
|
7
|
+
data.tar.gz: 6711e0296cea2b5fc0a7849322a65bd1bb3f8b70d0a81fec444bb4d52b5143b67ad8ee29fcb456334c7aec26975b59c12b5c6bc0ceba239a3525789e6f0f1ba6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 xord.org
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -2,25 +2,20 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
%w[.]
|
5
|
-
.map {|s| File.expand_path "
|
5
|
+
.map {|s| File.expand_path "#{s}/lib", __dir__}
|
6
6
|
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
7
|
|
8
8
|
require 'xot/rake'
|
9
|
-
require 'xot/module'
|
10
9
|
|
11
|
-
|
10
|
+
require 'xot/module'
|
12
11
|
|
13
12
|
|
14
|
-
MODULES = [Xot]
|
15
|
-
MODULE = MODULES.last
|
13
|
+
MODULES = [Xot]
|
16
14
|
DLNAME = 'tester'
|
17
15
|
|
16
|
+
build_native_library
|
17
|
+
build_ruby_extension dlname: DLNAME
|
18
|
+
test_ruby_extension
|
19
|
+
build_ruby_gem
|
18
20
|
|
19
|
-
task :default => :
|
20
|
-
|
21
|
-
task :build => :lib
|
22
|
-
|
23
|
-
empty_task :test
|
24
|
-
|
25
|
-
|
26
|
-
MODULES.each {|m| m.load_tasks :lib, :ext, :test, :gem}
|
21
|
+
task :default => :test
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.16
|
data/ext/xot/extconf.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
%w[.]
|
5
|
-
.map {|s| File.expand_path "
|
5
|
+
.map {|s| File.expand_path "../../#{s}/lib", __dir__}
|
6
6
|
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
7
|
|
8
8
|
require 'mkmf'
|
@@ -12,9 +12,8 @@ require 'xot/module'
|
|
12
12
|
|
13
13
|
Xot::ExtConf.new Xot do
|
14
14
|
setup do
|
15
|
-
headers << '
|
15
|
+
headers << 'ruby.h'
|
16
16
|
end
|
17
17
|
|
18
|
-
dir_config 'boost'
|
19
18
|
create_makefile 'xot/tester'
|
20
19
|
end
|
data/ext/xot/tester.cpp
CHANGED
@@ -4,6 +4,26 @@
|
|
4
4
|
#include "xot.h"
|
5
5
|
|
6
6
|
|
7
|
+
static bool
|
8
|
+
test_string ()
|
9
|
+
{
|
10
|
+
if (Xot::String("aBc") .upcase() != "ABC") return false;
|
11
|
+
if (Xot::String("aBc") .downcase() != "abc") return false;
|
12
|
+
if (Xot::String(" \taBc \r\n\f\v").strip() != "aBc") return false;
|
13
|
+
if (Xot::String(" \t\r\n\f\v") .strip() != "") return false;
|
14
|
+
if (Xot::String("") .strip() != "") return false;
|
15
|
+
return true;
|
16
|
+
}
|
17
|
+
|
18
|
+
static bool
|
19
|
+
test_time ()
|
20
|
+
{
|
21
|
+
double t = Xot::time();
|
22
|
+
Xot::sleep(0.001);
|
23
|
+
if (Xot::time() <= t) return false;
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
|
7
27
|
template <typename EXCEPTION>
|
8
28
|
static bool
|
9
29
|
test_exception (bool should_catch = true)
|
@@ -65,27 +85,53 @@ test_ref ()
|
|
65
85
|
static bool
|
66
86
|
test_util ()
|
67
87
|
{
|
88
|
+
if (Xot::bit(0) != 0x1) return false;
|
89
|
+
if (Xot::bit(1) != 0x2) return false;
|
90
|
+
if (Xot::bit(2) != 0x4) return false;
|
91
|
+
if (Xot::bit(3) != 0x8) return false;
|
92
|
+
|
68
93
|
if (!(Xot::clip(10, 100, 50) == 50)) return false;
|
69
94
|
if (!(Xot::clip(10, 100, 10) == 10)) return false;
|
70
95
|
if (!(Xot::clip(10, 100, 100) == 100)) return false;
|
71
96
|
if (!(Xot::clip(10, 100, 0) == 10)) return false;
|
72
97
|
if (!(Xot::clip(10, 100, 200) == 100)) return false;
|
73
98
|
|
99
|
+
static const int F0 = Xot::bit(0), F1 = Xot::bit(1), F2 = Xot::bit(2);
|
100
|
+
|
101
|
+
int flags = 0;
|
102
|
+
if (Xot::has_flag(flags, 0)) return false;
|
103
|
+
if (Xot::has_flag(flags, F0)) return false;
|
104
|
+
|
105
|
+
Xot:: add_flag(&flags, F0);
|
106
|
+
if (!Xot::has_flag(flags, F0)) return false;
|
107
|
+
|
108
|
+
Xot:: add_flag(&flags, F1);
|
109
|
+
if (!Xot::has_flag(flags, F0)) return false;
|
110
|
+
if (!Xot::has_flag(flags, F1)) return false;
|
111
|
+
if (!Xot::has_flag(flags, F0 | F1)) return false;
|
112
|
+
if ( Xot::has_flag(flags, F0 | F1 | F2)) return false;
|
113
|
+
|
114
|
+
Xot:: remove_flag(&flags, F1);
|
115
|
+
if (!Xot::has_flag(flags, F0)) return false;
|
116
|
+
if ( Xot::has_flag(flags, F1)) return false;
|
117
|
+
if ( Xot::has_flag(flags, F0 | F1)) return false;
|
118
|
+
if ( Xot::has_flag(flags, F0 | F1 | F2)) return false;
|
119
|
+
|
74
120
|
int value;
|
75
121
|
int* p = &value;
|
76
122
|
if (!(Xot::get_pointer_flag(p) == false)) return false;
|
77
123
|
|
78
|
-
p =
|
124
|
+
p = Xot::set_pointer_flag(p);
|
79
125
|
if (!(Xot::get_pointer_flag(p) == true)) return false;
|
80
126
|
|
81
|
-
p =
|
127
|
+
p = Xot::set_pointer_flag(p, false);
|
82
128
|
if (!(Xot::get_pointer_flag(p) == false)) return false;
|
83
129
|
|
84
|
-
p =
|
130
|
+
p = Xot::set_pointer_flag(p, true);
|
85
131
|
if (!(Xot::get_pointer_flag(p) == true)) return false;
|
86
132
|
|
87
|
-
if (!( p != &value))
|
88
|
-
if (!(Xot::set_pointer_flag(p, false) == &value))
|
133
|
+
if (!( p != &value)) return false;
|
134
|
+
if (!(Xot::set_pointer_flag(p, false) == &value)) return false;
|
89
135
|
|
90
136
|
return true;
|
91
137
|
}
|
@@ -94,9 +140,11 @@ test_util ()
|
|
94
140
|
static VALUE
|
95
141
|
test_native (VALUE self)
|
96
142
|
{
|
143
|
+
if (!test_string()) return false;
|
144
|
+
if (!test_time()) return false;
|
97
145
|
if (!test_exception()) return false;
|
98
|
-
if (!test_ref())
|
99
|
-
if (!test_util())
|
146
|
+
if (!test_ref()) return false;
|
147
|
+
if (!test_util()) return false;
|
100
148
|
return true;
|
101
149
|
}
|
102
150
|
|
data/include/xot.h
CHANGED
@@ -5,13 +5,15 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
#include <xot/defs.h>
|
8
|
-
#include <xot/string.h>
|
9
8
|
#include <xot/exception.h>
|
9
|
+
#include <xot/debug.h>
|
10
|
+
|
11
|
+
#include <xot/string.h>
|
12
|
+
#include <xot/time.h>
|
10
13
|
#include <xot/ref.h>
|
11
14
|
#include <xot/pimpl.h>
|
12
|
-
#include <xot/
|
15
|
+
#include <xot/noncopyable.h>
|
13
16
|
#include <xot/util.h>
|
14
|
-
#include <xot/debug.h>
|
15
17
|
|
16
18
|
|
17
19
|
#endif//EOH
|
data/include/xot/debug.h
CHANGED
data/include/xot/defs.h
CHANGED
data/include/xot/exception.h
CHANGED
@@ -46,17 +46,29 @@ namespace Xot
|
|
46
46
|
namespace ErrorFunctions
|
47
47
|
{
|
48
48
|
|
49
|
-
|
49
|
+
[[noreturn]]
|
50
|
+
void xot_error (
|
51
|
+
const char* file, int line, const char* format = NULL, ...);
|
50
52
|
|
51
|
-
|
53
|
+
[[noreturn]]
|
54
|
+
void argument_error (
|
55
|
+
const char* file, int line, const char* format = NULL, ...);
|
52
56
|
|
53
|
-
|
57
|
+
[[noreturn]]
|
58
|
+
void index_error (
|
59
|
+
const char* file, int line, const char* format = NULL, ...);
|
54
60
|
|
55
|
-
|
61
|
+
[[noreturn]]
|
62
|
+
void invalid_state_error (
|
63
|
+
const char* file, int line, const char* format = NULL, ...);
|
56
64
|
|
57
|
-
|
65
|
+
[[noreturn]]
|
66
|
+
void system_error (
|
67
|
+
const char* file, int line, const char* format = NULL, ...);
|
58
68
|
|
59
|
-
|
69
|
+
[[noreturn]]
|
70
|
+
void not_implemented_error (
|
71
|
+
const char* file, int line, const char* format = NULL, ...);
|
60
72
|
|
61
73
|
}// ErrorFunctions
|
62
74
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __XOT_NONCOPYABLE_H__
|
4
|
+
#define __XOT_NONCOPYABLE_H__
|
5
|
+
|
6
|
+
|
7
|
+
namespace Xot
|
8
|
+
{
|
9
|
+
|
10
|
+
|
11
|
+
class NonCopyable
|
12
|
+
{
|
13
|
+
|
14
|
+
protected:
|
15
|
+
|
16
|
+
NonCopyable () = default;
|
17
|
+
|
18
|
+
~NonCopyable () = default;
|
19
|
+
|
20
|
+
NonCopyable (const NonCopyable&) = delete;
|
21
|
+
|
22
|
+
NonCopyable& operator = (const NonCopyable&) = delete;
|
23
|
+
|
24
|
+
};// NonCopyable
|
25
|
+
|
26
|
+
|
27
|
+
}// Xot
|
28
|
+
|
29
|
+
|
30
|
+
#endif//EOH
|
data/include/xot/pimpl.h
CHANGED
@@ -4,24 +4,20 @@
|
|
4
4
|
#define __XOT_PIMPL_H__
|
5
5
|
|
6
6
|
|
7
|
-
#include <
|
8
|
-
#include <boost/shared_ptr.hpp>
|
7
|
+
#include <memory>
|
9
8
|
|
10
9
|
|
11
10
|
namespace Xot
|
12
11
|
{
|
13
12
|
|
14
13
|
|
15
|
-
template <typename T, bool SHARED = false> class PImpl;
|
16
|
-
|
17
|
-
|
18
14
|
template <typename T>
|
19
|
-
class PImpl
|
15
|
+
class PImpl : public std::unique_ptr<T>
|
20
16
|
{
|
21
17
|
|
22
|
-
typedef
|
18
|
+
typedef std::unique_ptr<T> Super;
|
23
19
|
|
24
|
-
typedef PImpl<T
|
20
|
+
typedef PImpl<T> This;
|
25
21
|
|
26
22
|
public:
|
27
23
|
|
@@ -37,28 +33,24 @@ namespace Xot
|
|
37
33
|
return *this;
|
38
34
|
}
|
39
35
|
|
40
|
-
bool shared () const {return false;}
|
41
|
-
|
42
36
|
};// PImpl
|
43
37
|
|
44
38
|
|
45
39
|
template <typename T>
|
46
|
-
class
|
40
|
+
class PSharedImpl : public std::shared_ptr<T>
|
47
41
|
{
|
48
42
|
|
49
|
-
typedef
|
43
|
+
typedef std::shared_ptr<T> Super;
|
50
44
|
|
51
|
-
typedef PImpl<T
|
45
|
+
typedef PImpl<T> This;
|
52
46
|
|
53
47
|
public:
|
54
48
|
|
55
|
-
|
49
|
+
PSharedImpl () : Super(new T) {}
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
bool shared () const {return true;}
|
51
|
+
PSharedImpl (T* p) : Super(p) {}
|
60
52
|
|
61
|
-
};//
|
53
|
+
};// PSharedImpl
|
62
54
|
|
63
55
|
|
64
56
|
}// Xot
|
data/include/xot/ref.h
CHANGED
@@ -11,11 +11,10 @@
|
|
11
11
|
#include <limits.h>
|
12
12
|
#include <assert.h>
|
13
13
|
#include <typeinfo>
|
14
|
-
#include <
|
15
|
-
#include <boost/type_traits.hpp>
|
16
|
-
#include <boost/utility/enable_if.hpp>
|
14
|
+
#include <type_traits>
|
17
15
|
#include <xot/defs.h>
|
18
16
|
#include <xot/exception.h>
|
17
|
+
#include <xot/noncopyable.h>
|
19
18
|
#include <xot/debug.h>
|
20
19
|
|
21
20
|
|
@@ -30,38 +29,39 @@ namespace Xot
|
|
30
29
|
|
31
30
|
|
32
31
|
template <typename SuperClass = EmptyClass>
|
33
|
-
class RefCountable : public SuperClass, public
|
32
|
+
class RefCountable : public SuperClass, public NonCopyable
|
34
33
|
{
|
35
34
|
|
36
35
|
public:
|
37
36
|
|
38
|
-
virtual void retain (
|
37
|
+
virtual void retain (intptr_t data = 0) const
|
39
38
|
{
|
40
|
-
refc_update_count(
|
39
|
+
refc_update_count(true);
|
41
40
|
|
42
41
|
#ifdef XOT_REF_DEBUG
|
43
42
|
doutln(
|
44
43
|
"%s: %d -> %d",
|
45
|
-
typeid(this).name(), refc_count
|
44
|
+
typeid(this).name(), refc_count - 1, refc_count);
|
46
45
|
#endif
|
47
46
|
}
|
48
47
|
|
49
|
-
virtual void release (
|
48
|
+
virtual void release (intptr_t data = 0) const
|
50
49
|
{
|
51
|
-
assert(refc_count
|
52
|
-
|
50
|
+
assert(refc_count >= 0);
|
51
|
+
|
52
|
+
bool del = refc_count == 0 || refc_update_count(false) == 0;
|
53
53
|
|
54
54
|
#ifdef XOT_REF_DEBUG
|
55
55
|
doutln(
|
56
|
-
"%s: %d -> %d,
|
57
|
-
typeid(this).name(), refc_count
|
58
|
-
|
56
|
+
"%s: %d -> %d, delete:%s",
|
57
|
+
typeid(this).name(), refc_count + 1, refc_count,
|
58
|
+
del ? "yes" : "no");
|
59
59
|
#endif
|
60
60
|
|
61
61
|
if (del) delete this;
|
62
62
|
}
|
63
63
|
|
64
|
-
virtual void*
|
64
|
+
virtual void* rucy_wrapper_value () const
|
65
65
|
{
|
66
66
|
return NULL;
|
67
67
|
}
|
@@ -81,54 +81,21 @@ namespace Xot
|
|
81
81
|
{
|
82
82
|
}
|
83
83
|
|
84
|
-
|
85
|
-
{
|
86
|
-
return refc.count;
|
87
|
-
}
|
84
|
+
private:
|
88
85
|
|
89
|
-
|
90
|
-
{
|
91
|
-
return refc.aux & 0x1;
|
92
|
-
}
|
86
|
+
mutable int refc_count = 0;
|
93
87
|
|
94
|
-
|
88
|
+
int refc_update_count (bool increment) const
|
95
89
|
{
|
96
|
-
|
97
|
-
if (add >= 0) refc.aux |= 0x1;// bit for retained flag.
|
98
|
-
|
99
|
-
int c = refc.count + add;
|
90
|
+
int c = refc_count + (increment ? +1 : -1);
|
100
91
|
if (c < 0)
|
101
|
-
invalid_state_error(__FILE__, __LINE__);
|
102
|
-
if (c >
|
103
|
-
xot_error(__FILE__, __LINE__, "
|
92
|
+
invalid_state_error(__FILE__, __LINE__, "refc_count underflow");
|
93
|
+
if (c > INT_MAX)
|
94
|
+
xot_error(__FILE__, __LINE__, "refc_count overflow.");
|
104
95
|
|
105
|
-
return
|
96
|
+
return refc_count = c;
|
106
97
|
}
|
107
98
|
|
108
|
-
virtual ushort refc_aux () const
|
109
|
-
{
|
110
|
-
return refc.aux >> 1;
|
111
|
-
}
|
112
|
-
|
113
|
-
virtual void refc_set_aux (ushort aux) const
|
114
|
-
{
|
115
|
-
if ((0x1 << 15) & aux)
|
116
|
-
argument_error(__FILE__, __LINE__);
|
117
|
-
|
118
|
-
refc.aux = (refc.aux & 0x1) | (aux << 1);
|
119
|
-
}
|
120
|
-
|
121
|
-
private:
|
122
|
-
|
123
|
-
mutable struct Data
|
124
|
-
{
|
125
|
-
|
126
|
-
ushort count, aux;
|
127
|
-
|
128
|
-
Data () : count(0), aux(0) {}
|
129
|
-
|
130
|
-
} refc;
|
131
|
-
|
132
99
|
};// RefCountable
|
133
100
|
|
134
101
|
|
@@ -232,14 +199,14 @@ namespace Xot
|
|
232
199
|
|
233
200
|
|
234
201
|
template <typename T>
|
235
|
-
class Ref<T, typename
|
202
|
+
class Ref<T, typename std::enable_if<std::is_const<T>::value>::type>
|
236
203
|
{
|
237
204
|
|
238
205
|
typedef Ref<T> This;
|
239
206
|
|
240
|
-
typedef typename
|
207
|
+
typedef typename std::remove_const<T>::type Value;
|
241
208
|
|
242
|
-
typedef
|
209
|
+
typedef T ConstValue;
|
243
210
|
|
244
211
|
typedef Value& Reference;
|
245
212
|
|