rice 4.7.1 → 4.9.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -1
- data/CMakeLists.txt +14 -22
- data/CMakePresets.json +203 -75
- data/FindRuby.cmake +358 -123
- data/bin/rice-doc.rb +58 -141
- data/include/rice/api.hpp +261 -0
- data/include/rice/rice.hpp +2459 -1693
- data/include/rice/stl.hpp +450 -546
- data/lib/rice/doc/config.rb +70 -0
- data/lib/rice/doc/cpp_reference.rb +1 -4
- data/lib/rice/doc/mkdocs.rb +58 -20
- data/lib/rice/doc/rice.rb +21 -0
- data/lib/rice/doc.rb +1 -0
- data/lib/rice/make_rice_headers.rb +7 -0
- data/lib/rice/native_registry.rb +5 -10
- data/lib/rice/rbs.rb +6 -6
- data/lib/rice/version.rb +1 -1
- data/lib/rubygems_plugin.rb +12 -9
- data/rice/Arg.hpp +12 -6
- data/rice/Arg.ipp +14 -7
- data/rice/Buffer.ipp +44 -40
- data/rice/Callback.hpp +1 -1
- data/rice/Callback.ipp +2 -7
- data/rice/Constructor.hpp +1 -1
- data/rice/Constructor.ipp +11 -11
- data/rice/Data_Object.ipp +15 -15
- data/rice/Data_Type.hpp +9 -10
- data/rice/Data_Type.ipp +33 -31
- data/rice/Director.hpp +1 -0
- data/rice/Enum.ipp +58 -39
- data/rice/Exception.hpp +4 -4
- data/rice/Exception.ipp +7 -7
- data/rice/NoGVL.hpp +13 -0
- data/rice/Reference.hpp +56 -0
- data/rice/Reference.ipp +96 -0
- data/rice/Return.hpp +4 -1
- data/rice/Return.ipp +0 -6
- data/rice/cpp_api/Array.hpp +41 -4
- data/rice/cpp_api/Array.ipp +105 -9
- data/rice/cpp_api/Class.hpp +7 -2
- data/rice/cpp_api/Class.ipp +9 -4
- data/rice/cpp_api/Hash.ipp +7 -4
- data/rice/cpp_api/Module.hpp +4 -4
- data/rice/cpp_api/Module.ipp +12 -10
- data/rice/cpp_api/Object.hpp +10 -4
- data/rice/cpp_api/Object.ipp +20 -12
- data/rice/cpp_api/String.hpp +2 -2
- data/rice/cpp_api/String.ipp +11 -8
- data/rice/cpp_api/Symbol.ipp +7 -7
- data/rice/cpp_api/shared_methods.hpp +5 -9
- data/rice/detail/Forwards.hpp +18 -0
- data/rice/detail/Forwards.ipp +60 -0
- data/rice/detail/InstanceRegistry.hpp +0 -2
- data/rice/detail/Native.hpp +31 -21
- data/rice/detail/Native.ipp +282 -130
- data/rice/detail/NativeAttributeGet.hpp +5 -7
- data/rice/detail/NativeAttributeGet.ipp +26 -26
- data/rice/detail/NativeAttributeSet.hpp +2 -4
- data/rice/detail/NativeAttributeSet.ipp +20 -16
- data/rice/detail/NativeCallback.hpp +77 -0
- data/rice/detail/NativeCallback.ipp +280 -0
- data/rice/detail/NativeFunction.hpp +11 -21
- data/rice/detail/NativeFunction.ipp +58 -119
- data/rice/detail/NativeInvoker.hpp +4 -4
- data/rice/detail/NativeInvoker.ipp +7 -7
- data/rice/detail/NativeIterator.hpp +2 -4
- data/rice/detail/NativeIterator.ipp +18 -14
- data/rice/detail/NativeMethod.hpp +10 -20
- data/rice/detail/NativeMethod.ipp +54 -114
- data/rice/detail/NativeProc.hpp +5 -7
- data/rice/detail/NativeProc.ipp +39 -28
- data/rice/detail/NativeRegistry.hpp +1 -1
- data/rice/detail/NativeRegistry.ipp +29 -0
- data/rice/detail/Parameter.hpp +15 -8
- data/rice/detail/Parameter.ipp +102 -43
- data/rice/detail/Proc.ipp +14 -28
- data/rice/detail/RubyType.ipp +2 -53
- data/rice/detail/Type.hpp +23 -7
- data/rice/detail/Type.ipp +77 -93
- data/rice/detail/TypeRegistry.ipp +5 -4
- data/rice/detail/Wrapper.hpp +13 -12
- data/rice/detail/Wrapper.ipp +97 -44
- data/rice/detail/from_ruby.hpp +8 -6
- data/rice/detail/from_ruby.ipp +306 -173
- data/rice/detail/ruby.hpp +23 -0
- data/rice/libc/file.hpp +4 -4
- data/rice/rice.hpp +9 -8
- data/rice/rice_api/Native.ipp +5 -1
- data/rice/rice_api/NativeRegistry.ipp +14 -1
- data/rice/rice_api/Parameter.ipp +1 -1
- data/rice/ruby_mark.hpp +2 -1
- data/rice/stl/complex.ipp +12 -8
- data/rice/stl/map.ipp +27 -22
- data/rice/stl/monostate.ipp +16 -12
- data/rice/stl/multimap.hpp +0 -2
- data/rice/stl/multimap.ipp +27 -22
- data/rice/stl/optional.ipp +27 -11
- data/rice/stl/pair.ipp +5 -5
- data/rice/stl/reference_wrapper.ipp +5 -4
- data/rice/stl/set.ipp +16 -16
- data/rice/stl/shared_ptr.hpp +9 -9
- data/rice/stl/shared_ptr.ipp +52 -185
- data/rice/stl/string.ipp +18 -18
- data/rice/stl/string_view.ipp +1 -1
- data/rice/stl/tuple.ipp +15 -36
- data/rice/stl/unique_ptr.hpp +9 -3
- data/rice/stl/unique_ptr.ipp +86 -120
- data/rice/stl/unordered_map.ipp +20 -15
- data/rice/stl/variant.ipp +37 -21
- data/rice/stl/vector.ipp +41 -36
- data/rice/traits/function_traits.hpp +19 -19
- data/rice/traits/method_traits.hpp +4 -4
- data/rice/traits/rice_traits.hpp +162 -39
- data/rice.gemspec +1 -3
- data/test/test_Array.cpp +261 -3
- data/test/test_Attribute.cpp +6 -3
- data/test/test_Buffer.cpp +6 -42
- data/test/test_Callback.cpp +77 -23
- data/test/test_Data_Object.cpp +1 -1
- data/test/test_Data_Type.cpp +21 -22
- data/test/test_Director.cpp +2 -4
- data/test/test_Enum.cpp +34 -5
- data/test/test_File.cpp +9 -5
- data/test/test_From_Ruby.cpp +4 -3
- data/test/test_GVL.cpp +3 -3
- data/test/test_Hash.cpp +1 -1
- data/test/test_Inheritance.cpp +14 -14
- data/test/test_Iterator.cpp +54 -22
- data/test/test_Keep_Alive.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +7 -3
- data/test/test_Module.cpp +5 -5
- data/test/test_Overloads.cpp +345 -48
- data/test/test_Proc.cpp +54 -0
- data/test/test_Reference.cpp +181 -0
- data/test/test_Self.cpp +2 -2
- data/test/test_Stl_Set.cpp +6 -6
- data/test/test_Stl_SharedPtr.cpp +172 -33
- data/test/test_Stl_String_View.cpp +4 -2
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +48 -3
- data/test/test_Stl_Variant.cpp +6 -14
- data/test/test_Stl_Vector.cpp +61 -30
- data/test/test_String.cpp +4 -2
- data/test/test_Struct.cpp +1 -1
- data/test/test_Symbol.cpp +1 -1
- data/test/test_To_Ruby.cpp +1 -0
- data/test/test_Type.cpp +36 -35
- data/test/test_global_functions.cpp +1 -1
- data/test/unittest.cpp +1 -1
- data/test/unittest.hpp +5 -5
- metadata +12 -10
- data/rice/Function.hpp +0 -17
- data/rice/Function.ipp +0 -13
- data/rice/detail/MethodInfo.hpp +0 -48
- data/rice/detail/MethodInfo.ipp +0 -99
- data/rice/detail/NativeCallbackFFI.hpp +0 -55
- data/rice/detail/NativeCallbackFFI.ipp +0 -152
- data/rice/detail/NativeCallbackSimple.hpp +0 -30
- data/rice/detail/NativeCallbackSimple.ipp +0 -29
data/bin/rice-doc.rb
CHANGED
|
@@ -13,67 +13,74 @@ module Rice
|
|
|
13
13
|
# Generates Mkdocs for a Rice extension
|
|
14
14
|
#
|
|
15
15
|
# == Usage
|
|
16
|
-
# rice-doc [options] <
|
|
16
|
+
# rice-doc [options] <config_file>
|
|
17
17
|
#
|
|
18
18
|
# Options:
|
|
19
|
-
# -
|
|
20
|
-
# -v, --version Show version (1.1.0)
|
|
19
|
+
# -v, --version Show version
|
|
21
20
|
# -h, --help Show help message
|
|
22
21
|
|
|
23
22
|
class Cmd
|
|
24
|
-
# :enddoc:
|
|
25
23
|
attr_accessor :options
|
|
26
24
|
|
|
27
25
|
def option_parser
|
|
28
26
|
OptionParser.new do |opts|
|
|
29
27
|
opts.banner = "rice-doc #{Rice::VERSION}\n" +
|
|
30
|
-
"Usage: rice-doc [options] <
|
|
28
|
+
"Usage: rice-doc [options] <config_file.yaml>"
|
|
31
29
|
|
|
32
30
|
opts.separator ""
|
|
33
31
|
opts.separator "Options:"
|
|
34
32
|
|
|
35
|
-
opts.
|
|
36
|
-
|
|
37
|
-
options.output = File.expand_path(dir)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
opts.on_tail("-v version", "--version", "Show version (#{Rice::VERSION})") do
|
|
41
|
-
puts "ruby_prof " + Rice::VERSION
|
|
33
|
+
opts.on_tail("-v", "--version", "Show version (#{Rice::VERSION})") do
|
|
34
|
+
puts "rice-doc " + Rice::VERSION
|
|
42
35
|
exit
|
|
43
36
|
end
|
|
44
37
|
|
|
45
38
|
opts.on_tail("-h", "--help", "Show help message") do
|
|
46
39
|
puts opts
|
|
40
|
+
puts ""
|
|
41
|
+
puts "Config file format (YAML):"
|
|
42
|
+
puts " extension: path/to/extension.so"
|
|
43
|
+
puts " output: ./docs/api"
|
|
44
|
+
puts " resolvers:"
|
|
45
|
+
puts " Std:"
|
|
46
|
+
puts " type: cppreference"
|
|
47
|
+
puts " MyNamespace:"
|
|
48
|
+
puts " type: doxygen"
|
|
49
|
+
puts " root: https://example.com/docs"
|
|
50
|
+
puts " tagfile: https://example.com/docs/tagfile.xml"
|
|
51
|
+
puts " type_mappings:"
|
|
52
|
+
puts " - pattern: \"^enum\\\\s*\""
|
|
53
|
+
puts " replacement: \"\""
|
|
54
|
+
puts " method_mappings:"
|
|
55
|
+
puts " MyNamespace::MyClass:"
|
|
56
|
+
puts " ruby_method: cppMethod"
|
|
57
|
+
puts ""
|
|
58
|
+
puts "Note: Ruby core types are automatically linked to docs.ruby-lang.org"
|
|
47
59
|
exit
|
|
48
60
|
end
|
|
49
61
|
end
|
|
50
62
|
end
|
|
51
63
|
|
|
52
64
|
def parse_args
|
|
53
|
-
@options = Struct.new(:
|
|
54
|
-
options.
|
|
55
|
-
|
|
65
|
+
@options = Struct.new(:config_file).new
|
|
66
|
+
options.config_file = nil
|
|
67
|
+
|
|
68
|
+
self.option_parser.parse! ARGV
|
|
56
69
|
|
|
57
|
-
|
|
58
|
-
if ARGV.length < 1 and not options.exec
|
|
70
|
+
if ARGV.length < 1
|
|
59
71
|
puts self.option_parser
|
|
60
72
|
puts ""
|
|
61
|
-
puts "Must specify a
|
|
73
|
+
puts "Must specify a config file"
|
|
62
74
|
exit(-1)
|
|
63
75
|
end
|
|
64
76
|
|
|
65
|
-
|
|
77
|
+
options.config_file = ARGV.shift
|
|
66
78
|
|
|
67
|
-
|
|
68
|
-
puts "
|
|
79
|
+
unless File.exist?(options.config_file)
|
|
80
|
+
puts "Config file not found: #{options.config_file}"
|
|
69
81
|
exit(-1)
|
|
70
|
-
elsif !Dir.exist?(options.output)
|
|
71
|
-
puts "Creating output directory '#{options.output}'"
|
|
72
|
-
Dir.mkdir(options.output)
|
|
73
82
|
end
|
|
74
83
|
|
|
75
|
-
options.extension = ARGV.shift
|
|
76
|
-
|
|
77
84
|
options
|
|
78
85
|
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, OptionParser::MissingArgument => e
|
|
79
86
|
puts self.option_parser
|
|
@@ -87,125 +94,35 @@ end
|
|
|
87
94
|
cmd = Rice::Cmd.new
|
|
88
95
|
options = cmd.parse_args
|
|
89
96
|
|
|
97
|
+
# Load configuration
|
|
98
|
+
config = Rice::Doc::Config.new(options.config_file)
|
|
99
|
+
|
|
100
|
+
# Validate configuration
|
|
101
|
+
if config.extension.nil?
|
|
102
|
+
puts "Config file must specify 'extension'"
|
|
103
|
+
exit(-1)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
if config.output.nil?
|
|
107
|
+
puts "Config file must specify 'output'"
|
|
108
|
+
exit(-1)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Create output directory if needed
|
|
112
|
+
unless Dir.exist?(config.output)
|
|
113
|
+
puts "Creating output directory '#{config.output}'"
|
|
114
|
+
FileUtils.mkdir_p(config.output)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Add the extension directory the path in case it ships with extra libraries
|
|
118
|
+
ENV["PATH"] = "#{File.dirname(config.extension)}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
|
|
90
119
|
# Load the extension
|
|
91
|
-
require
|
|
120
|
+
require config.extension
|
|
92
121
|
|
|
93
122
|
# Get modules and classes
|
|
94
123
|
modules = Rice::Registries.instance.modules.modules
|
|
95
124
|
klasses = Rice::Registries.instance.types.klasses
|
|
96
125
|
|
|
97
|
-
#
|
|
98
|
-
|
|
99
|
-
doxygen_index = "https://docs.opencv.org/4.x/opencv.tag"
|
|
100
|
-
#doxygen_index = "c:/Users/cfis/Downloads/opencv.tag"
|
|
101
|
-
type_mappings = {/^enum\s*/i => '',
|
|
102
|
-
/^union\s*/i => '',
|
|
103
|
-
/<.*>/ => '',
|
|
104
|
-
'::debug_build_guard' => ''}
|
|
105
|
-
|
|
106
|
-
method_mappings = {'Cv' => {'agast' => 'AGAST',
|
|
107
|
-
'approx_poly_dp' => 'approxPolyDP',
|
|
108
|
-
'calc_optical_flow_pyr_lk' => 'calcOpticalFlowPyrLK',
|
|
109
|
-
'calibrate_camera_ro' => 'calibrateCameraRO',
|
|
110
|
-
'cam_shift' => 'CamShift',
|
|
111
|
-
'compose_rt' => 'composeRT',
|
|
112
|
-
'compute_ecc' => 'computeECC',
|
|
113
|
-
'create_clahe' => 'createCLAHE',
|
|
114
|
-
'current_ui_framework' => 'currentUIFramework',
|
|
115
|
-
'create_align_mtb' => 'createAlignMTB',
|
|
116
|
-
'create_background_subtractor_knn' => 'createBackgroundSubtractorKNN',
|
|
117
|
-
'create_background_subtractor_mog2' => 'createBackgroundSubtractorMOG2',
|
|
118
|
-
'denoise_tvl1' => 'denoise_TVL1',
|
|
119
|
-
'emd' => 'EMD',
|
|
120
|
-
'estimate_affine_2d' => 'estimateAffine2D',
|
|
121
|
-
'estimate_affine_partial_2d' => 'estimateAffinePartial2D',
|
|
122
|
-
'fast' => 'FAST',
|
|
123
|
-
'filter_2d' => 'filter2D',
|
|
124
|
-
'find_chessboard_corners_sb?' => 'findChessboardCornersSB',
|
|
125
|
-
'find_transform_ecc' => 'findTransformECC',
|
|
126
|
-
'fit_ellipse_ams' => 'fitEllipseAMS',
|
|
127
|
-
'flip_nd' => 'flipND',
|
|
128
|
-
'gaussian_blur' => 'GaussianBlur',
|
|
129
|
-
'get_cpu_features_line' => 'getCPUFeaturesLine',
|
|
130
|
-
'get_cpu_tick_count' => 'getCPUTickCount',
|
|
131
|
-
'get_number_of_cp_us' => 'getNumberOfCPUs',
|
|
132
|
-
'get_optimal_dft_size' => 'getOptimalDFTSize',
|
|
133
|
-
'get_rotation_matrix_2d' => 'getRotationMatrix2D',
|
|
134
|
-
'get_valid_disparity_roi' => 'getValidDisparityROI',
|
|
135
|
-
'group_rectangles_meanshift' => 'groupRectangles_meanshift',
|
|
136
|
-
'have_open_vx?' => 'haveOpenVX',
|
|
137
|
-
'hough_circles' => 'HoughCircles',
|
|
138
|
-
'hough_lines' => 'HoughLines',
|
|
139
|
-
'hough_lines_p' => 'HoughLinesP',
|
|
140
|
-
'hough_lines_point_set' => 'HoughLinesPointSet',
|
|
141
|
-
'hu_moments' => 'HuMoments',
|
|
142
|
-
'init_camera_matrix_2d' => 'initCameraMatrix2D',
|
|
143
|
-
'lu' => 'LU',
|
|
144
|
-
'lut' => 'LUT',
|
|
145
|
-
'pca_back_project' => 'PCABackProject',
|
|
146
|
-
'pca_compute' => 'PCACompute',
|
|
147
|
-
'pca_project' => 'PCAProject',
|
|
148
|
-
'psnr' => 'PSNR',
|
|
149
|
-
'rq_decomp3x3' => 'RQDecomp3x3',
|
|
150
|
-
'select_roi ' => 'selectROI',
|
|
151
|
-
'sep_filter_2d' => 'sepFilter2D',
|
|
152
|
-
'set_rng_seed' => 'setRNGSeed',
|
|
153
|
-
'set_use_open_vx' => 'setUseOpenVX',
|
|
154
|
-
'solve_lp' => 'solveLP',
|
|
155
|
-
'solve_pn_p_refine_lm' => 'solvePnPRefineLM',
|
|
156
|
-
'solve_pn_p_refine_vvs' => 'solvePnPRefineVVS',
|
|
157
|
-
'sv_back_subst' => 'SVBackSubst',
|
|
158
|
-
'sv_decomp' => 'SVDecomp',
|
|
159
|
-
'the_rng' => 'theRNG',
|
|
160
|
-
'transpose_nd' => 'transposeND',
|
|
161
|
-
'use_open_vx?' => 'useOpenVX',
|
|
162
|
-
'wrapper_emd' => 'wrapperEMD'},
|
|
163
|
-
'Cv::AsyncArray' => {'_get_impl' => '_getImpl',
|
|
164
|
-
'wait_for?' => 'wait_for'},
|
|
165
|
-
'Cv::BackgroundSubtractorKNN' => {'getk_nn_samples' => 'getkNNSamples',
|
|
166
|
-
'setk_nn_samples' => 'setkNNSamples'},
|
|
167
|
-
'Cv::Cuda::DeviceInfo' => {'device_id' => 'deviceID',
|
|
168
|
-
'ecc_enabled?' => 'ECCEnabled',
|
|
169
|
-
'max_surface_2d' => 'maxSurface2D',
|
|
170
|
-
'max_texture_2d' => 'maxTexture2D',
|
|
171
|
-
'pci_bus_id' => 'pciBusID',
|
|
172
|
-
'pci_device_id' => 'pciDeviceID',
|
|
173
|
-
'pci_domain_id' => 'pciDomainID'},
|
|
174
|
-
'Cv::Cuda::GpuMat' => {'adjust_roi' => 'adjustROI',
|
|
175
|
-
'locate_roi' => 'locateROI'},
|
|
176
|
-
'Cv::Cuda::GpuMatND' => {'to_gpu_mat' => 'operator GpuMat'},
|
|
177
|
-
'Cv::FaceDetectorYN' => {'get_nms_threshold' => 'getNMSThreshold'},
|
|
178
|
-
'Cv::FaceRecognizerSF' => {'set_nms_threshold' => 'setNMSThreshold'},
|
|
179
|
-
'Cv::HOGDescriptor' => {'detect_multi_scale_roi' => 'detectMultiScaleROI',
|
|
180
|
-
'detect_roi' => 'detectROI'},
|
|
181
|
-
'Cv::HOGDescriptor::DescriptorStorageFormat' => {'set_svm_detector' => 'setSVMDetector'},
|
|
182
|
-
'Cv::Hfloat' => {'to_float' => 'operator float'},
|
|
183
|
-
'Cv::Mat' => {'locate_roi' => 'locateROI'},
|
|
184
|
-
'Cv::Ml::ANN_MLP' => {'get_rprop_dw0' => 'getRpropDW0',
|
|
185
|
-
'get_rprop_dw_max' => 'getRpropDWMax',
|
|
186
|
-
'get_rprop_dw_min' => 'getRpropDWMin',
|
|
187
|
-
'get_rprop_dw_minus' => 'getRpropDWMinus',
|
|
188
|
-
'get_rprop_dw_plus' => 'getRpropDWPlus',
|
|
189
|
-
'set_anneal_energy_rng' => 'setAnnealEnergyRNG',
|
|
190
|
-
'set_rprop_dw0' => 'setRpropDW0',
|
|
191
|
-
'set_rprop_dw_max' => 'setRpropDWMax',
|
|
192
|
-
'set_rprop_dw_min' => 'setRpropDWMin',
|
|
193
|
-
'set_rprop_dw_minus' => 'setRpropDWMinus',
|
|
194
|
-
'set_rprop_dw_plus' => 'setRpropDWPlus'},
|
|
195
|
-
'Cv::Ml::DTrees' => {'get_cv_folds' => 'getCVFolds',
|
|
196
|
-
'get_use1_se_rule?' => 'getUse1SERule',
|
|
197
|
-
'set_cv_folds' => 'setCVFolds',
|
|
198
|
-
'set_use1_se_rule' => 'setUse1SERule'},
|
|
199
|
-
'Cv::Ml::RTrees' => {'get_oob_error' => 'getOOBError'}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
doxygen_resolver = Rice::Doc::Doxygen.new(doxygen_root, doxygen_index, type_mappings, method_mappings)
|
|
203
|
-
|
|
204
|
-
# Setup resolvers per namespace
|
|
205
|
-
resolvers = {nil => Rice::Doc::Ruby.new,
|
|
206
|
-
'Cv' => doxygen_resolver,
|
|
207
|
-
'Rice' => Rice::Doc::Rice.new,
|
|
208
|
-
'Std' => Rice::Doc::CppReference.new}
|
|
209
|
-
|
|
210
|
-
generator = Rice::Doc::Mkdocs.new(modules + klasses, resolvers, options.output)
|
|
126
|
+
# Generate documentation
|
|
127
|
+
generator = Rice::Doc::Mkdocs.new(modules + klasses, config.resolvers, config.output)
|
|
211
128
|
generator.generate
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// This file is part of [rice](https://github.com/ruby-rice/rice).
|
|
2
|
+
//
|
|
3
|
+
// Copyright (C) 2025 Jason Roelofs <jasongroelofs@gmail.com>
|
|
4
|
+
// Paul Brannan <curlypaul924@gmail.com>,
|
|
5
|
+
// Charlie Savage
|
|
6
|
+
//
|
|
7
|
+
// Redistribution and use in source and binary forms, with or without
|
|
8
|
+
// modification, are permitted provided that the following conditions
|
|
9
|
+
// are met:
|
|
10
|
+
//
|
|
11
|
+
// 1. Redistributions of source code must retain the above copyright
|
|
12
|
+
// notice, this list of conditions and the following disclaimer.
|
|
13
|
+
// 2. Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
// documentation and/or other materials provided with the distribution.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
18
|
+
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
19
|
+
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
20
|
+
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
+
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
22
|
+
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
24
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26
|
+
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
28
|
+
#ifndef Rice__Api_hpp_
|
|
29
|
+
#define Rice__Api_hpp_
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// ========= ModuleRegistry.hpp =========
|
|
33
|
+
#ifndef Rice_Api_Module_Registry_hpp
|
|
34
|
+
#define Rice_Api_Module_Registry_hpp
|
|
35
|
+
|
|
36
|
+
extern "C"
|
|
37
|
+
void Init_Module_Registry();
|
|
38
|
+
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
// ========= ModuleRegistry.ipp =========
|
|
42
|
+
using namespace Rice;
|
|
43
|
+
|
|
44
|
+
extern "C"
|
|
45
|
+
void Init_Module_Registry()
|
|
46
|
+
{
|
|
47
|
+
Module rb_mRice = define_module("Rice");
|
|
48
|
+
|
|
49
|
+
Rice::define_class_under<detail::ModuleRegistry>(rb_mRice, "ModuleRegistry").
|
|
50
|
+
define_method("modules", &detail::ModuleRegistry::modules, Return().setValue());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ========= NativeRegistry.hpp =========
|
|
54
|
+
#ifndef Rice_Api_Native_Registry_hpp
|
|
55
|
+
#define Rice_Api_Native_Registry_hpp
|
|
56
|
+
|
|
57
|
+
extern "C"
|
|
58
|
+
void Init_Native_Registry();
|
|
59
|
+
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
// ========= NativeRegistry.ipp =========
|
|
63
|
+
using namespace Rice;
|
|
64
|
+
|
|
65
|
+
extern "C"
|
|
66
|
+
inline void Init_Native_Registry()
|
|
67
|
+
{
|
|
68
|
+
Module rb_mRice = define_module("Rice");
|
|
69
|
+
|
|
70
|
+
Rice::define_class_under<detail::NativeRegistry>(rb_mRice, "NativeRegistry").
|
|
71
|
+
define_method("lookup", [](detail::NativeRegistry& self, VALUE klass) -> Array
|
|
72
|
+
{
|
|
73
|
+
Array result;
|
|
74
|
+
|
|
75
|
+
const std::vector<detail::Native*> natives = self.lookup(klass);
|
|
76
|
+
for (detail::Native* native : natives)
|
|
77
|
+
{
|
|
78
|
+
result.push(native, false);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return result;
|
|
82
|
+
}, Arg("klass").setValue()).
|
|
83
|
+
|
|
84
|
+
define_method("lookup_by_kind", [](detail::NativeRegistry& self, VALUE klass, detail::NativeKind kind) -> Array
|
|
85
|
+
{
|
|
86
|
+
Array result;
|
|
87
|
+
|
|
88
|
+
const std::vector<detail::Native*> natives = self.lookup(klass, kind);
|
|
89
|
+
for (detail::Native* native : natives)
|
|
90
|
+
{
|
|
91
|
+
result.push(native, false);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return result;
|
|
95
|
+
}, Arg("klass").setValue(), Arg("kind"));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ========= TypeRegistry.hpp =========
|
|
99
|
+
#ifndef Rice_Api_Type_Registry_hpp
|
|
100
|
+
#define Rice_Api_Type_Registry_hpp
|
|
101
|
+
|
|
102
|
+
extern "C"
|
|
103
|
+
void Init_Type_Registry();
|
|
104
|
+
|
|
105
|
+
#endif
|
|
106
|
+
|
|
107
|
+
// ========= TypeRegistry.ipp =========
|
|
108
|
+
using namespace Rice;
|
|
109
|
+
|
|
110
|
+
extern "C"
|
|
111
|
+
void Init_Type_Registry()
|
|
112
|
+
{
|
|
113
|
+
Module rb_mRice = define_module("Rice");
|
|
114
|
+
|
|
115
|
+
Rice::define_class_under<detail::TypeRegistry>(rb_mRice, "TypeRegistry").
|
|
116
|
+
define_method("klasses", &detail::TypeRegistry::klasses, Return().setValue());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ========= Registries.hpp =========
|
|
120
|
+
#ifndef Rice_Api_Registries_hpp
|
|
121
|
+
#define Rice_Api_Registries_hpp
|
|
122
|
+
|
|
123
|
+
void Init_Registries();
|
|
124
|
+
|
|
125
|
+
#endif
|
|
126
|
+
|
|
127
|
+
// ========= Registries.ipp =========
|
|
128
|
+
using namespace Rice;
|
|
129
|
+
|
|
130
|
+
inline void Init_Registries()
|
|
131
|
+
{
|
|
132
|
+
Module rb_mRice = define_module("Rice");
|
|
133
|
+
|
|
134
|
+
define_class_under<detail::Registries>(rb_mRice, "Registries").
|
|
135
|
+
define_singleton_attr("instance", &detail::Registries::instance, AttrAccess::Read).
|
|
136
|
+
define_attr("modules", &detail::Registries::modules, AttrAccess::Read).
|
|
137
|
+
define_attr("natives", &detail::Registries::natives, AttrAccess::Read).
|
|
138
|
+
define_attr("types", &detail::Registries::types, AttrAccess::Read);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ========= Arg.hpp =========
|
|
142
|
+
#ifndef Rice_Api_Arg_hpp
|
|
143
|
+
#define Rice_Api_Arg_hpp
|
|
144
|
+
|
|
145
|
+
extern "C"
|
|
146
|
+
void Init_Arg();
|
|
147
|
+
|
|
148
|
+
#endif
|
|
149
|
+
|
|
150
|
+
// ========= Arg.ipp =========
|
|
151
|
+
using namespace Rice;
|
|
152
|
+
|
|
153
|
+
inline void Init_Arg()
|
|
154
|
+
{
|
|
155
|
+
Module rb_mRice = define_module("Rice");
|
|
156
|
+
|
|
157
|
+
define_class_under<Arg>(rb_mRice, "Arg").
|
|
158
|
+
define_attr("name", &Arg::name, AttrAccess::Read);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ========= Parameter.hpp =========
|
|
162
|
+
#ifndef Rice_Api_Parameter_hpp
|
|
163
|
+
#define Rice_Api_Parameter_hpp
|
|
164
|
+
|
|
165
|
+
extern "C"
|
|
166
|
+
void Init_Parameter();
|
|
167
|
+
|
|
168
|
+
#endif
|
|
169
|
+
|
|
170
|
+
// ========= Parameter.ipp =========
|
|
171
|
+
using namespace Rice;
|
|
172
|
+
|
|
173
|
+
inline void Init_Parameter()
|
|
174
|
+
{
|
|
175
|
+
Module rb_mRice = define_module("Rice");
|
|
176
|
+
|
|
177
|
+
define_class_under<detail::ParameterAbstract>(rb_mRice, "Parameter").
|
|
178
|
+
define_method("arg", &detail::ParameterAbstract::arg).
|
|
179
|
+
define_method("klass", &detail::ParameterAbstract::klass, Return().setValue()).
|
|
180
|
+
define_method("cpp_klass", &detail::ParameterAbstract::cppTypeName);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ========= Native.hpp =========
|
|
184
|
+
#ifndef Rice_Api_Native_Function_hpp
|
|
185
|
+
#define Rice_Api_Native_Function_hpp
|
|
186
|
+
|
|
187
|
+
extern "C"
|
|
188
|
+
void Init_Native();
|
|
189
|
+
|
|
190
|
+
#endif
|
|
191
|
+
|
|
192
|
+
// ========= Native.ipp =========
|
|
193
|
+
using namespace Rice;
|
|
194
|
+
|
|
195
|
+
#include <ostream>
|
|
196
|
+
|
|
197
|
+
extern "C"
|
|
198
|
+
inline void Init_Native()
|
|
199
|
+
{
|
|
200
|
+
Module rb_mRice = define_module("Rice");
|
|
201
|
+
|
|
202
|
+
define_enum_under<detail::NativeKind>("NativeKind", rb_mRice)
|
|
203
|
+
.define_value("Function", detail::NativeKind::Function)
|
|
204
|
+
.define_value("Method", detail::NativeKind::Method)
|
|
205
|
+
.define_value("AttributeReader", detail::NativeKind::AttributeReader)
|
|
206
|
+
.define_value("AttributeWriter", detail::NativeKind::AttributeWriter)
|
|
207
|
+
.define_value("Proc", detail::NativeKind::Proc)
|
|
208
|
+
.define_value("Callback", detail::NativeKind::Callback);
|
|
209
|
+
|
|
210
|
+
define_class_under<detail::Native>(rb_mRice, "Native").
|
|
211
|
+
define_method("name", &detail::Native::name).
|
|
212
|
+
define_method("kind", &detail::Native::kind).
|
|
213
|
+
define_method("return_klass", &detail::Native::returnKlass, Return().setValue()).
|
|
214
|
+
define_method("parameters", &detail::Native::parameters).
|
|
215
|
+
define_method("to_s", [](detail::Native& self) -> std::string
|
|
216
|
+
{
|
|
217
|
+
std::ostringstream stream;
|
|
218
|
+
stream << "Native";
|
|
219
|
+
|
|
220
|
+
switch (self.kind())
|
|
221
|
+
{
|
|
222
|
+
case detail::NativeKind::Function:
|
|
223
|
+
stream << "Function";
|
|
224
|
+
break;
|
|
225
|
+
case detail::NativeKind::Method:
|
|
226
|
+
stream << "Method";
|
|
227
|
+
break;
|
|
228
|
+
case detail::NativeKind::Iterator:
|
|
229
|
+
stream << "Iterator";
|
|
230
|
+
break;
|
|
231
|
+
case detail::NativeKind::AttributeReader:
|
|
232
|
+
stream << "AttributeReader";
|
|
233
|
+
break;
|
|
234
|
+
case detail::NativeKind::AttributeWriter:
|
|
235
|
+
stream << "AttributeWriter";
|
|
236
|
+
break;
|
|
237
|
+
case detail::NativeKind::Proc:
|
|
238
|
+
stream << "Proc";
|
|
239
|
+
break;
|
|
240
|
+
case detail::NativeKind::Callback:
|
|
241
|
+
stream << "Callback";
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
stream << "<" << self.name() << "> ";
|
|
246
|
+
return stream.str();
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
extern "C"
|
|
251
|
+
inline void Init_Rice_Api()
|
|
252
|
+
{
|
|
253
|
+
Init_Registries();
|
|
254
|
+
Init_Module_Registry();
|
|
255
|
+
Init_Native_Registry();
|
|
256
|
+
Init_Type_Registry();
|
|
257
|
+
Init_Arg();
|
|
258
|
+
Init_Parameter();
|
|
259
|
+
Init_Native();
|
|
260
|
+
}
|
|
261
|
+
#endif
|