gecoder-with-gecode 0.7.1-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +81 -0
- data/COPYING +17 -0
- data/LGPL-LICENSE +458 -0
- data/README +45 -0
- data/Rakefile +13 -0
- data/example/example_helper.rb +1 -0
- data/example/magic_sequence.rb +43 -0
- data/example/queens.rb +43 -0
- data/example/raw_bindings.rb +42 -0
- data/example/send_more_money.rb +43 -0
- data/example/send_most_money.rb +58 -0
- data/example/square_tiling.rb +84 -0
- data/example/sudoku-set.rb +110 -0
- data/example/sudoku.rb +61 -0
- data/lib/gecode.dll +0 -0
- data/lib/gecoder.rb +5 -0
- data/lib/gecoder/bindings.rb +54 -0
- data/lib/gecoder/bindings/bindings.rb +2210 -0
- data/lib/gecoder/interface.rb +8 -0
- data/lib/gecoder/interface/binding_changes.rb +313 -0
- data/lib/gecoder/interface/branch.rb +152 -0
- data/lib/gecoder/interface/constraints.rb +397 -0
- data/lib/gecoder/interface/constraints/bool/boolean.rb +246 -0
- data/lib/gecoder/interface/constraints/bool/linear.rb +29 -0
- data/lib/gecoder/interface/constraints/bool_enum/boolean.rb +84 -0
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +8 -0
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +75 -0
- data/lib/gecoder/interface/constraints/int/arithmetic.rb +71 -0
- data/lib/gecoder/interface/constraints/int/domain.rb +78 -0
- data/lib/gecoder/interface/constraints/int/linear.rb +295 -0
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +72 -0
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +100 -0
- data/lib/gecoder/interface/constraints/int_enum/count.rb +92 -0
- data/lib/gecoder/interface/constraints/int_enum/distinct.rb +69 -0
- data/lib/gecoder/interface/constraints/int_enum/element.rb +82 -0
- data/lib/gecoder/interface/constraints/int_enum/equality.rb +38 -0
- data/lib/gecoder/interface/constraints/int_enum/sort.rb +126 -0
- data/lib/gecoder/interface/constraints/int_enum_constraints.rb +37 -0
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +58 -0
- data/lib/gecoder/interface/constraints/reifiable_constraints.rb +78 -0
- data/lib/gecoder/interface/constraints/set/cardinality.rb +75 -0
- data/lib/gecoder/interface/constraints/set/connection.rb +193 -0
- data/lib/gecoder/interface/constraints/set/domain.rb +109 -0
- data/lib/gecoder/interface/constraints/set/operation.rb +132 -0
- data/lib/gecoder/interface/constraints/set/relation.rb +178 -0
- data/lib/gecoder/interface/constraints/set_enum/channel.rb +18 -0
- data/lib/gecoder/interface/constraints/set_enum/distinct.rb +80 -0
- data/lib/gecoder/interface/constraints/set_enum/operation.rb +60 -0
- data/lib/gecoder/interface/constraints/set_enum/selection.rb +217 -0
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +34 -0
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +72 -0
- data/lib/gecoder/interface/enum_matrix.rb +64 -0
- data/lib/gecoder/interface/enum_wrapper.rb +153 -0
- data/lib/gecoder/interface/model.rb +251 -0
- data/lib/gecoder/interface/search.rb +123 -0
- data/lib/gecoder/interface/variables.rb +254 -0
- data/lib/gecoder/version.rb +4 -0
- data/specs/binding_changes.rb +76 -0
- data/specs/bool_var.rb +74 -0
- data/specs/branch.rb +170 -0
- data/specs/constraints/arithmetic.rb +266 -0
- data/specs/constraints/bool_enum.rb +140 -0
- data/specs/constraints/boolean.rb +232 -0
- data/specs/constraints/cardinality.rb +154 -0
- data/specs/constraints/channel.rb +126 -0
- data/specs/constraints/connection.rb +373 -0
- data/specs/constraints/constraint_helper.rb +180 -0
- data/specs/constraints/constraints.rb +74 -0
- data/specs/constraints/count.rb +139 -0
- data/specs/constraints/distinct.rb +218 -0
- data/specs/constraints/element.rb +106 -0
- data/specs/constraints/equality.rb +31 -0
- data/specs/constraints/int_domain.rb +69 -0
- data/specs/constraints/int_relation.rb +78 -0
- data/specs/constraints/linear.rb +332 -0
- data/specs/constraints/reification_sugar.rb +96 -0
- data/specs/constraints/selection.rb +292 -0
- data/specs/constraints/set_domain.rb +181 -0
- data/specs/constraints/set_operation.rb +285 -0
- data/specs/constraints/set_relation.rb +201 -0
- data/specs/constraints/sort.rb +175 -0
- data/specs/distribution.rb +14 -0
- data/specs/enum_matrix.rb +43 -0
- data/specs/enum_wrapper.rb +122 -0
- data/specs/int_var.rb +144 -0
- data/specs/logging.rb +24 -0
- data/specs/model.rb +190 -0
- data/specs/search.rb +246 -0
- data/specs/set_var.rb +68 -0
- data/specs/spec_helper.rb +93 -0
- data/tasks/all_tasks.rb +1 -0
- data/tasks/building.howto +65 -0
- data/tasks/distribution.rake +156 -0
- data/tasks/rcov.rake +17 -0
- data/tasks/specs.rake +15 -0
- data/tasks/svn.rake +11 -0
- data/tasks/website.rake +51 -0
- data/vendor/gecode/win32/lib/libgecodeint.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodekernel.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodeminimodel.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodesearch.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodeset.dll +0 -0
- data/vendor/rust/README +28 -0
- data/vendor/rust/bin/cxxgenerator.rb +93 -0
- data/vendor/rust/include/rust_checks.hh +115 -0
- data/vendor/rust/include/rust_conversions.hh +102 -0
- data/vendor/rust/rust.rb +67 -0
- data/vendor/rust/rust/attribute.rb +51 -0
- data/vendor/rust/rust/bindings.rb +172 -0
- data/vendor/rust/rust/class.rb +339 -0
- data/vendor/rust/rust/constants.rb +48 -0
- data/vendor/rust/rust/container.rb +110 -0
- data/vendor/rust/rust/cppifaceparser.rb +129 -0
- data/vendor/rust/rust/cwrapper.rb +72 -0
- data/vendor/rust/rust/cxxclass.rb +98 -0
- data/vendor/rust/rust/element.rb +81 -0
- data/vendor/rust/rust/enum.rb +63 -0
- data/vendor/rust/rust/function.rb +407 -0
- data/vendor/rust/rust/namespace.rb +61 -0
- data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
- data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
- data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
- data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
- data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
- data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
- data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
- data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +91 -0
- data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
- data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +26 -0
- data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
- data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
- data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
- data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
- data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
- data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
- data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +7 -0
- data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
- data/vendor/rust/rust/type.rb +98 -0
- data/vendor/rust/test/Makefile +4 -0
- data/vendor/rust/test/constants.rb +36 -0
- data/vendor/rust/test/cppclass.cc +45 -0
- data/vendor/rust/test/cppclass.hh +67 -0
- data/vendor/rust/test/cppclass.rb +59 -0
- data/vendor/rust/test/cwrapper.c +74 -0
- data/vendor/rust/test/cwrapper.h +41 -0
- data/vendor/rust/test/cwrapper.rb +56 -0
- data/vendor/rust/test/dummyclass.hh +31 -0
- data/vendor/rust/test/lib/extension-test.rb +98 -0
- data/vendor/rust/test/operators.cc +41 -0
- data/vendor/rust/test/operators.hh +39 -0
- data/vendor/rust/test/operators.rb +39 -0
- data/vendor/rust/test/test-constants.rb +43 -0
- data/vendor/rust/test/test-cppclass.rb +82 -0
- data/vendor/rust/test/test-cwrapper.rb +80 -0
- data/vendor/rust/test/test-operators.rb +42 -0
- metadata +293 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/vendor/rust/README
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
When I wanted to write a GUI tagger for KDE using Korundum (KDE Ruby
|
2
|
+
bindings), I discovered to my sadness that most of the tagging
|
3
|
+
extensions for Ruby were simple bindings for the C interface of the
|
4
|
+
most common TagLib library (that is written in C++ instead); writing
|
5
|
+
bindings for the C++ interface was quite a complex task, and boring as
|
6
|
+
it was to copy and paste the same code over and over.
|
7
|
+
|
8
|
+
For this reason I started first writing a simple extensions generator
|
9
|
+
that used a YAML description of the namespaces and the classes to
|
10
|
+
write bindings for. This method worked fine for what I was working on
|
11
|
+
(RubyTag++), and also allowed me to write quite quickly some Ruby
|
12
|
+
bindings for Hunspell too.
|
13
|
+
|
14
|
+
Unfortunately this generator was not adaptable enough to write
|
15
|
+
bindings for C libraries that used some object oriented interfaces,
|
16
|
+
and was a mess to extend to provide bindings more suitable to some
|
17
|
+
different cases than the ones I've already used the script for.
|
18
|
+
|
19
|
+
For this reason I've started working on Rust: a more flexible
|
20
|
+
extensions builder, that allowed to bind even C libraries by faking
|
21
|
+
some classes on Ruby (although I haven't implemented this yet).
|
22
|
+
|
23
|
+
Hopefully in the future Rust can be used to easily produce Ruby
|
24
|
+
bindings for a number of libraries that currently aren't available at
|
25
|
+
all.
|
26
|
+
|
27
|
+
To contact me, send me patches or comments, just write to
|
28
|
+
<flameeyes@gmail.com> .
|
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
require 'rust/cppifaceparser'
|
3
|
+
|
4
|
+
|
5
|
+
if __FILE__ == $0
|
6
|
+
def usage
|
7
|
+
puts "Use: #{File.basename($0)} [header] [module name] [output file]"
|
8
|
+
end
|
9
|
+
|
10
|
+
parser = Rust::Cpp::IfaceParser.new
|
11
|
+
|
12
|
+
if ARGV.size != 3 or not File.exists?(ARGV[0].to_s)
|
13
|
+
usage
|
14
|
+
exit 0
|
15
|
+
end
|
16
|
+
|
17
|
+
header = ARGV[0]
|
18
|
+
namespace = ARGV[1]
|
19
|
+
outputfile = ARGV[2]
|
20
|
+
outputfile += ".rb" if not outputfile =~ /\.rb$/
|
21
|
+
|
22
|
+
classes = parser.parseFile(header)
|
23
|
+
|
24
|
+
rust = %@
|
25
|
+
require 'rust'
|
26
|
+
|
27
|
+
Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "#{namespace}" do |b|
|
28
|
+
b.include_header '#{header}', Rust::Bindings::HeaderGlobal
|
29
|
+
b.add_namespace "#{namespace}", "" do |ns|
|
30
|
+
@
|
31
|
+
classes.each { |klass|
|
32
|
+
rust += %@ ns.add_cxx_class "#{klass[:name]}" do |klass|\n@
|
33
|
+
klass[:constructors].each { |constructor|
|
34
|
+
rust += " klass.add_constructor "
|
35
|
+
if not constructor[:params].empty? and not constructor[:params].detect { |p| p[:type] =~ /void/ }
|
36
|
+
rust += "do |method|\n"
|
37
|
+
constructor[:params].each { |param|
|
38
|
+
rust += %@ method.add_parameter "#{param[:type]}", "#{param[:name]}"\n@
|
39
|
+
}
|
40
|
+
rust += " end"
|
41
|
+
end
|
42
|
+
rust += "\n"
|
43
|
+
}
|
44
|
+
|
45
|
+
klass[:methods].each { |method|
|
46
|
+
comment_method = false
|
47
|
+
if method[:params].detect { |p| p[:type] =~ /\s*\*\s*\*/ }
|
48
|
+
$stderr << "Ignoring method: #{method[:name]}\n"
|
49
|
+
comment_method = true
|
50
|
+
end
|
51
|
+
|
52
|
+
rust += "# " if comment_method
|
53
|
+
rust += %@ klass.add_method "#{method[:name]}", "#{method[:type]}"@
|
54
|
+
if not method[:params].empty? and not method[:params].detect { |p| p[:type] =~ /void/ }
|
55
|
+
rust += " do |method|\n" if not method[:params].empty?
|
56
|
+
|
57
|
+
|
58
|
+
method[:params].each { |param|
|
59
|
+
rust += "# " if comment_method
|
60
|
+
rust += %@ method.add_parameter "#{param[:type]}", "#{param[:name]}"\n@
|
61
|
+
}
|
62
|
+
rust += "# " if comment_method
|
63
|
+
rust += " end"
|
64
|
+
end
|
65
|
+
|
66
|
+
rust += "\n"
|
67
|
+
}
|
68
|
+
rust += " end\n"
|
69
|
+
}
|
70
|
+
|
71
|
+
rust += %@
|
72
|
+
end
|
73
|
+
end
|
74
|
+
@
|
75
|
+
|
76
|
+
File.open( outputfile, "w" ) { |f|
|
77
|
+
f << rust << "\n"
|
78
|
+
}
|
79
|
+
|
80
|
+
# Create configure.rb
|
81
|
+
File.open( File.dirname(outputfile)+"/configure.rb", "w" ) { |f|
|
82
|
+
f << %@
|
83
|
+
require 'mkmf'
|
84
|
+
find_header("rust_conversions.hh", "./include" )
|
85
|
+
eval File.open("#{File.basename(outputfile)}").readlines.to_s
|
86
|
+
create_makefile("#{namespace}")
|
87
|
+
@
|
88
|
+
}
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/* Copyright (c) 2007 David Cuadrado <krawek@gmail.com>
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
* a copy of this software and associated documentation files (the
|
5
|
+
* "Software"), to deal in the Software without restriction, including
|
6
|
+
* without limitation the rights to use, copy, modify, merge,
|
7
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
8
|
+
* and to permit persons to whom the Software is furnished to do so,
|
9
|
+
* subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be
|
12
|
+
* included in all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
18
|
+
* BE LIABLE
|
19
|
+
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
20
|
+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
*/
|
23
|
+
|
24
|
+
#ifndef __RUST_CHECKS__
|
25
|
+
#define __RUST_CHECKS__
|
26
|
+
|
27
|
+
#include <ruby.h>
|
28
|
+
|
29
|
+
static inline void rust_CheckType(VALUE *a)
|
30
|
+
{
|
31
|
+
Check_Type(a[0], NUM2INT(a[1]));
|
32
|
+
}
|
33
|
+
|
34
|
+
static inline bool isType(VALUE val, int type)
|
35
|
+
{
|
36
|
+
int result;
|
37
|
+
if( type == 0x0 ) return false;
|
38
|
+
|
39
|
+
VALUE args[2];
|
40
|
+
args[0] = (VALUE)val;
|
41
|
+
args[1] = INT2FIX(type);
|
42
|
+
|
43
|
+
rb_protect( (VALUE(*)(VALUE))rust_CheckType, (VALUE)args, &result);
|
44
|
+
return result == 0;
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
static inline bool is_object(VALUE val)
|
49
|
+
{
|
50
|
+
return isType(val, T_OBJECT);
|
51
|
+
}
|
52
|
+
|
53
|
+
static inline bool is_class(VALUE val)
|
54
|
+
{
|
55
|
+
return isType(val, T_CLASS);
|
56
|
+
}
|
57
|
+
|
58
|
+
static inline bool is_module(VALUE val)
|
59
|
+
{
|
60
|
+
return isType(val, T_MODULE);
|
61
|
+
}
|
62
|
+
|
63
|
+
static inline bool is_fLoat(VALUE val)
|
64
|
+
{
|
65
|
+
return isType(val, T_FLOAT);
|
66
|
+
}
|
67
|
+
|
68
|
+
static inline bool is_string(VALUE val)
|
69
|
+
{
|
70
|
+
return isType(val, T_STRING);
|
71
|
+
}
|
72
|
+
|
73
|
+
static inline bool is_regexp(VALUE val)
|
74
|
+
{
|
75
|
+
return isType(val, T_REGEXP);
|
76
|
+
}
|
77
|
+
|
78
|
+
static inline bool is_array(VALUE val)
|
79
|
+
{
|
80
|
+
return isType(val, T_ARRAY);
|
81
|
+
}
|
82
|
+
|
83
|
+
static inline bool is_int(VALUE val)
|
84
|
+
{
|
85
|
+
return isType(val, T_FIXNUM);
|
86
|
+
}
|
87
|
+
|
88
|
+
static inline bool is_hash(VALUE val)
|
89
|
+
{
|
90
|
+
return isType(val, T_HASH);
|
91
|
+
}
|
92
|
+
|
93
|
+
static inline bool is_symbol(VALUE val)
|
94
|
+
{
|
95
|
+
return isType(val, T_SYMBOL);
|
96
|
+
}
|
97
|
+
|
98
|
+
static inline bool is_bool(VALUE val)
|
99
|
+
{
|
100
|
+
return val == Qtrue || val == Qfalse;
|
101
|
+
}
|
102
|
+
|
103
|
+
static inline bool is_charPtr(VALUE val)
|
104
|
+
{
|
105
|
+
char *c = 0;
|
106
|
+
c = reinterpret_cast<char *>(DATA_PTR(val));
|
107
|
+
|
108
|
+
return c != 0; // FIXME
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
#endif
|
115
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
/* Copyright (c) 2005-2007 Diego Pettenò <flameeyes@gmail.com>
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
* a copy of this software and associated documentation files (the
|
5
|
+
* "Software"), to deal in the Software without restriction, including
|
6
|
+
* without limitation the rights to use, copy, modify, merge,
|
7
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
8
|
+
* and to permit persons to whom the Software is furnished to do so,
|
9
|
+
* subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be
|
12
|
+
* included in all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
18
|
+
* BE LIABLE
|
19
|
+
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
20
|
+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
*/
|
23
|
+
|
24
|
+
#ifndef __RUST_CONVERSIONS__
|
25
|
+
#define __RUST_CONVERSIONS__
|
26
|
+
|
27
|
+
#include <stdint.h>
|
28
|
+
#include <ruby.h>
|
29
|
+
|
30
|
+
/* Standard conversions for integer values */
|
31
|
+
|
32
|
+
static inline uint32_t ruby2uint(VALUE rval, int argn = -1) {
|
33
|
+
return NUM2UINT(rval);
|
34
|
+
}
|
35
|
+
|
36
|
+
static inline int32_t ruby2int(VALUE rval, int argn = -1) {
|
37
|
+
return NUM2INT(rval);
|
38
|
+
}
|
39
|
+
|
40
|
+
static inline VALUE cxx2ruby(int32_t val) {
|
41
|
+
return INT2FIX(val);
|
42
|
+
}
|
43
|
+
|
44
|
+
static inline VALUE cxx2ruby(uint32_t val) {
|
45
|
+
return INT2FIX(val);
|
46
|
+
}
|
47
|
+
|
48
|
+
static inline VALUE cxx2ruby(double val) {
|
49
|
+
return rb_float_new(val);
|
50
|
+
}
|
51
|
+
|
52
|
+
/* Standard conversions for stdint-provided types */
|
53
|
+
/* TODO: replace these with something more comples but that properly
|
54
|
+
handle a try to convert a number too big to stay into the size
|
55
|
+
requested.
|
56
|
+
*/
|
57
|
+
#define ruby2uint32_t ruby2uint
|
58
|
+
#define ruby2uint16_t ruby2uint
|
59
|
+
#define ruby2uint8_t ruby2uint
|
60
|
+
|
61
|
+
#define ruby2int32_t ruby2int
|
62
|
+
#define ruby2int16_t ruby2int
|
63
|
+
#define ruby2int8_t ruby2int
|
64
|
+
|
65
|
+
/* Conversion for common types (like strings */
|
66
|
+
|
67
|
+
static inline int *ruby2intArray(VALUE rval, int argn = -1) {
|
68
|
+
int i;
|
69
|
+
RArray *array = RARRAY(rval);
|
70
|
+
int* ret = (int*)malloc(array->len*sizeof(int)); // FIXME: Leak!!!
|
71
|
+
for(i = 0; i < array->len; i++)
|
72
|
+
{
|
73
|
+
ret[i] = NUM2INT(array->ptr[i]);
|
74
|
+
}
|
75
|
+
return ret;
|
76
|
+
}
|
77
|
+
|
78
|
+
static inline char *ruby2charPtr(VALUE rval, int argn = -1) {
|
79
|
+
Check_Type(rval, T_STRING);
|
80
|
+
return StringValuePtr(rval);
|
81
|
+
}
|
82
|
+
|
83
|
+
static inline VALUE cxx2ruby(const char *val) {
|
84
|
+
if ( ! val ) return Qnil;
|
85
|
+
return rb_str_new2(val);
|
86
|
+
}
|
87
|
+
|
88
|
+
static inline VALUE cxx2ruby(const std::string &str) {
|
89
|
+
return rb_str_new2(str.c_str());
|
90
|
+
}
|
91
|
+
|
92
|
+
/* Booleans conversion */
|
93
|
+
|
94
|
+
static inline VALUE cxx2ruby(bool val) {
|
95
|
+
return val ? Qtrue : Qfalse;
|
96
|
+
}
|
97
|
+
|
98
|
+
static inline bool ruby2bool(VALUE rval, int argn = -1) {
|
99
|
+
return !( rval == Qnil || rval == Qfalse );
|
100
|
+
}
|
101
|
+
|
102
|
+
#endif
|
data/vendor/rust/rust.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (c) 2005-2007 Diego Pettenò <flameeyes@gmail.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge,
|
7
|
+
# publish, distribute, sublicense, and/or sell copies of the Software,
|
8
|
+
# and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
18
|
+
# BE LIABLE
|
19
|
+
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
20
|
+
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'pathname'
|
24
|
+
|
25
|
+
# Rust is a Ruby bindings generator, developed by Diego Pettenò
|
26
|
+
# <flameeyes@gmail.com>, based on a simpler Ruby bindings generator
|
27
|
+
# that was used for RubyTag++ and ruby-hunspell.
|
28
|
+
#
|
29
|
+
# The original bindings generator was designed to permit a 1:1 mapping
|
30
|
+
# between C++ classes and Ruby classes, as otherwise writing Ruby
|
31
|
+
# bindings for a C++-based library would have consisted of a long
|
32
|
+
# series of generic functions to convert the types from one language
|
33
|
+
# to the other and to call the methods.
|
34
|
+
#
|
35
|
+
# Most C bindings, instead, either writes a lot of C code to create
|
36
|
+
# "fake" Classes out of a vaguely object-oriented C API, or simply
|
37
|
+
# create a module where to put all the C functions to call.
|
38
|
+
#
|
39
|
+
# The objective of Rust is to allow the description of a C or C++
|
40
|
+
# interface, through the creation of 1:1 class mappings or the design
|
41
|
+
# of "fake" classes out of C functions, without the need to actually
|
42
|
+
# write all the generic code, as that does not really change beside
|
43
|
+
# names, types and parameters.
|
44
|
+
module Rust
|
45
|
+
|
46
|
+
# The Template singleton class is used to simulate a big hash of
|
47
|
+
# templates, loaded with the data from the templates/ subdirectory.
|
48
|
+
# In truth the templates are loaded only when requested, removing
|
49
|
+
# the one-line comments found inside the files (as they are usually
|
50
|
+
# just for documenting that particular template).
|
51
|
+
class Templates
|
52
|
+
@cache = { }
|
53
|
+
@tpls_dir = (Pathname.new File.dirname(__FILE__)) + "rust/templates"
|
54
|
+
|
55
|
+
def Templates.[](name)
|
56
|
+
return @cache[name].dup if @cache[name]
|
57
|
+
|
58
|
+
pn = @tpls_dir + "#{name}.rusttpl"
|
59
|
+
raise "Template #{name} not found." unless pn.exist?
|
60
|
+
|
61
|
+
@cache[name] = pn.read.gsub(/\/\/.*$\n?/, '')
|
62
|
+
return @cache[name].dup
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
require 'rust/bindings'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (c) 2007 David Cuadrado <krawek@gmail.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge,
|
7
|
+
# publish, distribute, sublicense, and/or sell copies of the Software,
|
8
|
+
# and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
18
|
+
# BE LIABLE
|
19
|
+
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
20
|
+
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'set'
|
24
|
+
require 'rust/element'
|
25
|
+
require 'rust/type'
|
26
|
+
|
27
|
+
module Rust
|
28
|
+
class Attribute < Element
|
29
|
+
def initialize(name, type, opts)
|
30
|
+
super()
|
31
|
+
|
32
|
+
@name = name
|
33
|
+
@type = Type.new(type)
|
34
|
+
@options = opts
|
35
|
+
|
36
|
+
@declaration_template = ""
|
37
|
+
@definition_template = Templates["AttributeDefinition"]
|
38
|
+
@prototype_template = "void set!attribute_bindname!(VALUE self, VALUE val);\nVALUE get!attribute_bindname!(VALUE self);\n"
|
39
|
+
@initialization_template = Templates["AttributeInitBinding"]
|
40
|
+
|
41
|
+
|
42
|
+
add_expansion 'parent_varname', "@options[:parent].varname"
|
43
|
+
add_expansion 'attribute_bindname', "@name"
|
44
|
+
add_expansion 'attribute_type', "@type"
|
45
|
+
add_expansion 'attribute_name', "@name"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|