xot 0.1.3 → 0.1.4
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.
- 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/.gitignore
ADDED
data/Rakefile
CHANGED
@@ -1,37 +1,22 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'rubygems'
|
9
|
-
require 'xot/rake/helpers'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'xot/rake'
|
10
6
|
require 'xot/module'
|
11
7
|
|
12
8
|
include Xot::Rake
|
13
9
|
|
14
10
|
|
15
11
|
MODULE = Xot
|
12
|
+
DLNAME = 'tester'
|
16
13
|
|
17
14
|
|
18
15
|
task :default => :build
|
19
16
|
|
20
17
|
task :build => :lib
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
task :lib => 'lib:build'
|
25
|
-
|
26
|
-
task :doc => 'ext:doc'
|
27
|
-
|
28
|
-
task :gem => 'gem:build'
|
29
|
-
|
30
|
-
task :install => 'gem:install'
|
31
|
-
|
32
|
-
task :uninstall => 'gem:uninstall'
|
33
|
-
|
34
|
-
task :clean => ['lib:clean', 'gem:clean']
|
19
|
+
empty_task :test
|
35
20
|
|
36
21
|
|
37
22
|
Xot.load_tasks
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/ext/xot/extconf.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'mkmf'
|
6
|
+
require 'xot/rake/helpers'
|
7
|
+
require 'xot/module'
|
8
|
+
|
9
|
+
include Xot::Rake
|
10
|
+
|
11
|
+
|
12
|
+
debug = env :DEBUG, false
|
13
|
+
|
14
|
+
|
15
|
+
DEFS = []
|
16
|
+
INCDIRS = %w[
|
17
|
+
/opt/local/include
|
18
|
+
/opt/include
|
19
|
+
]
|
20
|
+
LIBDIRS = []
|
21
|
+
|
22
|
+
HEADERS = %w[
|
23
|
+
boost/noncopyable.hpp
|
24
|
+
ruby.h
|
25
|
+
xot.h
|
26
|
+
]
|
27
|
+
LIBS = %w[
|
28
|
+
stdc++
|
29
|
+
xot
|
30
|
+
]
|
31
|
+
|
32
|
+
|
33
|
+
DEFS << '_DEBUG' if debug
|
34
|
+
DEFS << 'NDEBUG' unless debug
|
35
|
+
DEFS << 'WINDOWS' << 'WIN32' if win32?
|
36
|
+
DEFS << 'COCOA' if cocoa?
|
37
|
+
DEFS << $~[0].upcase if RUBY_PLATFORM =~ /mswin|ming|cygwin|darwin/i
|
38
|
+
|
39
|
+
$CPPFLAGS << DEFS.map {|s| " -D#{s}"}.join
|
40
|
+
$CPPFLAGS << INCDIRS.map {|s| " -I#{s}"}.join
|
41
|
+
$LDFLAGS << LIBDIRS.map {|s| " -L#{s}"}.join
|
42
|
+
$CFLAGS << ' --stdlib=libc++' if clang?
|
43
|
+
|
44
|
+
RbConfig::CONFIG.each do |key, val|
|
45
|
+
{'gcc' => 'g++', 'clang' => 'clang++'}.each {|from, to| val.gsub! from, to}
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
dir_config 'boost'
|
50
|
+
dir_config 'xot', Xot.root_dir
|
51
|
+
|
52
|
+
exit 1 unless HEADERS.all? {|s| have_header(s)}
|
53
|
+
exit 1 unless LIBS.all? {|s| have_library(s)}
|
54
|
+
|
55
|
+
|
56
|
+
create_makefile 'xot/tester'
|
data/ext/xot/tester.cpp
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
|
4
|
+
static VALUE
|
5
|
+
test_native (VALUE self)
|
6
|
+
{
|
7
|
+
return true;
|
8
|
+
}
|
9
|
+
|
10
|
+
|
11
|
+
extern "C" void
|
12
|
+
Init_tester ()
|
13
|
+
{
|
14
|
+
VALUE mXot = rb_define_module( "Xot");
|
15
|
+
VALUE mTester = rb_define_module_under(mXot, "Tester");
|
16
|
+
|
17
|
+
rb_define_singleton_method(
|
18
|
+
mTester, "test_native", RUBY_METHOD_FUNC(test_native), 0);
|
19
|
+
}
|
data/include/xot.h
CHANGED
data/include/xot/debug.h
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __XOT_DEBUG_H__
|
4
|
+
#define __XOT_DEBUG_H__
|
5
|
+
|
6
|
+
|
7
|
+
namespace Xot
|
8
|
+
{
|
9
|
+
|
10
|
+
|
11
|
+
#ifdef _DEBUG
|
12
|
+
|
13
|
+
void dout (const char* format, ...);
|
14
|
+
|
15
|
+
void doutln (const char* format, ...);
|
16
|
+
|
17
|
+
#else
|
18
|
+
|
19
|
+
inline void dout(...) {}
|
20
|
+
|
21
|
+
inline void doutln(...) {}
|
22
|
+
|
23
|
+
#endif
|
24
|
+
|
25
|
+
|
26
|
+
}// Xot
|
27
|
+
|
28
|
+
|
29
|
+
#endif//EOH
|
data/include/xot/defs.h
CHANGED
@@ -4,6 +4,20 @@
|
|
4
4
|
#define __XOT_DEFS_H__
|
5
5
|
|
6
6
|
|
7
|
+
#include <stddef.h>
|
8
|
+
|
9
|
+
|
10
|
+
#ifdef CYGWIN
|
11
|
+
|
12
|
+
typedef unsigned short ushort;
|
13
|
+
|
14
|
+
typedef unsigned int uint;
|
15
|
+
|
16
|
+
typedef unsigned long ulong;
|
17
|
+
|
18
|
+
#endif
|
19
|
+
|
20
|
+
|
7
21
|
namespace Xot
|
8
22
|
{
|
9
23
|
|
@@ -12,13 +26,23 @@ namespace Xot
|
|
12
26
|
{
|
13
27
|
|
14
28
|
|
15
|
-
typedef unsigned char
|
29
|
+
typedef unsigned char uchar;
|
30
|
+
|
31
|
+
#ifdef CYGWIN
|
32
|
+
|
33
|
+
using ::ushort;
|
34
|
+
using ::uint;
|
35
|
+
using ::ulong;
|
36
|
+
|
37
|
+
#else
|
38
|
+
|
39
|
+
typedef unsigned short ushort;
|
16
40
|
|
17
|
-
|
41
|
+
typedef unsigned int uint;
|
18
42
|
|
19
|
-
|
43
|
+
typedef unsigned long ulong;
|
20
44
|
|
21
|
-
|
45
|
+
#endif
|
22
46
|
|
23
47
|
typedef long long longlong;
|
24
48
|
|
data/include/xot/pimpl.h
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __XOT_PIMPL_H__
|
4
|
+
#define __XOT_PIMPL_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <boost/scoped_ptr.hpp>
|
8
|
+
#include <boost/shared_ptr.hpp>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Xot
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
template <typename T, bool SHARED = false> class PImpl;
|
16
|
+
|
17
|
+
|
18
|
+
template <typename T>
|
19
|
+
class PImpl<T, false> : public boost::scoped_ptr<T>
|
20
|
+
{
|
21
|
+
|
22
|
+
typedef boost::scoped_ptr<T> Super;
|
23
|
+
|
24
|
+
typedef PImpl<T, false> This;
|
25
|
+
|
26
|
+
public:
|
27
|
+
|
28
|
+
PImpl () : Super(new T) {}
|
29
|
+
|
30
|
+
PImpl (T* p) : Super(p) {}
|
31
|
+
|
32
|
+
PImpl (const This& obj) : Super(new T(*obj)) {}
|
33
|
+
|
34
|
+
This& operator = (const This& obj)
|
35
|
+
{
|
36
|
+
if (&obj != this) reset(new T(*obj));
|
37
|
+
return *this;
|
38
|
+
}
|
39
|
+
|
40
|
+
bool shared () const {return false;}
|
41
|
+
|
42
|
+
};// PImpl
|
43
|
+
|
44
|
+
|
45
|
+
template <typename T>
|
46
|
+
class PImpl<T, true> : public boost::shared_ptr<T>
|
47
|
+
{
|
48
|
+
|
49
|
+
typedef boost::shared_ptr<T> Super;
|
50
|
+
|
51
|
+
typedef PImpl<T, true> This;
|
52
|
+
|
53
|
+
public:
|
54
|
+
|
55
|
+
PImpl () : Super(new T) {}
|
56
|
+
|
57
|
+
PImpl (T* p) : Super(p) {}
|
58
|
+
|
59
|
+
bool shared () const {return true;}
|
60
|
+
|
61
|
+
};// PImpl
|
62
|
+
|
63
|
+
|
64
|
+
}// Xot
|
65
|
+
|
66
|
+
|
67
|
+
#endif//EOH
|
data/include/xot/ref.h
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __XOT_REF_H__
|
4
|
+
#define __XOT_REF_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <assert.h>
|
8
|
+
#include <typeinfo>
|
9
|
+
#include <boost/noncopyable.hpp>
|
10
|
+
#include <xot/defs.h>
|
11
|
+
#include <xot/debug.h>
|
12
|
+
|
13
|
+
|
14
|
+
//#define XOT_REF_DEBUG 1
|
15
|
+
|
16
|
+
|
17
|
+
namespace Xot
|
18
|
+
{
|
19
|
+
|
20
|
+
|
21
|
+
class EmptyClass {};
|
22
|
+
|
23
|
+
|
24
|
+
template <typename SuperClass = EmptyClass>
|
25
|
+
class RefCountable : public SuperClass
|
26
|
+
{
|
27
|
+
|
28
|
+
public:
|
29
|
+
|
30
|
+
virtual void retain ()
|
31
|
+
{
|
32
|
+
reference(+1);
|
33
|
+
|
34
|
+
#ifdef XOT_REF_DEBUG
|
35
|
+
doutln(
|
36
|
+
"%s: %d -> %d",
|
37
|
+
typeid(this).name(), count() - 1, count());
|
38
|
+
#endif
|
39
|
+
}
|
40
|
+
|
41
|
+
virtual void release ()
|
42
|
+
{
|
43
|
+
assert(count() >= 0);
|
44
|
+
bool del = !retained() || reference(-1) == 0;
|
45
|
+
|
46
|
+
#ifdef XOT_REF_DEBUG
|
47
|
+
doutln(
|
48
|
+
"%s: %d -> %d, refcount:%s, delete:%s",
|
49
|
+
typeid(this).name(), count() + 1, count(),
|
50
|
+
retained() ? "yes" : "no", del ? "yes" : "no");
|
51
|
+
#endif
|
52
|
+
|
53
|
+
if (del) delete this;
|
54
|
+
}
|
55
|
+
|
56
|
+
protected:
|
57
|
+
|
58
|
+
RefCountable ()
|
59
|
+
: refcount(0)
|
60
|
+
{
|
61
|
+
}
|
62
|
+
|
63
|
+
virtual ~RefCountable ()
|
64
|
+
{
|
65
|
+
}
|
66
|
+
|
67
|
+
private:
|
68
|
+
|
69
|
+
int refcount;
|
70
|
+
|
71
|
+
bool retained () const
|
72
|
+
{
|
73
|
+
return refcount & 0x1;
|
74
|
+
}
|
75
|
+
|
76
|
+
int count () const
|
77
|
+
{
|
78
|
+
return refcount >> 1;
|
79
|
+
}
|
80
|
+
|
81
|
+
int reference (int add)
|
82
|
+
{
|
83
|
+
assert(add != 0);
|
84
|
+
int c = count() + add;
|
85
|
+
refcount = c << 1 | 0x1;// bit for retained flag.
|
86
|
+
return c;
|
87
|
+
}
|
88
|
+
|
89
|
+
RefCountable (const RefCountable&);
|
90
|
+
|
91
|
+
RefCountable& operator = (const RefCountable&);
|
92
|
+
|
93
|
+
};// RefCountable
|
94
|
+
|
95
|
+
|
96
|
+
template <typename T>
|
97
|
+
class Ref
|
98
|
+
{
|
99
|
+
|
100
|
+
typedef Ref<T> This;
|
101
|
+
|
102
|
+
public:
|
103
|
+
|
104
|
+
Ref (T* ptr = NULL)
|
105
|
+
: ptr(ptr)
|
106
|
+
{
|
107
|
+
if (ptr) ptr->retain();
|
108
|
+
}
|
109
|
+
|
110
|
+
Ref (const This& obj)
|
111
|
+
: ptr(obj.ptr)
|
112
|
+
{
|
113
|
+
if (ptr) ptr->retain();
|
114
|
+
}
|
115
|
+
|
116
|
+
Ref& operator = (T* ptr)
|
117
|
+
{
|
118
|
+
reset(ptr);
|
119
|
+
return *this;
|
120
|
+
}
|
121
|
+
|
122
|
+
Ref& operator = (const This& obj)
|
123
|
+
{
|
124
|
+
if (&obj == this) return *this;
|
125
|
+
reset(obj.ptr);
|
126
|
+
return *this;
|
127
|
+
}
|
128
|
+
|
129
|
+
~Ref ()
|
130
|
+
{
|
131
|
+
if (ptr) ptr->release();
|
132
|
+
}
|
133
|
+
|
134
|
+
void reset (T* ptr = NULL)
|
135
|
+
{
|
136
|
+
if (this->ptr == ptr) return;
|
137
|
+
if (this->ptr) this->ptr->release();
|
138
|
+
this->ptr = ptr;
|
139
|
+
if (this->ptr) this->ptr->retain();
|
140
|
+
}
|
141
|
+
|
142
|
+
T* get () {return ptr;}
|
143
|
+
|
144
|
+
const T* get () const {return ptr;}
|
145
|
+
|
146
|
+
T* operator -> () {return get();}
|
147
|
+
|
148
|
+
const T* operator -> () const {return get();}
|
149
|
+
|
150
|
+
T& operator * () {return *get();}
|
151
|
+
|
152
|
+
const T& operator * () const {return *get();}
|
153
|
+
|
154
|
+
operator T* () {return get();}
|
155
|
+
|
156
|
+
operator const T* () const {return get();}
|
157
|
+
|
158
|
+
bool operator == (T* ptr) const {return this->ptr == ptr;}
|
159
|
+
|
160
|
+
bool operator != (T* ptr) const {return !operator==(ptr);}
|
161
|
+
|
162
|
+
bool operator == (const T* ptr) const {return this->ptr == ptr;}
|
163
|
+
|
164
|
+
bool operator != (const T* ptr) const {return !operator==(ptr);}
|
165
|
+
|
166
|
+
bool operator == (const This& obj) const {return ptr == obj.ptr;}
|
167
|
+
|
168
|
+
bool operator != (const This& obj) const {return !operator==(obj);}
|
169
|
+
|
170
|
+
operator bool () const {return ptr != NULL;}
|
171
|
+
|
172
|
+
bool operator ! () const {return !operator bool();}
|
173
|
+
|
174
|
+
private:
|
175
|
+
|
176
|
+
T* ptr;
|
177
|
+
|
178
|
+
};// Ref
|
179
|
+
|
180
|
+
|
181
|
+
}// Xot
|
182
|
+
|
183
|
+
|
184
|
+
#endif//EOH
|