rice 4.5.0 → 4.6.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 +23 -0
- data/CMakeLists.txt +31 -0
- data/CMakePresets.json +75 -0
- data/COPYING +3 -2
- data/FindRuby.cmake +437 -0
- data/Rakefile +5 -4
- data/include/rice/rice.hpp +5436 -3201
- data/include/rice/stl.hpp +2355 -1269
- data/lib/make_rice_headers.rb +79 -0
- data/lib/mkmf-rice.rb +4 -0
- data/lib/rice/version.rb +3 -0
- data/lib/rice.rb +1 -0
- data/lib/rubygems/builder.rb +11 -0
- data/lib/rubygems/cmake_builder.rb +113 -0
- data/lib/rubygems_plugin.rb +9 -0
- data/rice/Arg.hpp +7 -1
- data/rice/Arg.ipp +11 -2
- data/rice/Buffer.hpp +123 -0
- data/rice/Buffer.ipp +599 -0
- data/rice/Constructor.ipp +3 -3
- data/rice/Data_Object.hpp +2 -3
- data/rice/Data_Object.ipp +188 -188
- data/rice/Data_Type.hpp +4 -5
- data/rice/Data_Type.ipp +42 -26
- data/rice/Enum.hpp +0 -1
- data/rice/Enum.ipp +26 -23
- data/rice/Init.hpp +8 -0
- data/rice/Init.ipp +8 -0
- data/rice/MemoryView.ipp +1 -41
- data/rice/Return.hpp +1 -1
- data/rice/Return.ipp +6 -0
- data/rice/cpp_api/Array.hpp +209 -0
- data/rice/cpp_api/Array.ipp +304 -0
- data/rice/cpp_api/Builtin_Object.hpp +31 -0
- data/rice/cpp_api/Builtin_Object.ipp +37 -0
- data/rice/cpp_api/Class.hpp +70 -0
- data/rice/cpp_api/Class.ipp +97 -0
- data/rice/cpp_api/Encoding.hpp +32 -0
- data/rice/cpp_api/Encoding.ipp +59 -0
- data/rice/cpp_api/Hash.hpp +194 -0
- data/rice/cpp_api/Hash.ipp +257 -0
- data/rice/cpp_api/Identifier.hpp +46 -0
- data/rice/cpp_api/Identifier.ipp +31 -0
- data/rice/cpp_api/Module.hpp +72 -0
- data/rice/cpp_api/Module.ipp +101 -0
- data/rice/cpp_api/Object.hpp +272 -0
- data/rice/cpp_api/Object.ipp +235 -0
- data/rice/cpp_api/String.hpp +74 -0
- data/rice/cpp_api/String.ipp +120 -0
- data/rice/cpp_api/Struct.hpp +113 -0
- data/rice/cpp_api/Struct.ipp +92 -0
- data/rice/cpp_api/Symbol.hpp +46 -0
- data/rice/cpp_api/Symbol.ipp +93 -0
- data/rice/cpp_api/shared_methods.hpp +134 -0
- data/rice/detail/MethodInfo.hpp +1 -9
- data/rice/detail/MethodInfo.ipp +5 -72
- data/rice/detail/Native.hpp +3 -2
- data/rice/detail/Native.ipp +32 -4
- data/rice/detail/NativeAttributeGet.hpp +3 -2
- data/rice/detail/NativeAttributeGet.ipp +8 -2
- data/rice/detail/NativeAttributeSet.hpp +3 -2
- data/rice/detail/NativeAttributeSet.ipp +8 -2
- data/rice/detail/NativeCallbackFFI.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +17 -6
- data/rice/detail/NativeFunction.ipp +168 -64
- data/rice/detail/NativeIterator.hpp +3 -2
- data/rice/detail/NativeIterator.ipp +8 -2
- data/rice/detail/RubyType.hpp +2 -5
- data/rice/detail/RubyType.ipp +50 -5
- data/rice/detail/Type.hpp +3 -1
- data/rice/detail/Type.ipp +61 -31
- data/rice/detail/Wrapper.hpp +68 -33
- data/rice/detail/Wrapper.ipp +103 -113
- data/rice/detail/from_ruby.hpp +5 -4
- data/rice/detail/from_ruby.ipp +737 -365
- data/rice/detail/to_ruby.ipp +1092 -186
- data/rice/global_function.ipp +1 -1
- data/rice/libc/file.hpp +11 -0
- data/rice/libc/file.ipp +32 -0
- data/rice/rice.hpp +23 -16
- data/rice/stl/complex.hpp +6 -0
- data/rice/stl/complex.ipp +93 -0
- data/rice/stl/exception.hpp +11 -0
- data/rice/stl/exception.ipp +29 -0
- data/rice/stl/exception_ptr.hpp +6 -0
- data/rice/stl/exception_ptr.ipp +27 -0
- data/rice/stl/map.hpp +12 -0
- data/rice/stl/map.ipp +469 -0
- data/rice/stl/monostate.hpp +6 -0
- data/rice/stl/monostate.ipp +80 -0
- data/rice/stl/multimap.hpp +14 -0
- data/rice/stl/multimap.ipp +448 -0
- data/rice/stl/optional.hpp +6 -0
- data/rice/stl/optional.ipp +118 -0
- data/rice/stl/pair.hpp +13 -0
- data/rice/stl/pair.ipp +155 -0
- data/rice/stl/reference_wrapper.hpp +6 -0
- data/rice/stl/reference_wrapper.ipp +41 -0
- data/rice/stl/set.hpp +12 -0
- data/rice/stl/set.ipp +495 -0
- data/rice/stl/shared_ptr.hpp +28 -0
- data/rice/stl/shared_ptr.ipp +224 -0
- data/rice/stl/string.hpp +6 -0
- data/rice/stl/string.ipp +158 -0
- data/rice/stl/string_view.hpp +6 -0
- data/rice/stl/string_view.ipp +65 -0
- data/rice/stl/tuple.hpp +6 -0
- data/rice/stl/tuple.ipp +128 -0
- data/rice/stl/type_index.hpp +6 -0
- data/rice/stl/type_index.ipp +30 -0
- data/rice/stl/type_info.hpp +6 -0
- data/rice/stl/type_info.ipp +29 -0
- data/rice/stl/unique_ptr.hpp +22 -0
- data/rice/stl/unique_ptr.ipp +139 -0
- data/rice/stl/unordered_map.hpp +12 -0
- data/rice/stl/unordered_map.ipp +469 -0
- data/rice/stl/variant.hpp +6 -0
- data/rice/stl/variant.ipp +242 -0
- data/rice/stl/vector.hpp +12 -0
- data/rice/stl/vector.ipp +590 -0
- data/rice/stl.hpp +7 -3
- data/rice/traits/attribute_traits.hpp +26 -0
- data/rice/traits/function_traits.hpp +95 -0
- data/rice/traits/method_traits.hpp +47 -0
- data/rice/traits/rice_traits.hpp +160 -0
- data/rice.gemspec +85 -0
- data/test/embed_ruby.cpp +3 -0
- data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
- data/test/test_Array.cpp +6 -3
- data/test/test_Attribute.cpp +34 -1
- data/test/test_Buffer.cpp +285 -0
- data/test/test_Callback.cpp +2 -3
- data/test/test_Data_Object.cpp +88 -34
- data/test/test_Data_Type.cpp +106 -65
- data/test/test_Director.cpp +7 -3
- data/test/test_Enum.cpp +5 -2
- data/test/test_File.cpp +1 -1
- data/test/test_From_Ruby.cpp +181 -114
- data/test/test_Iterator.cpp +1 -1
- data/test/{test_JumpException.cpp → test_Jump_Exception.cpp} +1 -0
- data/test/test_Keep_Alive.cpp +7 -18
- data/test/test_Keep_Alive_No_Wrapper.cpp +0 -1
- data/test/test_Module.cpp +13 -6
- data/test/test_Native_Registry.cpp +0 -1
- data/test/test_Overloads.cpp +180 -5
- data/test/test_Ownership.cpp +100 -57
- data/test/test_Proc.cpp +0 -1
- data/test/test_Self.cpp +4 -4
- data/test/test_Stl_Map.cpp +37 -39
- data/test/test_Stl_Multimap.cpp +693 -0
- data/test/test_Stl_Pair.cpp +8 -8
- data/test/test_Stl_Reference_Wrapper.cpp +4 -2
- data/test/test_Stl_Set.cpp +790 -0
- data/test/{test_Stl_SmartPointer.cpp → test_Stl_SharedPtr.cpp} +97 -127
- data/test/test_Stl_Tuple.cpp +116 -0
- data/test/test_Stl_Type.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +202 -0
- data/test/test_Stl_Unordered_Map.cpp +28 -34
- data/test/test_Stl_Variant.cpp +217 -89
- data/test/test_Stl_Vector.cpp +209 -83
- data/test/test_To_Ruby.cpp +373 -1
- data/test/test_Type.cpp +85 -14
- data/test/test_global_functions.cpp +17 -4
- metadata +94 -10
- data/rice/detail/TupleIterator.hpp +0 -14
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
LINE_ENDING = "\n"
|
4
|
+
RICE_INCLUDE_REGEX = %r{#include "(.*)"}
|
5
|
+
OTHER_INCLUDE_REGEX = %r{#include <(.*)>}
|
6
|
+
|
7
|
+
RICE_HEADER_GUARD_1 = %r{#ifndef Rice__}
|
8
|
+
RICE_HEADER_GUARD_2 = %r{#define Rice__}
|
9
|
+
RICE_HEADER_GUARD_3 = %r{#endif\s*//\s*Rice__}
|
10
|
+
SHARED_METHODS_REGEX = %r{#include "((?:cpp_api\/)?shared_methods.hpp)"}
|
11
|
+
|
12
|
+
def load_file(relative_path)
|
13
|
+
content = File.read(relative_path, mode: 'rb')
|
14
|
+
|
15
|
+
# Special case shared_methods.hpp which if requested we want to
|
16
|
+
# merge into the current file
|
17
|
+
match = content.match(SHARED_METHODS_REGEX)
|
18
|
+
if match
|
19
|
+
shared_path = File.join(File.dirname(relative_path), match[1])
|
20
|
+
content.gsub!(SHARED_METHODS_REGEX, File.read(shared_path, mode: 'rb'))
|
21
|
+
end
|
22
|
+
|
23
|
+
content
|
24
|
+
end
|
25
|
+
|
26
|
+
def strip_includes(content)
|
27
|
+
content.lines.find_all do |line|
|
28
|
+
!line.match(RICE_INCLUDE_REGEX)
|
29
|
+
end.join
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_include(path, stream)
|
33
|
+
basename = File.basename(path)
|
34
|
+
basename_no_ext = File.basename(path, ".*")
|
35
|
+
|
36
|
+
stream << "\n" << "// ========= #{File.basename(path)} =========" << "\n"
|
37
|
+
|
38
|
+
load_file(path).each_line do |line|
|
39
|
+
if match = line.match(RICE_INCLUDE_REGEX)
|
40
|
+
# Check for related includes, ie., Object.hpp, Object_defn.hpp and Object.ipp
|
41
|
+
sub_include = File.basename(match[1])
|
42
|
+
if ["#{basename_no_ext}_defn.hpp", "#{basename_no_ext}.ipp"].include?(sub_include)
|
43
|
+
sub_include_path = File.join(File.dirname(path), match[1])
|
44
|
+
stream << "\n" << "// --------- #{File.basename(sub_include_path)} ---------" << "\n"
|
45
|
+
stream << strip_includes(load_file(sub_include_path))
|
46
|
+
end
|
47
|
+
elsif line.match(RICE_HEADER_GUARD_1) || line.match(RICE_HEADER_GUARD_2) || line.match(RICE_HEADER_GUARD_3)
|
48
|
+
# Skip the header guard
|
49
|
+
else
|
50
|
+
# Include the line in the output
|
51
|
+
stream << line
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def combine_headers(filename)
|
57
|
+
stream = StringIO.new
|
58
|
+
|
59
|
+
load_file("rice/#{filename}").each_line do |line|
|
60
|
+
if matches = line.match(RICE_INCLUDE_REGEX)
|
61
|
+
path = File.join("rice", matches[1])
|
62
|
+
add_include(path, stream)
|
63
|
+
else
|
64
|
+
stream << line
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
File.open("include/rice/#{filename}", 'wb') do |file|
|
69
|
+
file << stream.string
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
puts "Building rice.hpp"
|
74
|
+
combine_headers('rice.hpp')
|
75
|
+
|
76
|
+
puts "Building stl.hpp"
|
77
|
+
combine_headers('stl.hpp')
|
78
|
+
|
79
|
+
puts "Success"
|
data/lib/mkmf-rice.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
require 'mkmf'
|
2
|
+
require 'rice/version'
|
3
|
+
|
4
|
+
major, minor, patch = Rice::VERSION.split(".")
|
5
|
+
$CXXFLAGS += " -DRICE_VERSION_MAJOR=#{major} -DRICE_VERSION_MINOR=#{minor} -DRICE_VERSION_PATCH=#{patch}"
|
2
6
|
|
3
7
|
IS_MSWIN = /mswin/ =~ RUBY_PLATFORM
|
4
8
|
IS_MINGW = /mingw/ =~ RUBY_PLATFORM
|
data/lib/rice/version.rb
ADDED
data/lib/rice.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "rice/version"
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This builder creates extensions defined using CMake. Its is invoked if a Gem's spec file
|
4
|
+
# sets the `extension` property to a string that contains `CMakeLists.txt`.
|
5
|
+
#
|
6
|
+
# In general, CMake projects are built in two steps:
|
7
|
+
#
|
8
|
+
# * configure
|
9
|
+
# * build
|
10
|
+
#
|
11
|
+
# The builder follow this convention. First it runs a configuration step and then it runs a build step.
|
12
|
+
#
|
13
|
+
# CMake projects can be quite configurable - it is likely you will want to specify options when
|
14
|
+
# installing a gem. To pass options to CMake specify them after `--` in the gem install command. For example:
|
15
|
+
#
|
16
|
+
# gem install <gem_name> -- --preset <preset_name>
|
17
|
+
#
|
18
|
+
# Note that options are ONLY sent to the configure step - it is not currently possible to specify
|
19
|
+
# options for the build step. If this becomes and issue then the CMake builder can be updated to
|
20
|
+
# support build options.
|
21
|
+
#
|
22
|
+
# Useful options to know are:
|
23
|
+
#
|
24
|
+
# -G to specify a generator (-G Ninja is recommended)
|
25
|
+
# -D<CMAKE_VARIABLE> to set a CMake variable (for example -DCMAKE_BUILD_TYPE=Release)
|
26
|
+
# --preset <preset_name> to use a preset
|
27
|
+
#
|
28
|
+
# If the Gem author provides presets, via CMakePresets.json file, you will likely want to us use one of them.
|
29
|
+
# If not, then you may wish to specify a generator (Ninja is recommended since it can build projects in parallel
|
30
|
+
# versus a Make generator which build ins serial and thus is *much* slower).
|
31
|
+
|
32
|
+
require "fileutils"
|
33
|
+
|
34
|
+
class Gem::Ext::CmakeBuilder
|
35
|
+
attr_accessor :runner, :profile
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@runner = self.class.method(:run)
|
39
|
+
@profile = :release
|
40
|
+
end
|
41
|
+
|
42
|
+
def build(extension, gem_dir, results, args = [], lib_dir = nil, cmake_dir = Dir.pwd, target_rbconfig = Gem.target_rbconfig)
|
43
|
+
if target_rbconfig.path
|
44
|
+
warn "--target-rbconfig is not yet supported for CMake extensions. Ignoring"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Make sure lib dir is set
|
48
|
+
lib_dir ||= File.join(gem_dir, "lib")
|
49
|
+
|
50
|
+
# Figure the build dir
|
51
|
+
build_dir = File.join(cmake_dir, "build")
|
52
|
+
|
53
|
+
# Check if the gem defined presets
|
54
|
+
check_presets(cmake_dir, args)
|
55
|
+
|
56
|
+
# Configure
|
57
|
+
configure(cmake_dir, build_dir, lib_dir, args, results)
|
58
|
+
|
59
|
+
# Compile
|
60
|
+
compile(cmake_dir, build_dir, args, results)
|
61
|
+
|
62
|
+
results
|
63
|
+
end
|
64
|
+
|
65
|
+
def configure(cmake_dir, build_dir, lib_dir, args, results)
|
66
|
+
cmd = ["cmake",
|
67
|
+
cmake_dir,
|
68
|
+
"-B #{build_dir}",
|
69
|
+
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=#{lib_dir}", # Windows
|
70
|
+
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=#{lib_dir}", # Not Windows
|
71
|
+
*Gem::Command.build_args,
|
72
|
+
*args]
|
73
|
+
|
74
|
+
runner.call(cmd, results, "cmake", cmake_dir)
|
75
|
+
end
|
76
|
+
|
77
|
+
def compile(cmake_dir, build_dir, args, results)
|
78
|
+
cmd = ["cmake",
|
79
|
+
"--build",
|
80
|
+
build_dir.to_s,
|
81
|
+
"--config",
|
82
|
+
@profile.to_s]
|
83
|
+
runner.call(cmd, results, "cmake", cmake_dir)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def check_presets(cmake_dir, args)
|
89
|
+
# Return if the user specified a preset
|
90
|
+
return unless args.grep(/--preset/i).empty?
|
91
|
+
|
92
|
+
cmd = ["cmake",
|
93
|
+
"--list-presets"]
|
94
|
+
|
95
|
+
begin
|
96
|
+
require "open3"
|
97
|
+
build_env = { "SOURCE_DATE_EPOCH" => Gem.source_date_epoch_string }
|
98
|
+
stdout, _, _ = Open3.capture3(build_env, *cmd, chdir: cmake_dir)
|
99
|
+
message = <<~EOS
|
100
|
+
The gem author provided a list of presets that can be used to build the gem. To use a preset specify it on the command line:
|
101
|
+
|
102
|
+
gem install <gem_name> -- --preset <preset_name>
|
103
|
+
|
104
|
+
#{stdout}
|
105
|
+
EOS
|
106
|
+
|
107
|
+
STDOUT << message << "\n"
|
108
|
+
STDOUT.flush
|
109
|
+
rescue Gem::InstallError
|
110
|
+
# Do nothing, CMakePresets.json was not included in the Gem
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Create RubyGems hook so we can replace the default CMakeBuilder with our own version
|
2
|
+
Gem.pre_install do |installer|
|
3
|
+
extensions = installer.package&.spec&.extensions
|
4
|
+
if extensions && extensions.grep(/CMakeLists/)
|
5
|
+
require_relative 'rubygems/builder'
|
6
|
+
require_relative 'rubygems/cmake_builder'
|
7
|
+
end
|
8
|
+
true
|
9
|
+
end
|
data/rice/Arg.hpp
CHANGED
@@ -55,7 +55,7 @@ namespace Rice
|
|
55
55
|
/*! \return the type saved to this Arg
|
56
56
|
*/
|
57
57
|
template<typename Arg_Type>
|
58
|
-
Arg_Type
|
58
|
+
Arg_Type defaultValue();
|
59
59
|
|
60
60
|
//! Tell the receiving object to keep this argument alive
|
61
61
|
//! until the receiving object is freed.
|
@@ -81,6 +81,10 @@ namespace Rice
|
|
81
81
|
virtual Arg& takeOwnership();
|
82
82
|
bool isOwner();
|
83
83
|
|
84
|
+
//! Is the parameter a C style array
|
85
|
+
virtual Arg& setArray();
|
86
|
+
bool isArray();
|
87
|
+
|
84
88
|
public:
|
85
89
|
std::string name;
|
86
90
|
int32_t position = -1;
|
@@ -92,6 +96,8 @@ namespace Rice
|
|
92
96
|
bool isKeepAlive_ = false;
|
93
97
|
bool isOwner_ = false;
|
94
98
|
bool isOpaque_ = false;
|
99
|
+
bool isArray_ = false;
|
100
|
+
|
95
101
|
};
|
96
102
|
} // Rice
|
97
103
|
|
data/rice/Arg.ipp
CHANGED
@@ -21,9 +21,9 @@ namespace Rice
|
|
21
21
|
/*! \return the type saved to this Arg
|
22
22
|
*/
|
23
23
|
template<typename Arg_Type>
|
24
|
-
inline Arg_Type
|
24
|
+
inline Arg_Type Arg::defaultValue()
|
25
25
|
{
|
26
|
-
return std::any_cast<Arg_Type
|
26
|
+
return std::any_cast<Arg_Type>(this->defaultValue_);
|
27
27
|
}
|
28
28
|
|
29
29
|
inline Arg& Arg::keepAlive()
|
@@ -70,5 +70,14 @@ namespace Rice
|
|
70
70
|
return this->isOwner_;
|
71
71
|
}
|
72
72
|
|
73
|
+
inline Arg& Arg::setArray()
|
74
|
+
{
|
75
|
+
this->isArray_ = true;
|
76
|
+
return *this;
|
77
|
+
}
|
73
78
|
|
79
|
+
inline bool Arg::isArray()
|
80
|
+
{
|
81
|
+
return this->isArray_;
|
82
|
+
}
|
74
83
|
} // Rice
|
data/rice/Buffer.hpp
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
#ifndef Rice__Buffer__hpp_
|
2
|
+
#define Rice__Buffer__hpp_
|
3
|
+
|
4
|
+
namespace Rice
|
5
|
+
{
|
6
|
+
template<typename T>
|
7
|
+
class Buffer
|
8
|
+
{
|
9
|
+
public:
|
10
|
+
using type = T;
|
11
|
+
|
12
|
+
Buffer(T* pointer);
|
13
|
+
Buffer(T* pointer, size_t size);
|
14
|
+
Buffer(VALUE value);
|
15
|
+
|
16
|
+
~Buffer();
|
17
|
+
|
18
|
+
Buffer(const Buffer& other) = delete;
|
19
|
+
Buffer(Buffer&& other);
|
20
|
+
|
21
|
+
Buffer& operator=(const Buffer& other) = delete;
|
22
|
+
Buffer& operator=(Buffer&& other);
|
23
|
+
|
24
|
+
T* ptr();
|
25
|
+
T& reference();
|
26
|
+
void release();
|
27
|
+
|
28
|
+
size_t size() const;
|
29
|
+
void setSize(size_t value);
|
30
|
+
|
31
|
+
// Ruby API
|
32
|
+
// VALUE toString() const;
|
33
|
+
|
34
|
+
VALUE bytes() const;
|
35
|
+
VALUE bytes(size_t count) const;
|
36
|
+
|
37
|
+
Array toArray() const;
|
38
|
+
Array toArray(size_t count) const;
|
39
|
+
|
40
|
+
T get(size_t index) const;
|
41
|
+
void set(size_t index, T value);
|
42
|
+
|
43
|
+
bool isOwner() const;
|
44
|
+
void setOwner(bool value);
|
45
|
+
|
46
|
+
private:
|
47
|
+
void fromRubyType(VALUE value);
|
48
|
+
void fromDataType(VALUE value);
|
49
|
+
|
50
|
+
bool m_owner = false;
|
51
|
+
size_t m_size = 0;
|
52
|
+
// std::unique_ptr would be greate but std::unique_ptr<void> isn't allowed
|
53
|
+
T* m_buffer = nullptr;
|
54
|
+
};
|
55
|
+
|
56
|
+
template<typename T>
|
57
|
+
class Buffer<T*>
|
58
|
+
{
|
59
|
+
public:
|
60
|
+
using type = T*;
|
61
|
+
|
62
|
+
Buffer(T** pointer);
|
63
|
+
Buffer(T** pointer, size_t size);
|
64
|
+
Buffer(VALUE value);
|
65
|
+
|
66
|
+
~Buffer();
|
67
|
+
|
68
|
+
Buffer(const Buffer& other) = delete;
|
69
|
+
Buffer(Buffer&& other);
|
70
|
+
|
71
|
+
Buffer& operator=(const Buffer& other) = delete;
|
72
|
+
Buffer& operator=(Buffer&& other);
|
73
|
+
|
74
|
+
const Buffer<T>& operator[](size_t index);
|
75
|
+
|
76
|
+
T** ptr();
|
77
|
+
void release();
|
78
|
+
|
79
|
+
size_t size() const;
|
80
|
+
void setSize(size_t value);
|
81
|
+
|
82
|
+
// Ruby API
|
83
|
+
// VALUE toString() const;
|
84
|
+
|
85
|
+
VALUE bytes() const;
|
86
|
+
VALUE bytes(size_t count) const;
|
87
|
+
|
88
|
+
Array toArray() const;
|
89
|
+
Array toArray(size_t count) const;
|
90
|
+
|
91
|
+
void setOwner(bool value);
|
92
|
+
bool isOwner() const;
|
93
|
+
|
94
|
+
private:
|
95
|
+
bool m_owner = false;
|
96
|
+
size_t m_size = 0;
|
97
|
+
T** m_outer = nullptr;
|
98
|
+
std::vector<Buffer<T>> m_inner;
|
99
|
+
};
|
100
|
+
|
101
|
+
template<>
|
102
|
+
class Buffer<void>
|
103
|
+
{
|
104
|
+
public:
|
105
|
+
Buffer(void* pointer);
|
106
|
+
Buffer(const Buffer& other) = delete;
|
107
|
+
Buffer(Buffer&& other);
|
108
|
+
|
109
|
+
Buffer& operator=(const Buffer& other) = delete;
|
110
|
+
Buffer& operator=(Buffer&& other);
|
111
|
+
|
112
|
+
void* ptr();
|
113
|
+
|
114
|
+
private:
|
115
|
+
void* m_buffer = nullptr;
|
116
|
+
};
|
117
|
+
|
118
|
+
template<typename T>
|
119
|
+
Data_Type<Buffer<T>> define_buffer(std::string klassName = "");
|
120
|
+
|
121
|
+
void define_fundamental_buffer_types();
|
122
|
+
}
|
123
|
+
#endif // Rice__Buffer__hpp_
|