rbplusplus 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/Rakefile +13 -13
  2. data/TODO +9 -41
  3. data/lib/rbplusplus/builders/allocation_strategy.rb +57 -0
  4. data/lib/rbplusplus/builders/base.rb +115 -212
  5. data/lib/rbplusplus/builders/class.rb +129 -115
  6. data/lib/rbplusplus/builders/const.rb +30 -0
  7. data/lib/rbplusplus/builders/const_converter.rb +52 -0
  8. data/lib/rbplusplus/builders/constructor.rb +19 -0
  9. data/lib/rbplusplus/builders/director.rb +149 -0
  10. data/lib/rbplusplus/builders/director_method.rb +20 -0
  11. data/lib/rbplusplus/builders/enumeration.rb +19 -26
  12. data/lib/rbplusplus/builders/extension.rb +42 -54
  13. data/lib/rbplusplus/builders/global_function.rb +18 -0
  14. data/lib/rbplusplus/builders/helpers/class.rb +74 -0
  15. data/lib/rbplusplus/builders/helpers/enumeration.rb +28 -0
  16. data/lib/rbplusplus/builders/helpers/module.rb +22 -0
  17. data/lib/rbplusplus/builders/include.rb +32 -0
  18. data/lib/rbplusplus/builders/instance_variable.rb +36 -0
  19. data/lib/rbplusplus/builders/method.rb +14 -0
  20. data/lib/rbplusplus/builders/method_base.rb +136 -0
  21. data/lib/rbplusplus/builders/module.rb +37 -51
  22. data/lib/rbplusplus/builders/module_function.rb +16 -0
  23. data/lib/rbplusplus/builders/static_method.rb +14 -0
  24. data/lib/rbplusplus/extension.rb +140 -28
  25. data/lib/rbplusplus/logger.rb +45 -0
  26. data/lib/rbplusplus/module.rb +55 -1
  27. data/lib/rbplusplus/transformers/class.rb +116 -35
  28. data/lib/rbplusplus/transformers/function.rb +14 -16
  29. data/lib/rbplusplus/transformers/method.rb +26 -1
  30. data/lib/rbplusplus/transformers/namespace.rb +12 -0
  31. data/lib/rbplusplus/transformers/node.rb +47 -54
  32. data/lib/rbplusplus/transformers/node_cache.rb +5 -9
  33. data/lib/rbplusplus/writers/multiple_files_writer.rb +290 -88
  34. data/lib/rbplusplus/writers/single_file_writer.rb +36 -14
  35. data/lib/rbplusplus.rb +44 -18
  36. data/test/allocation_strategies_test.rb +33 -0
  37. data/test/class_methods_encapsulate_test.rb +59 -0
  38. data/test/class_methods_test.rb +2 -35
  39. data/test/classes_test.rb +72 -2
  40. data/test/compiling_test.rb +13 -0
  41. data/test/constructors_test.rb +9 -18
  42. data/test/custom_code_test.rb +53 -0
  43. data/test/default_arguments_test.rb +69 -0
  44. data/test/director_test.rb +173 -0
  45. data/test/enumerations_test.rb +29 -0
  46. data/test/extension_test.rb +7 -2
  47. data/test/file_writers_test.rb +11 -4
  48. data/test/function_pointer_test.rb +56 -0
  49. data/test/function_pointers_classes_test.rb +27 -0
  50. data/test/generated/extconf.rb +2 -2
  51. data/test/headers/Adder.cpp +8 -0
  52. data/test/headers/Adder.h +31 -1
  53. data/test/headers/alloc_strats.h +26 -0
  54. data/test/headers/class_methods.h +30 -0
  55. data/test/headers/code/custom_to_from_ruby.cpp +11 -0
  56. data/test/headers/code/custom_to_from_ruby.hpp +13 -0
  57. data/test/headers/constructors.h +8 -20
  58. data/test/headers/default_arguments.h +49 -0
  59. data/test/headers/director.h +148 -0
  60. data/test/headers/enums.h +33 -0
  61. data/test/headers/function_pointers.h +32 -0
  62. data/test/headers/function_pointers_class.h +26 -0
  63. data/test/headers/needs_code.h +10 -0
  64. data/test/headers/overload.h +0 -3
  65. data/test/headers/subclass.h +10 -0
  66. data/test/headers/to_from_ruby.h +6 -4
  67. data/test/headers/ugly_interface.h +4 -7
  68. data/test/modules_test.rb +11 -6
  69. data/test/overloading_test.rb +6 -2
  70. data/test/subclass_test.rb +20 -10
  71. data/test/test_helper.rb +6 -1
  72. data/test/to_from_ruby_test.rb +0 -2
  73. data/test/wrap_as_test.rb +28 -37
  74. metadata +89 -57
  75. data/lib/rbplusplus/builders/types_manager.rb +0 -93
  76. data/lib/rbplusplus/transformers/constructor.rb +0 -4
  77. data/lib/rbplusplus/transformers/module.rb +0 -71
  78. data/lib/rbplusplus/transformers/node_reference.rb +0 -30
  79. data/test/headers/ugly_helper.h +0 -18
  80. data/test/object_persistence_test.rb +0 -44
@@ -27,6 +27,11 @@ context "Wrapping enumerations" do
27
27
  TestEnum::VALUE2.to_i.should == 1
28
28
  TestEnum::VALUE3.to_i.should == 2
29
29
  end
30
+
31
+ specify "should only wrap public enums" do
32
+ assert !defined?(Tester::NotWrapped)
33
+ assert !defined?(Tester::AlsoNotWrapped)
34
+ end
30
35
 
31
36
  specify "should wrap up enumerations at proper nesting" do
32
37
  assert defined?(Tester::MyEnum)
@@ -60,4 +65,28 @@ context "Wrapping enumerations" do
60
65
  t.get_an_enum("I like money").should == Tester::MyEnum::I_LIKE_MONEY
61
66
  t.get_an_enum("You like money").should == Tester::MyEnum::YOU_LIKE_MONEY_TOO
62
67
  end
68
+
69
+ specify "anonymous enumerations' values are added as constants to the parent class" do
70
+ assert defined?(Tester::ANON_ENUM_VAL1)
71
+ assert defined?(Tester::ANON_ENUM_VAL2)
72
+ assert defined?(Tester::ANON_ENUM_VAL3)
73
+ assert defined?(Tester::ANON_ENUM_VAL4)
74
+
75
+ Tester::ANON_ENUM_VAL1.should.equal 1
76
+ Tester::ANON_ENUM_VAL2.should.equal 2
77
+ Tester::ANON_ENUM_VAL3.should.equal 5
78
+ Tester::ANON_ENUM_VAL4.should.equal 3
79
+ end
80
+
81
+ specify "top-level anonymous enumerations' values are added to the global scope" do
82
+ assert defined?(OUTER_ANON_1)
83
+ assert defined?(OUTER_ANON_2)
84
+ assert defined?(FOURTY_TWO)
85
+ assert defined?(SEPERATE_OUTER_VALUE)
86
+
87
+ OUTER_ANON_1.should.equal 0
88
+ OUTER_ANON_2.should.equal 1
89
+ FOURTY_TWO.should.equal 42
90
+ SEPERATE_OUTER_VALUE.should.equal 14
91
+ end
63
92
  end
@@ -5,6 +5,7 @@ context "Ruby Extension creation" do
5
5
  specify "should create a valid Ruby extension" do
6
6
  Extension.new "ext_test" do |e|
7
7
  e.sources full_dir("headers/empty.h")
8
+ e.writer_mode :single
8
9
  end
9
10
 
10
11
  should.not.raise LoadError do
@@ -16,6 +17,7 @@ context "Ruby Extension creation" do
16
17
  e = Extension.new "extension"
17
18
  e.sources full_dir("headers/empty.h")
18
19
  e.working_dir = File.join(File.expand_path(File.dirname(__FILE__)), "generated")
20
+ e.writer_mode :single
19
21
  e.build
20
22
  e.write
21
23
  e.compile
@@ -27,11 +29,14 @@ context "Ruby Extension creation" do
27
29
 
28
30
  specify "should properly build working dir as deep as needed" do
29
31
  should.not.raise Errno::ENOENT do
32
+ path = File.join(File.expand_path(File.dirname(__FILE__)), "generated", "path1", "path2")
30
33
  Extension.new "extension" do |e|
31
34
  e.sources full_dir("headers/empty.h")
32
- e.working_dir = File.join(File.expand_path(File.dirname(__FILE__)),
33
- "generated", "path1", "path2")
35
+ e.working_dir = path
36
+ e.writer_mode :single
34
37
  end
38
+
39
+ assert File.exists?(File.join(path, "extconf.rb"))
35
40
  end
36
41
  end
37
42
  end
@@ -10,7 +10,8 @@ context "Multiple file writer (default)" do
10
10
  e.sources full_dir("headers/Adder.h")
11
11
 
12
12
  e.module "Mod" do |m|
13
- m.namespace "classes"
13
+ node = m.namespace "classes"
14
+ node.classes("Adder").disable_typedef_lookup
14
15
  end
15
16
 
16
17
  e.build
@@ -19,7 +20,7 @@ context "Multiple file writer (default)" do
19
20
 
20
21
  specify "should properly split up code into multiple files" do
21
22
  files = Dir["#{@working_dir}/*"]
22
- files.size.should == 6
23
+ files.size.should == 12
23
24
 
24
25
  %w(
25
26
  extconf.rb
@@ -27,6 +28,12 @@ context "Multiple file writer (default)" do
27
28
  _Mod.rb.hpp
28
29
  _classes_Adder.rb.cpp
29
30
  _classes_Adder.rb.hpp
31
+ _classes_IntAdder.rb.cpp
32
+ _classes_IntAdder.rb.hpp
33
+ _classes_ShouldFindMe.rb.hpp
34
+ _classes_ShouldFindMe.rb.cpp
35
+ _rbpp_custom.rb.hpp
36
+ _rbpp_custom.rb.cpp
30
37
  adder.rb.cpp
31
38
  ).each do |wants|
32
39
  assert_not_nil files.find {|got| File.basename(got) == wants }, "Didn't find #{wants}"
@@ -57,8 +64,8 @@ context "Multiple file writer with to_from_ruby" do
57
64
 
58
65
  %w(
59
66
  extconf.rb
60
- _to_from_ruby.rb.hpp
61
- _to_from_ruby.rb.cpp
67
+ _rbpp_custom.rb.hpp
68
+ _rbpp_custom.rb.cpp
62
69
  ).each do |wants|
63
70
  assert_not_nil files.find {|got| File.basename(got) == wants }, "Didn't find #{wants}"
64
71
  end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "properly handles and wraps function pointer arguments" do
4
+
5
+ def setup
6
+ if !defined?(@@function_pointers)
7
+ super
8
+ @@function_pointers = true
9
+ Extension.new "function_pointers" do |e|
10
+ e.sources full_dir("headers/function_pointers.h")
11
+ node = e.namespace "function_pointers"
12
+ end
13
+
14
+ require 'function_pointers'
15
+ end
16
+ end
17
+
18
+ specify "no arguments, no return" do
19
+ proc_called = false
20
+
21
+ set_callback do
22
+ proc_called = true
23
+ end
24
+
25
+ call_callback
26
+
27
+ assert proc_called
28
+ end
29
+
30
+ specify "arguments, no return" do
31
+ proc_arg = nil
32
+
33
+ set_callback_with_args do |i|
34
+ proc_arg = i
35
+ end
36
+
37
+ call_callback_with_args(10)
38
+
39
+ proc_arg.should == 10
40
+ end
41
+
42
+ specify "arguments and return" do
43
+ proc_arg = nil
44
+ set_callback_returns do |i|
45
+ proc_arg = i
46
+ i * 10
47
+ end
48
+
49
+ ret = call_callback_returns(8)
50
+
51
+ proc_arg.should == 8
52
+ ret.should == 80
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Function pointers into class methods" do
4
+
5
+ def setup
6
+ if !defined?(@@function_pointers_class)
7
+ super
8
+ @@function_pointers_class = true
9
+ Extension.new "function_pointers_class" do |e|
10
+ e.sources full_dir("headers/function_pointers_class.h")
11
+ node = e.namespace "function_pointers_class"
12
+ end
13
+
14
+ require 'function_pointers_class'
15
+ end
16
+ end
17
+
18
+
19
+ specify "works" do
20
+ t = PointerTest.new
21
+ t.set_callback do |i|
22
+ 42
23
+ end
24
+
25
+ t.call_callback(12).should == 42
26
+ end
27
+ end
@@ -7,7 +7,7 @@ def append_ld_flags(flags)
7
7
  with_ldflags("#{$LDFLAGS} #{flags.join(' ')}") { true }
8
8
  end
9
9
 
10
- $CPPFLAGS += " -I'/home/roelofs/projects/rbplusplus/test/generated' -I/home/roelofs/projects/rbplusplus/test/headers "
10
+ $CPPFLAGS += " -I'/home/roelofs/projects/rbplusplus/test/generated' "
11
11
  $LDFLAGS += " "
12
12
 
13
13
  if RUBY_PLATFORM =~ /darwin/
@@ -22,4 +22,4 @@ if RUBY_PLATFORM =~ /darwin/
22
22
  append_ld_flags '-all_load'
23
23
  end
24
24
 
25
- create_makefile("to_from_ruby")
25
+ create_makefile("function_pointers_class")
@@ -0,0 +1,8 @@
1
+ #include "Adder.h"
2
+
3
+ namespace classes {
4
+ const int Adder::MY_VALUE = 10;
5
+ const float Adder::HideMe = 14.35;
6
+
7
+ Adder::Adder() : const_var(14) { }
8
+ }
data/test/headers/Adder.h CHANGED
@@ -7,7 +7,11 @@ using namespace std;
7
7
  namespace classes {
8
8
  class Adder {
9
9
  public:
10
- Adder() { }
10
+ Adder();
11
+
12
+ static const int MY_VALUE;
13
+
14
+ static const float HideMe;
11
15
 
12
16
  static int doAdding(int a, int b, int c, int d, int e) {
13
17
  return a + b + c + d + e;
@@ -20,7 +24,33 @@ namespace classes {
20
24
  string addStrings(string a, string b) { return a + b; }
21
25
 
22
26
  string getClassName() { return "Adder"; }
27
+
28
+ int value1;
29
+ float value2;
30
+ string value3;
31
+
32
+ string shouldBeTransformed;
33
+
34
+ const int const_var;
35
+ };
36
+
37
+ template<typename T>
38
+ class TemplateAdder {
39
+
23
40
  };
41
+
42
+ typedef TemplateAdder<int> IntAdder;
43
+
44
+ template<typename T>
45
+ class NestedTemplate {
46
+
47
+ };
48
+
49
+ typedef NestedTemplate<int> SuperTemplate;
50
+ typedef SuperTemplate MiddleTypedef;
51
+ typedef MiddleTypedef ShouldFindMe;
52
+
53
+ typedef Adder DontFindMeBro;
24
54
  }
25
55
 
26
56
  #endif
@@ -0,0 +1,26 @@
1
+ #ifndef __ALLOC_STRATS_H__
2
+ #define __ALLOC_STRATS_H__
3
+
4
+ namespace alloc_strats {
5
+
6
+ class NoConstructor {
7
+ public:
8
+ ~NoConstructor() { }
9
+
10
+ private:
11
+ NoConstructor() { }
12
+ };
13
+
14
+ class Neither {
15
+ private:
16
+ Neither() {}
17
+ ~Neither() {}
18
+ public:
19
+ NoConstructor* getConstructor() { return 0; }
20
+
21
+ Neither* getInstance() { return 0; }
22
+ };
23
+ }
24
+
25
+
26
+ #endif
@@ -1,3 +1,6 @@
1
+ #ifndef __ENCAPSULATE_H__
2
+ #define __ENCAPSULATE_H__
3
+
1
4
  namespace encapsulation {
2
5
  class Base {
3
6
  protected:
@@ -38,4 +41,31 @@ namespace encapsulation {
38
41
  return new Extended();
39
42
  }
40
43
  };
44
+
45
+ class ArgumentAccess {
46
+ struct PrivateStruct { };
47
+
48
+ protected:
49
+ struct ProtStruct { };
50
+
51
+ public:
52
+ struct PublicStruct {
53
+ PublicStruct() {}
54
+ };
55
+
56
+ ArgumentAccess() {}
57
+ ~ArgumentAccess() {}
58
+
59
+ // Only wrap methods that use public structs
60
+ void wrapMePrivate(PrivateStruct st) { }
61
+ void wrapMeProtected(ProtStruct st) { }
62
+ void wrapMePublic(PublicStruct st) { }
63
+
64
+ // And make sure it works with multiple arguments
65
+ void wrapMeManyNo(int a, float b, PublicStruct st1, ProtStruct st2) { }
66
+ void wrapMeManyYes(int a, float b, PublicStruct st1) { }
67
+
68
+ };
41
69
  }
70
+
71
+ #endif
@@ -0,0 +1,11 @@
1
+ #include "custom_to_from_ruby.hpp"
2
+
3
+ template<>
4
+ Rice::Object to_ruby<short int>(short int const & a) {
5
+ return INT2NUM(a);
6
+ }
7
+
8
+ template<>
9
+ short int from_ruby<short int>(Rice::Object x) {
10
+ return FIX2INT(x.value());
11
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef __CUSTOM_TO_RUBY_H__
2
+ #define __CUSTOM_TO_RUBY_H__
3
+
4
+ #include <rice/Object.hpp>
5
+ #include <rice/to_from_ruby.hpp>
6
+
7
+ template<>
8
+ Rice::Object to_ruby<short int>(short int const & a);
9
+
10
+ template<>
11
+ short int from_ruby<short int>(Rice::Object x);
12
+
13
+ #endif
@@ -6,34 +6,22 @@
6
6
  using namespace std;
7
7
 
8
8
  namespace constructors {
9
- class StringHolder {
10
- private:
11
- std::string name;
12
- public:
13
- StringHolder() { }
14
- StringHolder(std::string name) {
15
- setName(name);
16
- }
17
- inline std::string getName() {
18
- return name;
19
- }
20
- inline void setName(std::string name) {
21
- this->name = name;
22
- }
23
- };
24
-
25
9
  class DoubleStringHolder {
26
10
  private:
27
- StringHolder *one, *two;
11
+ std::string one, two;
28
12
  public:
29
- DoubleStringHolder(StringHolder *one, StringHolder *two) {
13
+
14
+ DoubleStringHolder(std::string one, std::string two) {
30
15
  this->one = one;
31
16
  this->two = two;
32
17
  }
33
- inline StringHolder *getOne() {
18
+
19
+ DoubleStringHolder() { }
20
+
21
+ inline std::string getOne() {
34
22
  return this->one;
35
23
  }
36
- inline StringHolder *getTwo() {
24
+ inline std::string getTwo() {
37
25
  return this->two;
38
26
  }
39
27
  };
@@ -0,0 +1,49 @@
1
+ #ifndef __DEFAULT_ARGS_H__
2
+ #define __DEFAULT_ARGS_H__
3
+
4
+ #include <string>
5
+ #include <iostream>
6
+ using namespace std;
7
+
8
+ namespace default_args {
9
+
10
+ // Global functions
11
+ int global_do(int x, int y = 3, int z = 10) {
12
+ return x * y * z;
13
+ }
14
+
15
+ // Module functions
16
+ int module_do(int x, int y = 3, int z = 10) {
17
+ return x + y + z;
18
+ }
19
+
20
+ class Tester {
21
+ public:
22
+ Tester() { }
23
+
24
+ // Class methods
25
+ std::string concat(std::string value1, std::string value2, const char* with = "-") {
26
+ return value1 + std::string(with) + value2;
27
+ }
28
+
29
+ // Class static methods
30
+ static std::string build(std::string base, int times = 3) {
31
+ std::string out = "";
32
+ for(int i = 0; i < times; i++) {
33
+ out += base;
34
+ }
35
+ return out;
36
+ }
37
+ };
38
+
39
+ class Directed {
40
+ public:
41
+ // Director methods
42
+ virtual int virtualDo(int x, int y = 10) {
43
+ return x * y;
44
+ }
45
+ };
46
+
47
+ }
48
+
49
+ #endif // __DEFAULT_ARGS_H__
@@ -0,0 +1,148 @@
1
+ #ifndef __DIRECTOR__H__
2
+ #define __DIRECTOR__H__
3
+
4
+ #include <vector>
5
+ #include <string>
6
+
7
+ namespace director {
8
+
9
+ /**
10
+ * Abstract base class
11
+ */
12
+ class Worker {
13
+ public:
14
+ virtual ~Worker() { }
15
+
16
+ enum ZeeEnum {
17
+ VALUE = 4
18
+ };
19
+
20
+ int getNumber() { return 12; }
21
+
22
+ virtual int doSomething(int num) { return num * 4; }
23
+
24
+ virtual int process(int num) = 0;
25
+
26
+ virtual int doProcess(int num) { return doProcessImpl(num); }
27
+ virtual int doProcessImpl(int num) const = 0;
28
+ };
29
+
30
+ /**
31
+ * Subclass that implements pure virtual
32
+ */
33
+ class MultiplyWorker : public Worker {
34
+ public:
35
+ virtual ~MultiplyWorker() { }
36
+
37
+ virtual int process(int num) { return num * 2; }
38
+ };
39
+
40
+ /**
41
+ * Class to handle workers
42
+ */
43
+ class Handler {
44
+ std::vector<Worker*> mWorkers;
45
+
46
+ public:
47
+
48
+ void addWorker(Worker* worker) { mWorkers.push_back(worker); }
49
+
50
+ int processWorkers(int start) {
51
+ std::vector<Worker*>::iterator i = mWorkers.begin();
52
+ int results = start;
53
+
54
+ for(; i != mWorkers.end(); i++) {
55
+ results = (*i)->process(results);
56
+ }
57
+
58
+ return results;
59
+ }
60
+
61
+ int addWorkerNumbers() {
62
+ std::vector<Worker*>::iterator i = mWorkers.begin();
63
+ int results = 0;
64
+
65
+ for(; i != mWorkers.end(); i++) {
66
+ results += (*i)->getNumber();
67
+ }
68
+
69
+ return results;
70
+ }
71
+ };
72
+
73
+
74
+ /**
75
+ * Testing renaming works w/ directors
76
+ */
77
+ class BadNameClass {
78
+ public:
79
+ BadNameClass() { }
80
+
81
+ virtual bool _is_x_ok_to_run() { return false; }
82
+
83
+ virtual int __do_someProcessing() { return 14; }
84
+ };
85
+
86
+ /**
87
+ * Testing constructor args
88
+ */
89
+ class VirtualWithArgs {
90
+ int a_;
91
+ bool b_;
92
+ public:
93
+ VirtualWithArgs(int a, bool b) {
94
+ a_ = a;
95
+ b_ = b;
96
+ }
97
+
98
+ virtual int processA(std::string in) {
99
+ return in.length() + a_;
100
+ }
101
+
102
+ virtual bool processB() {
103
+ return b_;
104
+ }
105
+ };
106
+
107
+ /**
108
+ * Testing non-public constructors
109
+ */
110
+ class NoConstructor {
111
+ protected:
112
+ NoConstructor() { }
113
+ NoConstructor(const NoConstructor&) { }
114
+
115
+ public:
116
+ virtual int doSomething() { return 4; }
117
+ };
118
+
119
+ /**
120
+ * Test inheritance heirarchy with virtual methods
121
+ * throughout the tree
122
+ */
123
+ class VBase {
124
+ public:
125
+ VBase() { }
126
+ virtual ~VBase() { }
127
+
128
+ virtual std::string methodOne() = 0;
129
+ virtual std::string methodTwo() = 0;
130
+ virtual std::string methodThree() = 0;
131
+ };
132
+
133
+ class VOne : public VBase {
134
+ public:
135
+ virtual std::string methodOne() {
136
+ return "methodOne";
137
+ }
138
+ };
139
+
140
+ class VTwo : public VOne {
141
+ public:
142
+ virtual std::string methodTwo() {
143
+ return "methodTwo";
144
+ }
145
+ };
146
+ }
147
+
148
+ #endif
data/test/headers/enums.h CHANGED
@@ -15,6 +15,16 @@ namespace enums {
15
15
  VALUE3
16
16
  };
17
17
 
18
+ enum {
19
+ OUTER_ANON_1,
20
+ OUTER_ANON_2,
21
+ FOURTY_TWO = 42
22
+ };
23
+
24
+ enum {
25
+ SEPERATE_OUTER_VALUE = 14
26
+ };
27
+
18
28
  namespace inner {
19
29
  enum InnerEnum {
20
30
  INNER_1,
@@ -29,6 +39,16 @@ namespace enums {
29
39
  }
30
40
 
31
41
  class Tester {
42
+ enum NotWrapped {
43
+ I_IS_PRIVATE
44
+ };
45
+
46
+ protected:
47
+
48
+ enum AlsoNotWrapped {
49
+ CAUSE_I_IS_PROT
50
+ };
51
+
32
52
  public:
33
53
  Tester() {}
34
54
 
@@ -38,6 +58,19 @@ namespace enums {
38
58
  I_LIKE_YOU = 7
39
59
  };
40
60
 
61
+ /*
62
+ * Anonymous Enums
63
+ */
64
+ enum {
65
+ ANON_ENUM_VAL1 = 1
66
+ };
67
+
68
+ enum {
69
+ ANON_ENUM_VAL2 = 2,
70
+ ANON_ENUM_VAL3 = 5,
71
+ ANON_ENUM_VAL4 = 3
72
+ };
73
+
41
74
  std::string getEnumDescription(MyEnum e) {
42
75
  std::string ret;
43
76
  switch(e) {
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Code to wrap and handle function callbacks by exposing them
3
+ * into Ruby as block arguments
4
+ */
5
+ #ifndef __FUNCTION_POINTERS_H__
6
+ #define __FUNCTION_POINTERS_H__
7
+
8
+ namespace function_pointers {
9
+
10
+ // One that takes no argument, no return
11
+ typedef void(*Callback) (void);
12
+ Callback emptyCallback;
13
+
14
+ void setCallback(Callback cb) { emptyCallback = cb; }
15
+ void callCallback() { emptyCallback(); }
16
+
17
+ // With an argument, no return
18
+ typedef void(*ArgCallback) (int num);
19
+ ArgCallback argumentCallback;
20
+
21
+ void setCallbackWithArgs(ArgCallback cb) { argumentCallback = cb; }
22
+ void callCallbackWithArgs(int in) { argumentCallback(in); }
23
+
24
+ // With argument and returns a value
25
+ typedef int(*ReturnCallback) (int num);
26
+ ReturnCallback returnCallback;
27
+
28
+ void setCallbackReturns(ReturnCallback cb) { returnCallback = cb; }
29
+ int callCallbackReturns(int in) { return returnCallback(in); }
30
+ }
31
+
32
+ #endif