xot 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/xot/setter.rb CHANGED
@@ -7,10 +7,8 @@ module Xot
7
7
  module Setter
8
8
 
9
9
  def set (*args)
10
- return if args.empty?
11
-
12
10
  first = args.shift
13
- if first.class == Hash
11
+ if first.kind_of? Hash
14
12
  first.each {|name, value| set_value__ name, value}
15
13
  else
16
14
  set_value__ first, *args
@@ -19,9 +17,10 @@ module Xot
19
17
 
20
18
  private
21
19
 
22
- def set_value__ (name, *value)
23
- __send__ name.to_s + '=', *value
24
- end
20
+ def set_value__ (name, *values)
21
+ raise ArgumentError unless name && !values.empty?
22
+ __send__ "#{name}=", *values
23
+ end
25
24
 
26
25
  end# Setter
27
26
 
data/lib/xot/test.rb ADDED
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ module Xot
5
+
6
+
7
+ module Test
8
+
9
+ def assert_not (expression, *args)
10
+ assert !expression, *args
11
+ end
12
+
13
+ def assert_not_includes (collection, obj, *args)
14
+ assert !collection.include?(obj), *args
15
+ end
16
+
17
+ end# Test
18
+
19
+
20
+ end# Xot
data/src/debug.cpp CHANGED
@@ -3,7 +3,11 @@
3
3
 
4
4
  #include <stdio.h>
5
5
  #include <stdarg.h>
6
- #include <xot/string.h>
6
+ #include "xot/string.h"
7
+
8
+ // compile to check
9
+ #include "xot/pimpl.h"
10
+ #include "xot/ref.h"
7
11
 
8
12
 
9
13
  namespace Xot
data/src/exception.cpp ADDED
@@ -0,0 +1,89 @@
1
+ #include "xot/exception.h"
2
+
3
+
4
+ namespace Xot
5
+ {
6
+
7
+
8
+ XotError::XotError (const char* str)
9
+ : Super(str ? str : "")
10
+ {
11
+ }
12
+
13
+
14
+ InvalidStateError::InvalidStateError (const char* str)
15
+ : Super(str)
16
+ {
17
+ }
18
+
19
+
20
+ SystemError::SystemError (const char* str)
21
+ : Super(str)
22
+ {
23
+ }
24
+
25
+
26
+ NotImplementedError::NotImplementedError (const char* str)
27
+ : Super(str)
28
+ {
29
+ }
30
+
31
+
32
+ String
33
+ error_text (const char* file, int line, const char* str)
34
+ {
35
+ String s = str;
36
+ if (file) s = stringf("%s:%d: ", file, line) + s;
37
+ return s;
38
+ }
39
+
40
+
41
+ namespace ErrorFunctions
42
+ {
43
+
44
+ void
45
+ xot_error (const char* file, int line, const char* format, ...)
46
+ {
47
+ XOT_STRINGF(format, s);
48
+ throw XotError(error_text(file, line, s));
49
+ }
50
+
51
+ void
52
+ argument_error (const char* file, int line, const char* format, ...)
53
+ {
54
+ XOT_STRINGF(format, s);
55
+ throw std::invalid_argument(error_text(file, line, s));
56
+ }
57
+
58
+ void
59
+ index_error (const char* file, int line, const char* format, ...)
60
+ {
61
+ XOT_STRINGF(format, s);
62
+ throw std::out_of_range(error_text(file, line, s));
63
+ }
64
+
65
+ void
66
+ invalid_state_error (const char* file, int line, const char* format, ...)
67
+ {
68
+ XOT_STRINGF(format, s);
69
+ throw InvalidStateError(error_text(file, line, s));
70
+ }
71
+
72
+ void
73
+ system_error (const char* file, int line, const char* format, ...)
74
+ {
75
+ XOT_STRINGF(format, s);
76
+ throw SystemError(error_text(file, line, s));
77
+ }
78
+
79
+ void
80
+ not_implemented_error (const char* file, int line, const char* format, ...)
81
+ {
82
+ XOT_STRINGF(format, s);
83
+ throw NotImplementedError(error_text(file, line, s));
84
+ }
85
+
86
+ }// ErrorFunctions
87
+
88
+
89
+ }// Xot
data/src/string.cpp CHANGED
@@ -9,6 +9,45 @@ namespace Xot
9
9
  {
10
10
 
11
11
 
12
+ String::String ()
13
+ {
14
+ }
15
+
16
+ String::String (const char* str)
17
+ : Super(str)
18
+ {
19
+ }
20
+
21
+ String::operator const char* () const
22
+ {
23
+ return c_str();
24
+ }
25
+
26
+ String
27
+ operator + (const String& lhs, const String& rhs)
28
+ {
29
+ String t = lhs;
30
+ t += rhs;
31
+ return t;
32
+ }
33
+
34
+ String
35
+ operator + (const String& lhs, const char* rhs)
36
+ {
37
+ String t = lhs;
38
+ t += rhs;
39
+ return t;
40
+ }
41
+
42
+ String
43
+ operator + (const char* lhs, const String& rhs)
44
+ {
45
+ String t = lhs;
46
+ t += rhs;
47
+ return t;
48
+ }
49
+
50
+
12
51
  String
13
52
  stringf (const char* format, ...)
14
53
  {
data/src/time.cpp ADDED
@@ -0,0 +1,24 @@
1
+ #include "xot/time.h"
2
+
3
+
4
+ #include <boost/date_time/posix_time/posix_time.hpp>
5
+
6
+ namespace pt = boost::posix_time;
7
+
8
+
9
+ namespace Xot
10
+ {
11
+
12
+
13
+ double
14
+ time (bool local)
15
+ {
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;
21
+ }
22
+
23
+
24
+ }// Xot
data/task/ext.rake CHANGED
@@ -17,6 +17,7 @@ namespace :ext do
17
17
  rbconf = RbConfig::CONFIG
18
18
 
19
19
  mod = MODULE
20
+ mods = env :MODULES, [], :array
20
21
  modname = env :MODNAME, mod.name.downcase
21
22
  dlname = env :DLNAME, 'native'
22
23
  dlext = env :DLEXT, rbconf['DLEXT'] || 'so'
@@ -25,35 +26,20 @@ namespace :ext do
25
26
  ruby = env :RUBY, 'ruby'
26
27
  make = env :MAKE, 'make'
27
28
  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
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
32
36
 
33
37
  outname = "#{dlname}.#{dlext}"
34
38
  extout = File.join extdir, outname
35
39
  libout = File.join libdir, outname
36
40
 
37
41
  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
42
+ libs = FileList["#{libdir}/../lib*.a"]
57
43
 
58
44
  extconf = File.join extdir, 'extconf.rb'
59
45
  makefile = File.join extdir, 'Makefile'
@@ -75,15 +61,15 @@ namespace :ext do
75
61
  sh %( cd #{extdir} && #{make} )
76
62
  end
77
63
 
78
- file makefile => [extconf, depend] do
64
+ file makefile => [extconf, depend] + libs do
79
65
  sh %( cd #{extdir} && #{ruby} #{File.basename extconf} )
80
66
  end
81
67
 
82
68
  file depend => srcs do
83
- inc = incdirs.map{|s| " -I#{s}"}.join
84
- src = srcs.map{|cpp| File.basename cpp}.join ' '
69
+ inc = incdirs.map {|s| " -I#{s}"}.join
70
+ src = srcs.map {|cpp| File.basename cpp}.join ' '
85
71
  dep = File.basename depend
86
- sh %( cd #{extdir} && #{cxx} -M #{cxxflags} #{inc} #{src} > #{dep} )
72
+ sh %( cd #{extdir} && #{cxx} -M #{cppflags} #{inc} #{src} > #{dep} )
87
73
  end
88
74
 
89
75
 
data/task/lib.rake CHANGED
@@ -18,48 +18,32 @@ namespace :lib do
18
18
  rbconf = RbConfig::CONFIG
19
19
 
20
20
  mod = MODULE
21
- name = env :NAME, MODULE.name.downcase
21
+ mods = env :MODULES, [], :array
22
+ modname = env :MODNAME, MODULE.name.downcase
22
23
  incdir = env :INCDIR, 'include'
23
24
  srcdir = env :SRCDIR, 'src'
24
25
  libdir = env :LIBDIR, 'lib'
25
26
  cxx = env :CXX, rbconf['CXX'] || 'g++'
26
27
  ar = env :AR, rbconf['AR'] || 'ar'
27
- defs = env :DEFS, []
28
- debug = env :DEBUG, false
29
- incdirs = env :INCDIRS, []
30
- cxxflags = env(:CXXFLAGS, rbconf['CXXFLAGS']).dup
31
- arflags = env(:ARFLAGS, 'crs').dup
28
+ cppflags = env :CPPFLAGS, rbconf['CPPFLAGS']
29
+ cxxflags = env :CXXFLAGS, rbconf['CXXFLAGS']
30
+ arflags = env :ARFLAGS, 'crs'
31
+ defs = env :DEFS, [], :array
32
+ incdirs = env(:INCDIRS, [], :array) + mods.reverse.map {|m| m.include_dir}
32
33
 
33
- outname = "lib#{name}.a"
34
+ cppflags = cppflags cppflags, defs, incdirs
35
+ cxxflags = cflags cxxflags
36
+
37
+ outname = "lib#{modname}.a"
34
38
  out = File.join libdir, outname
35
39
 
36
40
  erbs = glob *[incdir, srcdir].map {|s| "#{s}/**/*.erb"}
37
41
  erbs = convertions erbs, {".erb" => ""}
38
- headers = glob("include/**/*.h") | erbs.values.grep(/\.h$/)
39
- srcs = glob("src/**/*.cpp") | erbs.values.grep(/\.cpp$/)
40
- srcs += glob("src/**/*.mm") if cocoa?
42
+ srcs = glob("#{srcdir}/**/*.cpp") | erbs.values.grep(/\.cpp$/)
43
+ srcs += glob("#{srcdir}/**/*.mm") if osx? || ios?
41
44
  srcs = srcs.reject {|s| s =~ %r(/win32/)} unless win32?
42
- srcs = srcs.reject {|s| s =~ %r(/cocoa/)} unless cocoa?
43
-
44
- incroot = rbconf['rubyhdrdir']
45
- incdirs.concat Xot.include_dirs + [
46
- incroot,
47
- "#{incroot}/#{RUBY_PLATFORM}",
48
- '/opt/local/include',
49
- '/opt/include'
50
- ]
51
- incdirs.uniq!
52
-
53
- defs << '_DEBUG' if debug
54
- defs << 'NDEBUG' unless debug
55
- defs << 'WIN32' if win32?
56
- defs << 'COCOA' if cocoa?
57
- defs << $~[0].upcase if RUBY_PLATFORM =~ /mswin|ming|cygwin|darwin/i
58
- cxxflags << ' ' << rbconf['debugflags'] if debug
59
- cxxflags.gsub! /-O\d?/, '' if debug
60
- cxxflags << ' --stdlib=libc++' if clang?
61
- cxxflags << defs.map{|s| " -D#{s}"}.join
62
- cxxflags << incdirs.map{|s| " -I#{s}"}.join
45
+ srcs = srcs.reject {|s| s =~ %r(/osx/)} unless osx?
46
+ srcs = srcs.reject {|s| s =~ %r(/ios/)} unless ios?
63
47
 
64
48
  depend = 'depend.mf'
65
49
  objs = convertions srcs, {".cpp" => ".o", ".mm" => ".o"}
@@ -77,11 +61,11 @@ namespace :lib do
77
61
  task :erb => erbs.values
78
62
 
79
63
  file out => objs.values do
80
- sh %( #{ar} #{arflags} #{out} #{objs.values.join " "} )
64
+ sh %( #{ar} #{arflags} #{out} #{objs.values.join " "} ) unless objs.values.empty?
81
65
  end
82
66
 
83
67
  file depend => erbs.values do
84
- sh %( #{cxx} -M #{cxxflags} #{srcs.join ' '} > #{depend} )
68
+ sh %( #{cxx} -M #{cppflags} #{srcs.join ' '} > #{depend} )
85
69
  input = open(depend) {|f| f.read}
86
70
  open(depend, 'w') do |output|
87
71
  output << input.gsub(/\w+\.o/, srcdir + '/\0')
@@ -90,13 +74,13 @@ namespace :lib do
90
74
 
91
75
  import depend if File.exist? depend
92
76
 
93
- objs.each do |(src, obj)|
77
+ objs.each do |src, obj|
94
78
  file obj => [depend, src] + erbs.values do
95
- sh %( #{cxx} -c #{cxxflags} -o #{obj} #{src} )
79
+ sh %( #{cxx} -c #{cppflags} #{cxxflags} -o #{obj} #{src} )
96
80
  end
97
81
  end
98
82
 
99
- erbs.each do |(erb, out)|
83
+ erbs.each do |erb, out|
100
84
  file out => erb do
101
85
  print "#{erb}: compiling to #{out} ..."
102
86
  compile erb, out
data/task/mac.rake ADDED
@@ -0,0 +1,45 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+
4
+ task :app => 'app:build'
5
+
6
+ %w[clean run].each do |t|
7
+ task t.intern => "app:#{t}"
8
+ end
9
+
10
+
11
+ namespace :app do
12
+
13
+
14
+ mod = MODULE
15
+ name = env :NAME, MODULE.name.downcase
16
+ bindir = env :BINDIR, 'bin'
17
+ ruby = env :RUBY, 'ruby'
18
+
19
+ bin = "#{bindir}/#{name}"
20
+ appname = name.capitalize
21
+ appdir = "#{appname}.app"
22
+ appbindir = "#{appdir}/Contents/MacOS"
23
+ out = "#{appbindir}/#{name}"
24
+
25
+ tmps = [appdir]
26
+
27
+
28
+ task :build => out
29
+
30
+ task :clean do
31
+ sh %( rm -rf #{tmps.join ' '} )
32
+ end
33
+
34
+ task :run => :app do
35
+ sh %( #{ruby} #{bin} )
36
+ end
37
+
38
+ file out => [bin, appbindir] do
39
+ sh %( cp #{bin} #{appbindir} )
40
+ end
41
+
42
+ directory appbindir
43
+
44
+
45
+ end# :app
data/test/helper.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- File.expand_path('../../lib', __FILE__).tap do |path|
5
- $:.unshift path if !$:.include?(path) && File.directory?(path)
6
- end
4
+ %w[.]
5
+ .map {|s| File.expand_path "../../#{s}/lib", __FILE__}
6
+ .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
8
8
  require 'test/unit'
9
9
  require 'xot'
10
+ require 'xot/test'
10
11
  require 'xot/tester'
12
+
13
+ include Xot::Test