rbplusplus 0.8 → 0.9

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.
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
@@ -1,93 +0,0 @@
1
- module RbPlusPlus
2
- module Builders
3
-
4
- # This is a singleton class that takes care of handling any to_ruby and from_ruby
5
- # definitions this wrapper might need. This is pulled out seperate from other builders
6
- # because of C++ coding and compiling restrictions. Mainly,
7
- #
8
- # 1. All cpp/hpp files where Rice needs to know about a given type needs to know about any to_/from_ruby definitions of that type
9
- # 2. The actual definition of these methods can only be in one place or we get compiler redefinition errors.
10
- class TypesManager
11
- include Singleton
12
-
13
- # Forward off all calls to the singleton instance of this method.
14
- # This allows one to use this class as if it's a bunch of class methods. E.g.:
15
- #
16
- # TypesManager.build_const_converter(type)
17
- #
18
- def self.method_missing(method, *args)
19
- if TypesManager.instance.respond_to?(method)
20
- TypesManager.instance.send(method, *args)
21
- else
22
- super
23
- end
24
- end
25
-
26
- attr_accessor :body, :prototypes, :includes
27
-
28
- def initialize
29
- @consts_wrapped = []
30
- @body = []
31
- @prototypes = []
32
- @includes = []
33
- end
34
-
35
- # Some libraries have really bad namespace declarations
36
- # so we allow for 2 methods of including files
37
- # 1. trace the class definition to the parent file
38
- # 2. explicitly declare which files to include in every generated source
39
- #
40
- def add_include_for(type)
41
- file = type.file_name(false)
42
- if Base.sources.include? file
43
- @includes << "#include \"#{file}\""
44
- else
45
- Base.sources.each do |header|
46
- @includes << "#include \"#{header}\""
47
- end
48
- end
49
- end
50
-
51
- # Rice doesn't automatically handle all to_ / from_ruby conversions for a given type.
52
- # A common construct is the +const Type&+ variable, which we need to manually handle.
53
- def build_const_converter(type)
54
- type = type.is_a?(RbGCCXML::Type) ? type.base_type : type
55
-
56
- # Don't need to deal with fundamental types
57
- return if type.is_a?(RbGCCXML::FundamentalType)
58
-
59
- full_name = type.qualified_name
60
-
61
- # Only wrap once
62
- # TODO cleaner way of doing this
63
- return if @consts_wrapped.include?(full_name)
64
-
65
- # Some types are already handled by Rice, ignore such types
66
- return if full_name =~ /std::string/
67
-
68
- @consts_wrapped << full_name
69
-
70
- # Enumerations are handled slightly differently
71
- class_type = if type.is_a?(RbGCCXML::Enumeration)
72
- "new #{full_name}(a)"
73
- else
74
- "(#{full_name} *)&a"
75
- end
76
-
77
- @includes << "#include <rice/Object.hpp>"
78
- @includes << "#include <rice/Data_Object.hpp>"
79
- @includes << "#include <rice/Data_Type.hpp>"
80
- add_include_for type
81
-
82
- @body << "template<>"
83
- @body << "Rice::Object to_ruby<#{full_name} >(#{full_name} const & a) {"
84
- @body << "\treturn Rice::Data_Object<#{full_name} >(#{class_type}, Rice::Data_Type<#{full_name} >::klass(), 0, 0);"
85
- @body << "}"
86
-
87
- @prototypes << "template<>"
88
- @prototypes << "Rice::Object to_ruby<#{full_name} >(#{full_name} const & a);"
89
- end
90
-
91
- end
92
- end
93
- end
@@ -1,4 +0,0 @@
1
- module RbGCCXML
2
- class Constructor #:nodoc:
3
- end
4
- end
@@ -1,71 +0,0 @@
1
- module RbPlusPlus
2
- class RbModule
3
- # Helper function for moving pieces of an API into other Ruby locations, eg from a Class to a Module,
4
- # from global functions to a Class, or from Module to Module.
5
- #
6
- # Module may include Functions
7
- # e.module "System" do |m|
8
- # m.includes node.functions("print").wrap_as("puts") # Moves the ::print function into the System module
9
- #
10
- # m.include node.classes("Vector3") # Explicitly put Vector3 class in the System module
11
- # end
12
- #
13
- def includes(val)
14
- if is_a?(val, RbGCCXML::Function)
15
- reference_function(val)
16
- elsif is_a?(val, RbGCCXML::Class)
17
- reference_class(val)
18
- elsif is_a?(val, RbGCCXML::Struct)
19
- reference_struct(val)
20
- else
21
- raise "Cannot use #{self.class}#includes for type '#{val.class}'"
22
- end
23
- end
24
-
25
- def functions #:nodoc:
26
- functions = @functions || []
27
- functions << @node.functions if @node
28
- functions.flatten
29
- end
30
-
31
- def classes #:nodoc:
32
- classes = @classes || []
33
- classes << @node.classes if @node
34
- classes.flatten
35
- end
36
-
37
- def structs #:nodoc:
38
- structs = @structs || []
39
- structs << @node.structs if @node
40
- structs.flatten
41
- end
42
-
43
- private
44
-
45
- # Map a function from a different namespace
46
- def reference_function(val) #:nodoc:
47
- @functions ||= []
48
- @functions << NodeReference.new(val)
49
- val.moved=true
50
- end
51
-
52
- # Map a class from a different namespace
53
- def reference_class(val) #:nodoc:
54
- @classes ||= []
55
- @classes << NodeReference.new(val)
56
- val.moved=true
57
- end
58
-
59
- def reference_struct(val) #:nodoc:
60
- @structs ||= []
61
- @structs << NodeReference.new(val)
62
- val.moved=true
63
- end
64
-
65
- def is_a?(val, klass) #:nodoc:
66
- return true if val.is_a?(klass)
67
- return true if val.is_a?(NodeReference) && val.references?(klass)
68
- return false
69
- end
70
- end
71
- end
@@ -1,30 +0,0 @@
1
- module RbPlusPlus
2
- class NodeReference #:nodoc:
3
- # Takes the delegate object as input
4
- def initialize(from)
5
- @delegate = from
6
- end
7
-
8
- # Delegate
9
- def method_missing(name, *args)
10
- @delegate.send name, *args
11
- end
12
-
13
- # Always false
14
- def moved?
15
- false
16
- end
17
-
18
- # Delegate
19
- def methods(*args)
20
- @delegate.methods *args
21
- end
22
-
23
- # Returns true if the class references the specified class
24
- def references?(klass)
25
- return true if @delegate.is_a?(klass)
26
- return true if @delegate.is_a?(NodeReference) && @delegate.references?(klass)
27
- return false
28
- end
29
- end
30
- end
@@ -1,18 +0,0 @@
1
- #ifndef UGLY_HELPER
2
- #define UGLY_HELPER
3
-
4
- #include "rice/Class.hpp"
5
- #include "rice/Data_Type.hpp"
6
- #include "rice/Constructor.hpp"
7
- #include "rice/Enum.hpp"
8
- #include "rice/to_from_ruby.hpp"
9
- #include "rice/Address_Registration_Guard.hpp"
10
-
11
- #include <ruby.h>
12
- #include "ugly_interface_ns.h"
13
-
14
- inline UI::C_UIVector *newInstanceButBetter(Rice::Object *self) {
15
- return new UI::C_UIVector();
16
- }
17
-
18
- #endif
@@ -1,44 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- context "Object Persistence" do
4
-
5
- def validate(node)
6
- namespaces = node.namespaces
7
-
8
- node.namespaces.each_with_index do |n, i|
9
-
10
- #puts "#{node.name}::#{n.name}"
11
- namespaces[i].object_id.should == n.object_id
12
-
13
- classes = n.classes
14
- classes.each_with_index do |cls, j|
15
- namespaces[i].classes[j].object_id.should == cls.object_id
16
-
17
- methods = cls.methods
18
- methods.each_with_index do |m, k|
19
- #puts "#{n.name}::#{cls.name}::#{m.name}"
20
- namespaces[i].classes[j].methods[k].object_id.should == m.object_id
21
- end
22
- end
23
-
24
- functions = n.functions
25
- functions.each_with_index do |funct, j|
26
- # puts "#{n.name}::#{funct.name}"
27
- namespaces[i].functions[j].object_id.should == funct.object_id
28
- end
29
-
30
- validate n
31
- end
32
-
33
- end
34
-
35
- specify "seperate query should lazy initialize objects" do
36
- Extension.new "ui" do |e|
37
- e.sources full_dir("headers/ugly_interface_ns.h")
38
- node = e.namespace("UI")
39
- validate(node)
40
- end
41
- end
42
- end
43
-
44
-