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.
@@ -1,9 +1,11 @@
1
1
  #include "xot/time.h"
2
2
 
3
3
 
4
- #include <boost/date_time/posix_time/posix_time.hpp>
4
+ #include <chrono>
5
+ #include <thread>
5
6
 
6
- namespace pt = boost::posix_time;
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 (bool local)
16
+ time ()
15
17
  {
16
- static pt::ptime zero = pt::from_time_t(0);
17
- pt::ptime now = local ?
18
- pt::microsec_clock::local_time() :
19
- pt::microsec_clock::universal_time();
20
- return (now - zero).total_milliseconds() / 1000.0;
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
 
@@ -6,9 +6,7 @@ require_relative 'helper'
6
6
 
7
7
  class TestBitFlag < Test::Unit::TestCase
8
8
 
9
- def bit (*args)
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
@@ -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[snori]
25
- s.email = 'snori@xord.org'
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 = '>=1.9.0'
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,46 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
- - snori
7
+ - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
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: 2019-11-23 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: snori@xord.org
15
+ email: xordog@gmail.com
44
16
  executables: []
45
17
  extensions:
46
18
  - Rakefile
@@ -55,6 +27,7 @@ files:
55
27
  - include/xot/debug.h
56
28
  - include/xot/defs.h
57
29
  - include/xot/exception.h
30
+ - include/xot/noncopyable.h
58
31
  - include/xot/pimpl.h
59
32
  - include/xot/ref.h
60
33
  - include/xot/string.h
@@ -62,32 +35,38 @@ files:
62
35
  - include/xot/util.h
63
36
  - lib/xot.rb
64
37
  - lib/xot/bit_flag.rb
38
+ - lib/xot/bit_flag_accessor.rb
39
+ - lib/xot/bit_util.rb
65
40
  - lib/xot/block_util.rb
41
+ - lib/xot/const_symbol_accessor.rb
66
42
  - lib/xot/extconf.rb
67
43
  - lib/xot/hookable.rb
68
44
  - lib/xot/invoker.rb
69
45
  - lib/xot/module.rb
70
46
  - lib/xot/rake.rb
47
+ - lib/xot/rake/alias_task.rb
48
+ - lib/xot/rake/escalation.rb
49
+ - lib/xot/rake/util.rb
71
50
  - lib/xot/setter.rb
72
51
  - lib/xot/test.rb
52
+ - lib/xot/universal_accessor.rb
73
53
  - src/debug.cpp
74
54
  - src/exception.cpp
75
55
  - src/string.cpp
76
56
  - src/time.cpp
77
57
  - src/util.cpp
78
- - task/ext.rake
79
- - task/gem.rake
80
- - task/lib.rake
81
- - task/mac.rake
82
- - task/test.rake
83
58
  - test/helper.rb
84
59
  - test/test_bit_flag.rb
60
+ - test/test_bit_flag_accessor.rb
61
+ - test/test_bit_util.rb
85
62
  - test/test_block_util.rb
63
+ - test/test_const_symbol_accessor.rb
86
64
  - test/test_hookable.rb
87
65
  - test/test_invoker.rb
88
66
  - test/test_rake.rb
89
67
  - test/test_setter.rb
90
68
  - test/test_tester.rb
69
+ - test/test_universal_accessor.rb
91
70
  - xot.gemspec
92
71
  homepage: https://github.com/xord/xot
93
72
  licenses: []
@@ -98,26 +77,29 @@ require_paths:
98
77
  - lib
99
78
  required_ruby_version: !ruby/object:Gem::Requirement
100
79
  requirements:
101
- - - ">="
80
+ - - "~>"
102
81
  - !ruby/object:Gem::Version
103
- version: 1.9.0
82
+ version: '2'
104
83
  required_rubygems_version: !ruby/object:Gem::Requirement
105
84
  requirements:
106
85
  - - ">="
107
86
  - !ruby/object:Gem::Version
108
87
  version: '0'
109
88
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.0.3
89
+ rubygems_version: 3.0.3
112
90
  signing_key:
113
91
  specification_version: 4
114
92
  summary: A Utility library for C++ developemt.
115
93
  test_files:
116
94
  - test/helper.rb
117
95
  - test/test_bit_flag.rb
96
+ - test/test_bit_flag_accessor.rb
97
+ - test/test_bit_util.rb
118
98
  - test/test_block_util.rb
99
+ - test/test_const_symbol_accessor.rb
119
100
  - test/test_hookable.rb
120
101
  - test/test_invoker.rb
121
102
  - test/test_rake.rb
122
103
  - test/test_setter.rb
123
104
  - test/test_tester.rb
105
+ - test/test_universal_accessor.rb
@@ -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