xot 0.1.12 → 0.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 917b9cdb102ebbcb2b9b78eee59fa4e746edb124
4
- data.tar.gz: b76b933faf98ddaeeac34ae81d8954f75b0ed710
2
+ SHA256:
3
+ metadata.gz: 88efd5d3701a109d4d84b73ca708534afd4b241b65e346a7713b7432c4448375
4
+ data.tar.gz: 7e34ffbf480f514bd89288861adfe607250c370bb6f39a9a6f269ffec1a9fadf
5
5
  SHA512:
6
- metadata.gz: 5f5a99b2dcef89976face14279f8ad0089ce8af434a92f3849dc0ed710563e6245cd03a7388020496a65421c9fb3254a324c2f0a420d6df63e8e254185473afb
7
- data.tar.gz: 56390fe7523401d8608145374c39174969a6be7f4b8943accd9186ae8842641962d6ca241aca3c0db9fccb6a35ab05b948685b85e44bc35bb9993403417dd24d
6
+ metadata.gz: 0c966eca380aa4d048f3f97a522e6b26b4b7bcf26b63f35f1a68ed3fa1e6d9fc075360004bbdfe338c7d2f57cf5b6b35be0ac76b7ed27d8beb20c38b6143b9ab
7
+ data.tar.gz: 2626967aa53d9f1493a132bba2bdb18ae0b7ea67a4991351941c60116e6a27460ad07e8b4be560f32063c546a44ee004e3552ab2a740c6e0e358558951fc3abf
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,19 @@
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
9
  require 'xot/module'
10
10
 
11
- include Xot::Rake
12
11
 
13
-
14
- MODULES = [Xot].map {|m| m.const_get :Module}
15
- MODULE = MODULES.last
12
+ MODULES = [Xot]
16
13
  DLNAME = 'tester'
17
14
 
15
+ build_native_library
16
+ build_ruby_extension dlname: :tester
17
+ test_ruby_extension
18
+ build_ruby_gem
18
19
 
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}
20
+ task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
@@ -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
@@ -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