xot 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -0
- data/Rakefile +4 -19
- data/VERSION +1 -1
- data/ext/xot/extconf.rb +56 -0
- data/ext/xot/tester.cpp +19 -0
- data/include/xot.h +3 -0
- data/include/xot/debug.h +29 -0
- data/include/xot/defs.h +28 -4
- data/include/xot/pimpl.h +67 -0
- data/include/xot/ref.h +184 -0
- data/include/xot/string.h +15 -0
- data/include/xot/util.h +26 -0
- data/lib/xot.rb +7 -0
- data/lib/xot/blockutil.rb +26 -0
- data/lib/xot/hookable.rb +38 -0
- data/lib/xot/module.rb +9 -2
- data/lib/xot/rake.rb +5 -0
- data/lib/xot/rake/helpers.rb +26 -1
- data/lib/xot/rake/task.rb +20 -0
- data/lib/xot/setter.rb +29 -0
- data/src/debug.cpp +36 -0
- data/src/defs.cpp +6 -0
- data/src/util.cpp +22 -0
- data/task/ext.rake +90 -0
- data/task/gem.rake +11 -8
- data/task/git.rake +5 -0
- data/task/lib.rake +39 -25
- data/task/submodule.rake +51 -0
- data/task/test.rake +35 -0
- data/test/helpers.rb +7 -0
- data/test/test_blockutil.rb +42 -0
- data/test/test_hookable.rb +73 -0
- data/test/test_rake_helpers.rb +35 -0
- data/test/test_setter.rb +42 -0
- data/test/test_tester.rb +13 -0
- data/xot.gemspec +18 -30
- metadata +106 -51
data/include/xot/string.h
CHANGED
@@ -25,4 +25,19 @@ namespace Xot
|
|
25
25
|
}// Xot
|
26
26
|
|
27
27
|
|
28
|
+
#define XOT_STRINGF(format, result) \
|
29
|
+
Xot::String result; \
|
30
|
+
do \
|
31
|
+
{ \
|
32
|
+
if (format) \
|
33
|
+
{ \
|
34
|
+
va_list args; \
|
35
|
+
va_start(args, format); \
|
36
|
+
result = Xot::stringf(format, args); \
|
37
|
+
va_end(args); \
|
38
|
+
} \
|
39
|
+
} \
|
40
|
+
while (false)
|
41
|
+
|
42
|
+
|
28
43
|
#endif//EOH
|
data/include/xot/util.h
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __XOT_UTIL_H__
|
4
|
+
#define __XOT_UTIL_H__
|
5
|
+
|
6
|
+
|
7
|
+
namespace Xot
|
8
|
+
{
|
9
|
+
|
10
|
+
|
11
|
+
int bit2byte (int bits);
|
12
|
+
|
13
|
+
int byte2bit (int bytes);
|
14
|
+
|
15
|
+
|
16
|
+
template <typename T>
|
17
|
+
inline T clip (T minval, T maxval, T value)
|
18
|
+
{
|
19
|
+
return value > maxval ? maxval : (value < minval ? minval : value);
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
}// Xot
|
24
|
+
|
25
|
+
|
26
|
+
#endif//EOH
|
data/lib/xot.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
module Xot
|
5
|
+
|
6
|
+
|
7
|
+
module BlockUtil
|
8
|
+
|
9
|
+
extend module ClassMethods
|
10
|
+
|
11
|
+
def instance_eval_or_block_call (recv, *args, &block)
|
12
|
+
if block.arity == 0
|
13
|
+
recv.instance_eval &block
|
14
|
+
else
|
15
|
+
block.call recv, *args
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
self
|
20
|
+
|
21
|
+
end# ClassMethods
|
22
|
+
|
23
|
+
end# BlockUtil
|
24
|
+
|
25
|
+
|
26
|
+
end# Xot
|
data/lib/xot/hookable.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
module Xot
|
5
|
+
|
6
|
+
|
7
|
+
module Hookable
|
8
|
+
|
9
|
+
def hook (name, &block)
|
10
|
+
c = class << self; self; end
|
11
|
+
c.__send__ :define_method, name, &block
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def on (name, &block)
|
16
|
+
hook name do |*a, &b|
|
17
|
+
block.call *a, &b
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def before (name, &block)
|
22
|
+
hook name do |*a, &b|
|
23
|
+
super *a, &b unless block.call(*a, &b) == :skip
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def after (name, &block)
|
28
|
+
hook name do |*a, &b|
|
29
|
+
ret = super *a, &b
|
30
|
+
block.call *a, &b
|
31
|
+
ret
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end# Hookable
|
36
|
+
|
37
|
+
|
38
|
+
end# Xot
|
data/lib/xot/module.rb
CHANGED
@@ -22,8 +22,15 @@ module Xot
|
|
22
22
|
File.join root_dir, 'task'
|
23
23
|
end
|
24
24
|
|
25
|
-
def load_tasks ()
|
26
|
-
|
25
|
+
def load_tasks (*names)
|
26
|
+
if names.empty?
|
27
|
+
Dir["#{task_dir}/**/*.rake"].each {|path| load path}
|
28
|
+
else
|
29
|
+
names.each do |name|
|
30
|
+
path = "#{task_dir}/#{name}.rake"
|
31
|
+
load path if File.exist? path
|
32
|
+
end
|
33
|
+
end
|
27
34
|
end
|
28
35
|
|
29
36
|
def version ()
|
data/lib/xot/rake.rb
ADDED
data/lib/xot/rake/helpers.rb
CHANGED
@@ -51,17 +51,42 @@ module Xot
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def env (name, defval = nil)
|
54
|
-
|
54
|
+
case val = (ENV[name.to_s] || Object.const_get(name) rescue defval)
|
55
|
+
when /^\d+$/ then val.to_i
|
56
|
+
when 'true' then true
|
57
|
+
when 'false' then false
|
58
|
+
else val
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def header (mod)
|
63
|
+
puts "-- #{mod.to_s.capitalize} " + "-" * 50
|
55
64
|
end
|
56
65
|
|
57
66
|
def win32? ()
|
58
67
|
RUBY_PLATFORM =~ /mswin|ming|cygwin/
|
59
68
|
end
|
60
69
|
|
70
|
+
def mswin? ()
|
71
|
+
RUBY_PLATFORM =~ /mswin/
|
72
|
+
end
|
73
|
+
|
74
|
+
def ming? ()
|
75
|
+
RUBY_PLATFORM =~ /ming/
|
76
|
+
end
|
77
|
+
|
78
|
+
def cygwin? ()
|
79
|
+
RUBY_PLATFORM =~ /cygwin/
|
80
|
+
end
|
81
|
+
|
61
82
|
def cocoa? ()
|
62
83
|
RUBY_PLATFORM =~ /darwin/
|
63
84
|
end
|
64
85
|
|
86
|
+
def clang? ()
|
87
|
+
RbConfig::CONFIG['CXX'] =~ /clang/
|
88
|
+
end
|
89
|
+
|
65
90
|
|
66
91
|
end# Rake
|
67
92
|
|
data/lib/xot/setter.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
module Xot
|
5
|
+
|
6
|
+
|
7
|
+
module Setter
|
8
|
+
|
9
|
+
def set (*args)
|
10
|
+
return if args.empty?
|
11
|
+
|
12
|
+
first = args.shift
|
13
|
+
if first.class == Hash
|
14
|
+
first.each {|name, value| set_value__ name, value}
|
15
|
+
else
|
16
|
+
set_value__ first, *args
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def set_value__ (name, *value)
|
23
|
+
__send__ name.to_s + '=', *value
|
24
|
+
end
|
25
|
+
|
26
|
+
end# Setter
|
27
|
+
|
28
|
+
|
29
|
+
end# Xot
|
data/src/debug.cpp
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#include "xot/debug.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <stdarg.h>
|
6
|
+
#include <xot/string.h>
|
7
|
+
|
8
|
+
|
9
|
+
namespace Xot
|
10
|
+
{
|
11
|
+
|
12
|
+
|
13
|
+
#ifdef _DEBUG
|
14
|
+
|
15
|
+
void
|
16
|
+
dout (const char* format, ...)
|
17
|
+
{
|
18
|
+
va_list args;
|
19
|
+
va_start(args, format);
|
20
|
+
printf("%s", stringf(format, args).c_str());
|
21
|
+
va_end(args);
|
22
|
+
}
|
23
|
+
|
24
|
+
void
|
25
|
+
doutln (const char* format, ...)
|
26
|
+
{
|
27
|
+
va_list args;
|
28
|
+
va_start(args, format);
|
29
|
+
printf("%s\n", stringf(format, args).c_str());
|
30
|
+
va_end(args);
|
31
|
+
}
|
32
|
+
|
33
|
+
#endif
|
34
|
+
|
35
|
+
|
36
|
+
}// Xot
|
data/src/defs.cpp
ADDED
data/src/util.cpp
ADDED
data/task/ext.rake
ADDED
@@ -0,0 +1,90 @@
|
|
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
|
+
modname = env :MODNAME, mod.name.downcase
|
21
|
+
dlname = env :DLNAME, 'native'
|
22
|
+
dlext = env :DLEXT, rbconf['DLEXT'] || 'so'
|
23
|
+
extdir = env :EXTDIR, "ext/#{modname}"
|
24
|
+
libdir = env :LIBDIR, "lib/#{modname}"
|
25
|
+
ruby = env :RUBY, 'ruby'
|
26
|
+
make = env :MAKE, 'make'
|
27
|
+
cxx = env :CXX, rbconf['CXX'] || 'g++'
|
28
|
+
defs = env :DEFS, []
|
29
|
+
debug = env :DEBUG, false
|
30
|
+
incdirs = env :INCDIRS, []
|
31
|
+
cxxflags = env(:CXXFLAGS, rbconf['CXXFLAGS']).dup
|
32
|
+
|
33
|
+
outname = "#{dlname}.#{dlext}"
|
34
|
+
extout = File.join extdir, outname
|
35
|
+
libout = File.join libdir, outname
|
36
|
+
|
37
|
+
srcs = FileList["#{extdir}/**/*.cpp"]
|
38
|
+
|
39
|
+
incroot = rbconf['rubyhdrdir']
|
40
|
+
incdirs += [
|
41
|
+
incroot,
|
42
|
+
"#{incroot}/#{RUBY_PLATFORM}",
|
43
|
+
'/opt/local/include',
|
44
|
+
'/opt/include'
|
45
|
+
]
|
46
|
+
incdirs.uniq!
|
47
|
+
|
48
|
+
defs << '_DEBUG' if debug
|
49
|
+
defs << 'NDEBUG' unless debug
|
50
|
+
defs << 'WIN32' if win32?
|
51
|
+
defs << 'COCOA' if cocoa?
|
52
|
+
defs << $~[0].upcase if RUBY_PLATFORM =~ /mswin|ming|cygwin|darwin/i
|
53
|
+
cxxflags << ' ' << rbconf['debugflags'] if debug
|
54
|
+
cxxflags << ' --stdlib=libc++' if clang?
|
55
|
+
cxxflags << defs.map{|s| " -D#{s}"}.join
|
56
|
+
cxxflags << incdirs.map{|s| " -I#{s}"}.join
|
57
|
+
|
58
|
+
extconf = File.join extdir, 'extconf.rb'
|
59
|
+
makefile = File.join extdir, 'Makefile'
|
60
|
+
depend = File.join extdir, 'depend.mf'
|
61
|
+
|
62
|
+
|
63
|
+
task :build => libout
|
64
|
+
|
65
|
+
task :clean do
|
66
|
+
sh %( cd #{extdir} && #{make} clean ) if File.exist? makefile
|
67
|
+
sh %( rm -rf #{makefile} #{depend} #{libout} )
|
68
|
+
end
|
69
|
+
|
70
|
+
file libout => extout do
|
71
|
+
sh %( cp #{extout} #{libout} )
|
72
|
+
end
|
73
|
+
|
74
|
+
file extout => [:lib, makefile] do
|
75
|
+
sh %( cd #{extdir} && #{make} )
|
76
|
+
end
|
77
|
+
|
78
|
+
file makefile => [extconf, depend] do
|
79
|
+
sh %( cd #{extdir} && #{ruby} #{File.basename extconf} )
|
80
|
+
end
|
81
|
+
|
82
|
+
file depend => srcs do
|
83
|
+
inc = incdirs.map{|s| " -I#{s}"}.join
|
84
|
+
src = srcs.map{|cpp| File.basename cpp}.join ' '
|
85
|
+
dep = File.basename depend
|
86
|
+
sh %( cd #{extdir} && #{cxx} -M #{cxxflags} #{inc} #{src} > #{dep} )
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end# :ext
|
data/task/gem.rake
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
task :gem => 'gem:build'
|
5
|
+
|
6
|
+
%w[clean install uninstall upload].each do |t|
|
7
|
+
task t.intern => "gem:#{t}"
|
7
8
|
end
|
8
9
|
|
10
|
+
empty_task :lib, :ext, :rdoc
|
11
|
+
|
9
12
|
|
10
13
|
namespace :gem do
|
11
14
|
|
@@ -21,6 +24,10 @@ namespace :gem do
|
|
21
24
|
|
22
25
|
task :build => gemfile
|
23
26
|
|
27
|
+
task :clean do
|
28
|
+
sh %( rm -f #{gemfile} )
|
29
|
+
end
|
30
|
+
|
24
31
|
task :install => gemfile do
|
25
32
|
sh %( #{gem} install #{gemfile} )
|
26
33
|
end
|
@@ -29,15 +36,11 @@ namespace :gem do
|
|
29
36
|
sh %( #{gem} uninstall #{name} )
|
30
37
|
end
|
31
38
|
|
32
|
-
task :clean do
|
33
|
-
sh %( rm -f #{gemfile} )
|
34
|
-
end
|
35
|
-
|
36
39
|
task :upload => gemfile do
|
37
40
|
sh %( #{gem} push #{gemfile} )
|
38
41
|
end
|
39
42
|
|
40
|
-
file gemfile => [
|
43
|
+
file gemfile => [:lib, :ext, :rdoc] do
|
41
44
|
sh %( #{gem} build #{gemspec} )
|
42
45
|
end
|
43
46
|
|