xot 0.1.11 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 72b3519f57041623e24f6d9addaf4053720f695d
4
- data.tar.gz: 7a3215a899ada49f8d22fe1100a1fe941f9c0875
2
+ SHA256:
3
+ metadata.gz: 0e6a18a9ea642c4ac20d70096dddf5eadf89e6de95b093940402e5cefa746be3
4
+ data.tar.gz: b2118e8a68ca94e770ae1ef26f9f60a26f77ccf04e2fc7ba28b7fc89f4da1aa8
5
5
  SHA512:
6
- metadata.gz: cd63c1d4fdbdc5df82b8f10d279efd371cc00219c9c5cfd10cbfd51238023cbfde1c7f1f941d21d73c668492cf8c83bf513c5cb57305d562297ff59c623f261f
7
- data.tar.gz: 7d5a161027335a059db6de4ef00415b5bf859485ef0fa24c42d293564d6f2d66269e2fcb528bdbf5fb8a05c692760a9a2ff7a050e2c2707a31a1235ec96ad952
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
@@ -1,4 +1,4 @@
1
1
 
2
2
  # Xot - Some useful utility classes and functions.
3
3
 
4
- by snori@xord.org
4
+ by xordog@gmail.com
data/Rakefile CHANGED
@@ -2,25 +2,20 @@
2
2
 
3
3
 
4
4
  %w[.]
5
- .map {|s| File.expand_path "../#{s}/lib", __FILE__}
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
- include Xot::Rake
10
+ require 'xot/module'
12
11
 
13
12
 
14
- MODULES = [Xot].map {|m| m.const_get :Module}
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 => :build
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.11
1
+ 0.1.16
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  %w[.]
5
- .map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
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 << 'boost/noncopyable.hpp' << 'ruby.h'
15
+ headers << 'ruby.h'
16
16
  end
17
17
 
18
- dir_config 'boost'
19
18
  create_makefile 'xot/tester'
20
19
  end
@@ -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 = Xot::set_pointer_flag(p);
124
+ p = Xot::set_pointer_flag(p);
79
125
  if (!(Xot::get_pointer_flag(p) == true)) return false;
80
126
 
81
- p = Xot::set_pointer_flag(p, false);
127
+ p = Xot::set_pointer_flag(p, false);
82
128
  if (!(Xot::get_pointer_flag(p) == false)) return false;
83
129
 
84
- p = Xot::set_pointer_flag(p, true);
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)) return false;
88
- if (!(Xot::set_pointer_flag(p, false) == &value)) return false;
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()) return false;
99
- if (!test_util()) return false;
146
+ if (!test_ref()) return false;
147
+ if (!test_util()) return false;
100
148
  return true;
101
149
  }
102
150
 
@@ -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/time.h>
15
+ #include <xot/noncopyable.h>
13
16
  #include <xot/util.h>
14
- #include <xot/debug.h>
15
17
 
16
18
 
17
19
  #endif//EOH
@@ -4,11 +4,16 @@
4
4
  #define __XOT_DEBUG_H__
5
5
 
6
6
 
7
+ #if 1//def _DEBUG
8
+ #define XOT_USE_DOUT
9
+ #endif
10
+
11
+
7
12
  namespace Xot
8
13
  {
9
14
 
10
15
 
11
- #ifdef _DEBUG
16
+ #ifdef XOT_USE_DOUT
12
17
 
13
18
  void dout (const char* format, ...);
14
19
 
@@ -26,6 +26,8 @@ namespace Xot
26
26
  {
27
27
 
28
28
 
29
+ typedef signed char schar;
30
+
29
31
  typedef unsigned char uchar;
30
32
 
31
33
  #ifdef CYGWIN
@@ -52,9 +54,6 @@ namespace Xot
52
54
  }// Types
53
55
 
54
56
 
55
- enum {UNKNOWN = 0};
56
-
57
-
58
57
  using namespace Types;
59
58
 
60
59
 
@@ -46,17 +46,29 @@ namespace Xot
46
46
  namespace ErrorFunctions
47
47
  {
48
48
 
49
- void xot_error (const char* file, int line, const char* format = NULL, ...);
49
+ [[noreturn]]
50
+ void xot_error (
51
+ const char* file, int line, const char* format = NULL, ...);
50
52
 
51
- void argument_error (const char* file, int line, const char* format = NULL, ...);
53
+ [[noreturn]]
54
+ void argument_error (
55
+ const char* file, int line, const char* format = NULL, ...);
52
56
 
53
- void index_error (const char* file, int line, const char* format = NULL, ...);
57
+ [[noreturn]]
58
+ void index_error (
59
+ const char* file, int line, const char* format = NULL, ...);
54
60
 
55
- void invalid_state_error (const char* file, int line, const char* format = NULL, ...);
61
+ [[noreturn]]
62
+ void invalid_state_error (
63
+ const char* file, int line, const char* format = NULL, ...);
56
64
 
57
- void system_error (const char* file, int line, const char* format = NULL, ...);
65
+ [[noreturn]]
66
+ void system_error (
67
+ const char* file, int line, const char* format = NULL, ...);
58
68
 
59
- void not_implemented_error (const char* file, int line, const char* format = NULL, ...);
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
@@ -4,24 +4,20 @@
4
4
  #define __XOT_PIMPL_H__
5
5
 
6
6
 
7
- #include <boost/scoped_ptr.hpp>
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<T, false> : public boost::scoped_ptr<T>
15
+ class PImpl : public std::unique_ptr<T>
20
16
  {
21
17
 
22
- typedef boost::scoped_ptr<T> Super;
18
+ typedef std::unique_ptr<T> Super;
23
19
 
24
- typedef PImpl<T, false> This;
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 PImpl<T, true> : public boost::shared_ptr<T>
40
+ class PSharedImpl : public std::shared_ptr<T>
47
41
  {
48
42
 
49
- typedef boost::shared_ptr<T> Super;
43
+ typedef std::shared_ptr<T> Super;
50
44
 
51
- typedef PImpl<T, true> This;
45
+ typedef PImpl<T> This;
52
46
 
53
47
  public:
54
48
 
55
- PImpl () : Super(new T) {}
49
+ PSharedImpl () : Super(new T) {}
56
50
 
57
- PImpl (T* p) : Super(p) {}
58
-
59
- bool shared () const {return true;}
51
+ PSharedImpl (T* p) : Super(p) {}
60
52
 
61
- };// PImpl
53
+ };// PSharedImpl
62
54
 
63
55
 
64
56
  }// Xot
@@ -11,11 +11,10 @@
11
11
  #include <limits.h>
12
12
  #include <assert.h>
13
13
  #include <typeinfo>
14
- #include <boost/noncopyable.hpp>
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 boost::noncopyable
32
+ class RefCountable : public SuperClass, public NonCopyable
34
33
  {
35
34
 
36
35
  public:
37
36
 
38
- virtual void retain (void* data = NULL) const
37
+ virtual void retain (intptr_t data = 0) const
39
38
  {
40
- refc_update_count(+1);
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() - 1, refc_count());
44
+ typeid(this).name(), refc_count - 1, refc_count);
46
45
  #endif
47
46
  }
48
47
 
49
- virtual void release (void* data = NULL) const
48
+ virtual void release (intptr_t data = 0) const
50
49
  {
51
- assert(refc_count() >= 0);
52
- bool del = !refc_retained() || refc_update_count(-1) == 0;
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, refcount:%s, delete:%s",
57
- typeid(this).name(), refc_count() + 1, refc_count(),
58
- refc_retained() ? "yes" : "no", del ? "yes" : "no");
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* rucy_value () const
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
- virtual int refc_count () const
85
- {
86
- return refc.count;
87
- }
84
+ private:
88
85
 
89
- virtual bool refc_retained () const
90
- {
91
- return refc.aux & 0x1;
92
- }
86
+ mutable int refc_count = 0;
93
87
 
94
- virtual int refc_update_count (int add) const
88
+ int refc_update_count (bool increment) const
95
89
  {
96
- assert(add != 0);
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 > USHRT_MAX)
103
- xot_error(__FILE__, __LINE__, "refc.count overflow.");
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 refc.count = c;
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 boost::enable_if<boost::is_const<T> >::type>
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 boost::remove_const<T>::type Value;
207
+ typedef typename std::remove_const<T>::type Value;
241
208
 
242
- typedef T ConstValue;
209
+ typedef T ConstValue;
243
210
 
244
211
  typedef Value& Reference;
245
212