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 +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
data/src/time.cpp
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
#include "xot/time.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include <
|
4
|
+
#include <chrono>
|
5
|
+
#include <thread>
|
5
6
|
|
6
|
-
|
7
|
+
|
8
|
+
namespace Ch = std::chrono;
|
7
9
|
|
8
10
|
|
9
11
|
namespace Xot
|
@@ -11,13 +13,19 @@ namespace Xot
|
|
11
13
|
|
12
14
|
|
13
15
|
double
|
14
|
-
time (
|
16
|
+
time ()
|
15
17
|
{
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
auto now = Ch::system_clock::now().time_since_epoch();
|
19
|
+
return Ch::duration_cast<Ch::milliseconds>(now).count() / 1000.0;
|
20
|
+
}
|
21
|
+
|
22
|
+
void
|
23
|
+
sleep (double seconds)
|
24
|
+
{
|
25
|
+
if (seconds <= 0) return;
|
26
|
+
|
27
|
+
long long millisecs = seconds * 1000;
|
28
|
+
std::this_thread::sleep_for(Ch::milliseconds(millisecs));
|
21
29
|
}
|
22
30
|
|
23
31
|
|
data/test/test_bit_flag.rb
CHANGED
@@ -6,9 +6,7 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestBitFlag < Test::Unit::TestCase
|
8
8
|
|
9
|
-
|
10
|
-
Xot::BitFlag.bit *args
|
11
|
-
end
|
9
|
+
include Xot::BitUtil
|
12
10
|
|
13
11
|
def flag (*args, &block)
|
14
12
|
bf = Xot::BitFlag.new *args, &block
|
@@ -20,13 +18,6 @@ class TestBitFlag < Test::Unit::TestCase
|
|
20
18
|
bf
|
21
19
|
end
|
22
20
|
|
23
|
-
def test_bit ()
|
24
|
-
assert_equal 0b1, bit(0)
|
25
|
-
assert_equal 0b10, bit(1)
|
26
|
-
assert_equal 0b1000, bit(3)
|
27
|
-
assert_equal 0b1010, bit(1, 3)
|
28
|
-
end
|
29
|
-
|
30
21
|
def test_bits2symbols ()
|
31
22
|
assert_equal [], flag.bits2symbols(0)
|
32
23
|
assert_equal [:bit1], flag.bits2symbols(bit 1)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestBitFlagAccessor < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include Xot::BitUtil
|
10
|
+
|
11
|
+
class IntAccessor
|
12
|
+
attr_accessor :bits
|
13
|
+
alias set bits=
|
14
|
+
alias get bits
|
15
|
+
def initialize (&block)
|
16
|
+
@bits = 0
|
17
|
+
block.call self if block
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class SymbolAccessor < IntAccessor
|
22
|
+
bit_flag_accessor :bits do
|
23
|
+
flag :bit0, bit: 0
|
24
|
+
flag :bit1, bit: 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def int (&block)
|
29
|
+
IntAccessor.new &block
|
30
|
+
end
|
31
|
+
|
32
|
+
def symbol (&block)
|
33
|
+
SymbolAccessor.new &block
|
34
|
+
end
|
35
|
+
|
36
|
+
def flag ()
|
37
|
+
SymbolAccessor.bits_flag
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_int_accessor ()
|
41
|
+
assert_equal 0b0, int.get
|
42
|
+
assert_equal 0b1, int{|o| o.bits = bit 0}.get
|
43
|
+
assert_equal 0b10, int{|o| o.bits = bit 1}.get
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_symbol_writer ()
|
47
|
+
assert_equal 0b0, symbol.get
|
48
|
+
assert_equal 0b1, symbol{|o| o.bits = :bit0}.get
|
49
|
+
assert_equal 0b10, symbol{|o| o.bits = :bit1}.get
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_symbol_reader ()
|
53
|
+
assert_equal [], symbol.bits
|
54
|
+
assert_equal [:bit0], symbol{|o| o.set bit 0}.bits
|
55
|
+
assert_equal [:bit1], symbol{|o| o.set bit 1}.bits
|
56
|
+
assert_equal [:bit0, :bit1], symbol{|o| o.set bit 0, 1}.bits
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_singleton_flag_reader ()
|
60
|
+
assert_equal 0b11, flag.symbols2bits(:bit0, :bit1)
|
61
|
+
assert_equal [:bit0, :bit1], flag.bits2symbols(0b11)
|
62
|
+
end
|
63
|
+
|
64
|
+
end# TestBitFlagAccessor
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestBitUtil < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include Xot::BitUtil
|
10
|
+
|
11
|
+
def test_bit ()
|
12
|
+
assert_equal 0b1, bit(0)
|
13
|
+
assert_equal 0b10, bit(1)
|
14
|
+
assert_equal 0b1000, bit(3)
|
15
|
+
assert_equal 0b1010, bit(1, 3)
|
16
|
+
end
|
17
|
+
|
18
|
+
end# TestBitFlag
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestConstSymbolAccessor < Test::Unit::TestCase
|
8
|
+
|
9
|
+
Unknown = -1
|
10
|
+
Const0 = 0
|
11
|
+
Const1 = 1
|
12
|
+
|
13
|
+
class ConstAccessor
|
14
|
+
attr_accessor :const
|
15
|
+
alias set const=
|
16
|
+
alias get const
|
17
|
+
def initialize (&block)
|
18
|
+
@const = Const0
|
19
|
+
block.call self if block
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class SymbolAccessor < ConstAccessor
|
24
|
+
const_symbol_accessor :const, {
|
25
|
+
const0: Const0,
|
26
|
+
const1: Const1
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def const (&block)
|
31
|
+
ConstAccessor.new &block
|
32
|
+
end
|
33
|
+
|
34
|
+
def symbol (&block)
|
35
|
+
SymbolAccessor.new &block
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_const_accessor ()
|
39
|
+
assert_equal Const0, const.get
|
40
|
+
assert_equal Const1, const{|o| o.const = Const1}.get
|
41
|
+
assert_nothing_raised {const.const = Unknown}
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_symbol_writer ()
|
45
|
+
assert_equal Const0, symbol.get
|
46
|
+
assert_equal Const1, symbol{|o| o.const = :const1}.get
|
47
|
+
assert_raise(ArgumentError) {symbol.const = :unknown}
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_symbol_reader ()
|
51
|
+
assert_equal :const0, symbol.const
|
52
|
+
assert_equal :const1, symbol{|o| o.set Const1}.const
|
53
|
+
assert_raise(RuntimeError) {symbol{|o| o.set Unknown}.const}
|
54
|
+
end
|
55
|
+
|
56
|
+
end# TestBitFlagAccessor
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestUniversalAccessor < Test::Unit::TestCase
|
8
|
+
|
9
|
+
class Accessor
|
10
|
+
|
11
|
+
attr_accessor :val
|
12
|
+
|
13
|
+
attr_reader :args
|
14
|
+
|
15
|
+
def args= (*args)
|
16
|
+
@args = args
|
17
|
+
end
|
18
|
+
|
19
|
+
universal_accessor :val, :args
|
20
|
+
|
21
|
+
end# Accessor
|
22
|
+
|
23
|
+
def accessor (*args)
|
24
|
+
Accessor.new *args
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_accessor ()
|
28
|
+
a = accessor
|
29
|
+
assert_equal nil, a.val
|
30
|
+
|
31
|
+
a.val 1
|
32
|
+
assert_equal 1, a.val
|
33
|
+
assert_equal 2, a.val(2)
|
34
|
+
|
35
|
+
a.val = 3
|
36
|
+
assert_equal 3, a.val
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_accessor_splat_args ()
|
40
|
+
a = accessor
|
41
|
+
|
42
|
+
a.args = 1, 2, 3; assert_equal [[1, 2, 3]], a.args
|
43
|
+
a.args = [1, 2, 3]; assert_equal [[1, 2, 3]], a.args
|
44
|
+
a.args = *[1, 2, 3]; assert_equal [[1, 2, 3]], a.args
|
45
|
+
|
46
|
+
assert_equal [1, 2, 3], a.args( 1, 2, 3)
|
47
|
+
assert_equal [[1, 2, 3]], a.args( [1, 2, 3])
|
48
|
+
assert_equal [1, 2, 3], a.args(*[1, 2, 3])
|
49
|
+
end
|
50
|
+
|
51
|
+
end# TestUniversalAccessor
|
data/xot.gemspec
CHANGED
@@ -21,15 +21,12 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.description = 'This library include some useful utility classes and functions for development with C++.'
|
22
22
|
s.version = mod.version
|
23
23
|
|
24
|
-
s.authors = %w[
|
25
|
-
s.email = '
|
24
|
+
s.authors = %w[xordog]
|
25
|
+
s.email = 'xordog@gmail.com'
|
26
26
|
s.homepage = "https://github.com/xord/xot"
|
27
27
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
|
-
s.required_ruby_version = '
|
30
|
-
|
31
|
-
s.add_runtime_dependency 'rake'
|
32
|
-
s.add_development_dependency 'gemcutter'
|
29
|
+
s.required_ruby_version = '~> 2'
|
33
30
|
|
34
31
|
s.files = `git ls-files`.split $/
|
35
32
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
metadata
CHANGED
@@ -1,51 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- xordog
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: gemcutter
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
11
|
+
date: 2020-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
41
13
|
description: This library include some useful utility classes and functions for development
|
42
14
|
with C++.
|
43
|
-
email:
|
15
|
+
email: xordog@gmail.com
|
44
16
|
executables: []
|
45
17
|
extensions:
|
46
18
|
- Rakefile
|
47
19
|
extra_rdoc_files: []
|
48
20
|
files:
|
21
|
+
- LICENSE
|
49
22
|
- README.md
|
50
23
|
- Rakefile
|
51
24
|
- VERSION
|
@@ -55,6 +28,7 @@ files:
|
|
55
28
|
- include/xot/debug.h
|
56
29
|
- include/xot/defs.h
|
57
30
|
- include/xot/exception.h
|
31
|
+
- include/xot/noncopyable.h
|
58
32
|
- include/xot/pimpl.h
|
59
33
|
- include/xot/ref.h
|
60
34
|
- include/xot/string.h
|
@@ -62,62 +36,71 @@ files:
|
|
62
36
|
- include/xot/util.h
|
63
37
|
- lib/xot.rb
|
64
38
|
- lib/xot/bit_flag.rb
|
39
|
+
- lib/xot/bit_flag_accessor.rb
|
40
|
+
- lib/xot/bit_util.rb
|
65
41
|
- lib/xot/block_util.rb
|
42
|
+
- lib/xot/const_symbol_accessor.rb
|
66
43
|
- lib/xot/extconf.rb
|
67
44
|
- lib/xot/hookable.rb
|
68
45
|
- lib/xot/invoker.rb
|
69
46
|
- lib/xot/module.rb
|
70
47
|
- lib/xot/rake.rb
|
48
|
+
- lib/xot/rake/alias_task.rb
|
49
|
+
- lib/xot/rake/escalation.rb
|
50
|
+
- lib/xot/rake/util.rb
|
71
51
|
- lib/xot/setter.rb
|
72
52
|
- lib/xot/test.rb
|
53
|
+
- lib/xot/universal_accessor.rb
|
73
54
|
- src/debug.cpp
|
74
55
|
- src/exception.cpp
|
75
56
|
- src/string.cpp
|
76
57
|
- src/time.cpp
|
77
58
|
- src/util.cpp
|
78
|
-
- task/ext.rake
|
79
|
-
- task/gem.rake
|
80
|
-
- task/lib.rake
|
81
|
-
- task/mac.rake
|
82
|
-
- task/test.rake
|
83
59
|
- test/helper.rb
|
84
60
|
- test/test_bit_flag.rb
|
61
|
+
- test/test_bit_flag_accessor.rb
|
62
|
+
- test/test_bit_util.rb
|
85
63
|
- test/test_block_util.rb
|
64
|
+
- test/test_const_symbol_accessor.rb
|
86
65
|
- test/test_hookable.rb
|
87
66
|
- test/test_invoker.rb
|
88
67
|
- test/test_rake.rb
|
89
68
|
- test/test_setter.rb
|
90
69
|
- test/test_tester.rb
|
70
|
+
- test/test_universal_accessor.rb
|
91
71
|
- xot.gemspec
|
92
72
|
homepage: https://github.com/xord/xot
|
93
73
|
licenses: []
|
94
74
|
metadata: {}
|
95
|
-
post_install_message:
|
75
|
+
post_install_message:
|
96
76
|
rdoc_options: []
|
97
77
|
require_paths:
|
98
78
|
- lib
|
99
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
80
|
requirements:
|
101
|
-
- - "
|
81
|
+
- - "~>"
|
102
82
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
83
|
+
version: '2'
|
104
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
85
|
requirements:
|
106
86
|
- - ">="
|
107
87
|
- !ruby/object:Gem::Version
|
108
88
|
version: '0'
|
109
89
|
requirements: []
|
110
|
-
|
111
|
-
|
112
|
-
signing_key:
|
90
|
+
rubygems_version: 3.0.3
|
91
|
+
signing_key:
|
113
92
|
specification_version: 4
|
114
93
|
summary: A Utility library for C++ developemt.
|
115
94
|
test_files:
|
116
95
|
- test/helper.rb
|
117
96
|
- test/test_bit_flag.rb
|
97
|
+
- test/test_bit_flag_accessor.rb
|
98
|
+
- test/test_bit_util.rb
|
118
99
|
- test/test_block_util.rb
|
100
|
+
- test/test_const_symbol_accessor.rb
|
119
101
|
- test/test_hookable.rb
|
120
102
|
- test/test_invoker.rb
|
121
103
|
- test/test_rake.rb
|
122
104
|
- test/test_setter.rb
|
123
105
|
- test/test_tester.rb
|
106
|
+
- test/test_universal_accessor.rb
|
data/task/ext.rake
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
-
|
3
|
-
|
4
|
-
require 'rbconfig'
|
5
|
-
|
6
|
-
|
7
|
-
task :ext => 'ext:build'
|
8
|
-
|
9
|
-
%w[clean].each do |t|
|
10
|
-
task t.intern => "ext:#{t}"
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
namespace :ext do
|
15
|
-
|
16
|
-
|
17
|
-
rbconf = RbConfig::CONFIG
|
18
|
-
|
19
|
-
mod = MODULE
|
20
|
-
mods = env :MODULES, [], :array
|
21
|
-
modname = env :MODNAME, mod.name.downcase
|
22
|
-
dlname = env :DLNAME, 'native'
|
23
|
-
dlext = env :DLEXT, rbconf['DLEXT'] || 'so'
|
24
|
-
extdir = env :EXTDIR, "ext/#{modname}"
|
25
|
-
libdir = env :LIBDIR, "lib/#{modname}"
|
26
|
-
ruby = env :RUBY, 'ruby'
|
27
|
-
make = env :MAKE, 'make'
|
28
|
-
cxx = env :CXX, rbconf['CXX'] || 'g++'
|
29
|
-
cppflags = env :CPPFLAGS, rbconf['CPPFLAGS']
|
30
|
-
cxxflags = env :CXXFLAGS, rbconf['CXXFLAGS']
|
31
|
-
defs = env :DEFS, [], :array
|
32
|
-
incdirs = env(:INCDIRS, [], :array) + mods.reverse.map {|m| m.include_dir}
|
33
|
-
|
34
|
-
cppflags = cppflags cppflags, defs, incdirs
|
35
|
-
cxxflags = cflags cxxflags
|
36
|
-
|
37
|
-
outname = "#{dlname}.#{dlext}"
|
38
|
-
extout = File.join extdir, outname
|
39
|
-
libout = File.join libdir, outname
|
40
|
-
|
41
|
-
srcs = FileList["#{extdir}/**/*.cpp"]
|
42
|
-
libs = FileList["#{libdir}/../lib*.a"]
|
43
|
-
|
44
|
-
extconf = File.join extdir, 'extconf.rb'
|
45
|
-
makefile = File.join extdir, 'Makefile'
|
46
|
-
depend = File.join extdir, 'depend.mf'
|
47
|
-
|
48
|
-
|
49
|
-
task :build => libout
|
50
|
-
|
51
|
-
task :clean do
|
52
|
-
sh %( cd #{extdir} && #{make} clean ) if File.exist? makefile
|
53
|
-
sh %( rm -rf #{makefile} #{depend} #{libout} )
|
54
|
-
end
|
55
|
-
|
56
|
-
file libout => extout do
|
57
|
-
sh %( cp #{extout} #{libout} )
|
58
|
-
end
|
59
|
-
|
60
|
-
file extout => [:lib, makefile] do
|
61
|
-
sh %( cd #{extdir} && #{make} )
|
62
|
-
end
|
63
|
-
|
64
|
-
file makefile => [extconf, depend] + libs do
|
65
|
-
sh %( cd #{extdir} && #{ruby} #{File.basename extconf} )
|
66
|
-
end
|
67
|
-
|
68
|
-
file depend => srcs do
|
69
|
-
inc = incdirs.map {|s| " -I#{s}"}.join
|
70
|
-
src = srcs.map {|cpp| File.basename cpp}.join ' '
|
71
|
-
dep = File.basename depend
|
72
|
-
sh %( cd #{extdir} && #{cxx} -M #{cppflags} #{inc} #{src} > #{dep} )
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
end# :ext
|