xot 0.1.12 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,8 @@
2
2
 
3
3
 
4
4
  #include <stdio.h>
5
- #include <boost/scoped_array.hpp>
5
+ #include <algorithm>
6
+ #include <memory>
6
7
 
7
8
 
8
9
  namespace Xot
@@ -18,6 +19,36 @@ namespace Xot
18
19
  {
19
20
  }
20
21
 
22
+ String
23
+ String::upcase () const
24
+ {
25
+ String s = c_str();
26
+ std::transform(
27
+ s.begin(), s.end(), s.begin(),
28
+ [](int c) {return toupper(c);});
29
+ return s;
30
+ }
31
+
32
+ String
33
+ String::downcase () const
34
+ {
35
+ String s = c_str();
36
+ std::transform(
37
+ s.begin(), s.end(), s.begin(),
38
+ [](int c) {return tolower(c);});
39
+ return s;
40
+ }
41
+
42
+ String
43
+ String::strip () const
44
+ {
45
+ String s = c_str();
46
+ auto isspace = [](int c) {return std::isspace(c);};
47
+ auto head = std::find_if_not(s.begin(), s.end(), isspace);
48
+ auto tail = std::find_if( head, s.end(), isspace);
49
+ return String(head, tail);
50
+ }
51
+
21
52
  String::operator const char* () const
22
53
  {
23
54
  return c_str();
@@ -67,7 +98,7 @@ namespace Xot
67
98
  return &stack[0];
68
99
 
69
100
  int bufsize = BUFSIZE;// vscprintf(format, args);
70
- boost::scoped_array<char> heap;
101
+ std::unique_ptr<char[]> heap;
71
102
  while (true)
72
103
  {
73
104
  bufsize *= 2;
@@ -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,51 +1,24 @@
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.19
5
5
  platform: ruby
6
6
  authors:
7
- - snori
8
- autorequire:
7
+ - xordog
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: 2020-12-10 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
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: 1.9.0
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
- rubyforge_project:
111
- rubygems_version: 2.0.3
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