rice 4.3.3 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -26
  3. data/README.md +7 -2
  4. data/Rakefile +7 -1
  5. data/include/rice/rice.hpp +7291 -4430
  6. data/include/rice/stl.hpp +769 -222
  7. data/lib/mkmf-rice.rb +37 -95
  8. data/rice/Address_Registration_Guard.hpp +72 -3
  9. data/rice/Arg.hpp +19 -5
  10. data/rice/Arg.ipp +24 -0
  11. data/rice/Callback.hpp +21 -0
  12. data/rice/Callback.ipp +13 -0
  13. data/rice/Constructor.hpp +4 -27
  14. data/rice/Constructor.ipp +79 -0
  15. data/rice/Data_Object.hpp +74 -3
  16. data/rice/Data_Object.ipp +324 -32
  17. data/rice/Data_Type.hpp +215 -3
  18. data/rice/Data_Type.ipp +125 -64
  19. data/rice/Director.hpp +0 -2
  20. data/rice/Enum.hpp +4 -6
  21. data/rice/Enum.ipp +101 -57
  22. data/rice/Exception.hpp +62 -2
  23. data/rice/Exception.ipp +7 -12
  24. data/rice/JumpException.hpp +44 -0
  25. data/rice/JumpException.ipp +48 -0
  26. data/rice/MemoryView.hpp +11 -0
  27. data/rice/MemoryView.ipp +43 -0
  28. data/rice/Return.hpp +6 -26
  29. data/rice/Return.ipp +10 -16
  30. data/rice/detail/DefaultHandler.hpp +12 -0
  31. data/rice/detail/DefaultHandler.ipp +8 -0
  32. data/rice/detail/HandlerRegistry.hpp +5 -35
  33. data/rice/detail/HandlerRegistry.ipp +7 -11
  34. data/rice/detail/InstanceRegistry.hpp +1 -4
  35. data/rice/detail/MethodInfo.hpp +15 -5
  36. data/rice/detail/MethodInfo.ipp +78 -6
  37. data/rice/detail/Native.hpp +32 -0
  38. data/rice/detail/Native.ipp +129 -0
  39. data/rice/detail/NativeAttributeGet.hpp +51 -0
  40. data/rice/detail/NativeAttributeGet.ipp +51 -0
  41. data/rice/detail/NativeAttributeSet.hpp +43 -0
  42. data/rice/detail/NativeAttributeSet.ipp +82 -0
  43. data/rice/detail/NativeCallbackFFI.hpp +55 -0
  44. data/rice/detail/NativeCallbackFFI.ipp +151 -0
  45. data/rice/detail/NativeCallbackSimple.hpp +30 -0
  46. data/rice/detail/NativeCallbackSimple.ipp +29 -0
  47. data/rice/detail/NativeFunction.hpp +20 -21
  48. data/rice/detail/NativeFunction.ipp +199 -64
  49. data/rice/detail/NativeIterator.hpp +8 -11
  50. data/rice/detail/NativeIterator.ipp +27 -31
  51. data/rice/detail/NativeRegistry.hpp +24 -15
  52. data/rice/detail/NativeRegistry.ipp +23 -48
  53. data/rice/detail/Proc.hpp +4 -0
  54. data/rice/detail/Proc.ipp +85 -0
  55. data/rice/detail/Registries.hpp +0 -7
  56. data/rice/detail/Registries.ipp +0 -18
  57. data/rice/detail/RubyFunction.hpp +0 -3
  58. data/rice/detail/RubyFunction.ipp +4 -8
  59. data/rice/detail/RubyType.hpp +19 -0
  60. data/rice/detail/RubyType.ipp +187 -0
  61. data/rice/detail/TupleIterator.hpp +14 -0
  62. data/rice/detail/Type.hpp +5 -6
  63. data/rice/detail/Type.ipp +150 -33
  64. data/rice/detail/TypeRegistry.hpp +15 -7
  65. data/rice/detail/TypeRegistry.ipp +105 -12
  66. data/rice/detail/Wrapper.hpp +6 -5
  67. data/rice/detail/Wrapper.ipp +45 -23
  68. data/rice/detail/cpp_protect.hpp +5 -6
  69. data/rice/detail/default_allocation_func.ipp +0 -2
  70. data/rice/detail/from_ruby.hpp +37 -3
  71. data/rice/detail/from_ruby.ipp +911 -454
  72. data/rice/detail/ruby.hpp +18 -0
  73. data/rice/detail/to_ruby.hpp +41 -3
  74. data/rice/detail/to_ruby.ipp +437 -113
  75. data/rice/global_function.hpp +0 -4
  76. data/rice/global_function.ipp +1 -2
  77. data/rice/rice.hpp +105 -22
  78. data/rice/ruby_mark.hpp +4 -3
  79. data/rice/stl.hpp +4 -0
  80. data/test/embed_ruby.cpp +4 -1
  81. data/test/extconf.rb +2 -0
  82. data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
  83. data/test/test_Address_Registration_Guard.cpp +5 -0
  84. data/test/test_Array.cpp +12 -1
  85. data/test/test_Attribute.cpp +103 -21
  86. data/test/test_Builtin_Object.cpp +5 -0
  87. data/test/test_Callback.cpp +231 -0
  88. data/test/test_Class.cpp +5 -31
  89. data/test/test_Constructor.cpp +69 -6
  90. data/test/test_Data_Object.cpp +9 -4
  91. data/test/test_Data_Type.cpp +428 -64
  92. data/test/test_Director.cpp +10 -5
  93. data/test/test_Enum.cpp +152 -40
  94. data/test/test_Exception.cpp +235 -0
  95. data/test/test_File.cpp +70 -0
  96. data/test/test_From_Ruby.cpp +542 -0
  97. data/test/test_Hash.cpp +5 -0
  98. data/test/test_Identifier.cpp +5 -0
  99. data/test/test_Inheritance.cpp +6 -1
  100. data/test/test_Iterator.cpp +5 -0
  101. data/test/test_JumpException.cpp +22 -0
  102. data/test/test_Keep_Alive.cpp +6 -1
  103. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -0
  104. data/test/test_Memory_Management.cpp +5 -0
  105. data/test/test_Module.cpp +118 -64
  106. data/test/test_Native_Registry.cpp +2 -33
  107. data/test/test_Object.cpp +5 -0
  108. data/test/test_Overloads.cpp +631 -0
  109. data/test/test_Ownership.cpp +67 -4
  110. data/test/test_Proc.cpp +45 -0
  111. data/test/test_Self.cpp +5 -0
  112. data/test/test_Stl_Exception.cpp +109 -0
  113. data/test/test_Stl_Map.cpp +22 -8
  114. data/test/test_Stl_Optional.cpp +5 -0
  115. data/test/test_Stl_Pair.cpp +7 -2
  116. data/test/test_Stl_Reference_Wrapper.cpp +5 -0
  117. data/test/test_Stl_SmartPointer.cpp +210 -5
  118. data/test/test_Stl_String.cpp +5 -0
  119. data/test/test_Stl_String_View.cpp +5 -0
  120. data/test/test_Stl_Type.cpp +147 -0
  121. data/test/test_Stl_Unordered_Map.cpp +18 -7
  122. data/test/test_Stl_Variant.cpp +5 -0
  123. data/test/test_Stl_Vector.cpp +130 -8
  124. data/test/test_String.cpp +5 -0
  125. data/test/test_Struct.cpp +5 -0
  126. data/test/test_Symbol.cpp +5 -0
  127. data/test/test_Template.cpp +192 -0
  128. data/test/test_To_Ruby.cpp +152 -0
  129. data/test/test_Tracking.cpp +1 -0
  130. data/test/test_Type.cpp +100 -0
  131. data/test/test_global_functions.cpp +53 -6
  132. data/test/unittest.cpp +8 -0
  133. metadata +37 -20
  134. data/lib/version.rb +0 -3
  135. data/rice/Address_Registration_Guard_defn.hpp +0 -79
  136. data/rice/Data_Object_defn.hpp +0 -84
  137. data/rice/Data_Type_defn.hpp +0 -190
  138. data/rice/Exception_defn.hpp +0 -68
  139. data/rice/HandlerRegistration.hpp +0 -15
  140. data/rice/Identifier.hpp +0 -50
  141. data/rice/Identifier.ipp +0 -29
  142. data/rice/detail/ExceptionHandler.hpp +0 -8
  143. data/rice/detail/ExceptionHandler.ipp +0 -28
  144. data/rice/detail/ExceptionHandler_defn.hpp +0 -77
  145. data/rice/detail/Jump_Tag.hpp +0 -21
  146. data/rice/detail/NativeAttribute.hpp +0 -64
  147. data/rice/detail/NativeAttribute.ipp +0 -112
  148. data/rice/detail/from_ruby_defn.hpp +0 -38
  149. data/rice/detail/to_ruby_defn.hpp +0 -48
  150. data/test/test_Jump_Tag.cpp +0 -17
  151. data/test/test_To_From_Ruby.cpp +0 -399
@@ -1,68 +0,0 @@
1
- #ifndef Rice__Exception_defn__hpp_
2
- #define Rice__Exception_defn__hpp_
3
-
4
- #include <stdexcept>
5
- #include "detail/ruby.hpp"
6
-
7
- namespace Rice
8
- {
9
- //! A placeholder for Ruby exceptions.
10
- /*! You can use this to safely throw a Ruby exception using C++ syntax:
11
- * \code
12
- * VALUE foo(VALUE self) {
13
- * RUBY_TRY {
14
- * throw Rice::Exception(rb_eMyException, "uh oh!");
15
- * RUBY_CATCH
16
- * }
17
- * \endcode
18
- */
19
- class Exception
20
- : public std::exception
21
- {
22
- public:
23
- //! Construct a Exception with a Ruby exception instance
24
- explicit Exception(VALUE exception);
25
-
26
- //! Construct a Exception with printf-style formatting.
27
- /*! \param exc either an exception object or a class that inherits
28
- * from Exception.
29
- * \param fmt a printf-style format string
30
- * \param ... the arguments to the format string.
31
- */
32
- template <typename... Arg_Ts>
33
- Exception(const Exception& other, char const* fmt, Arg_Ts&&...args);
34
-
35
- //! Construct a Exception with printf-style formatting.
36
- /*! \param exc either an exception object or a class that inherits
37
- * from Exception.
38
- * \param fmt a printf-style format string
39
- * \param ... the arguments to the format string.
40
- */
41
- template <typename... Arg_Ts>
42
- Exception(const VALUE exceptionType, char const* fmt, Arg_Ts&&...args);
43
-
44
- //! Destructor
45
- virtual ~Exception() noexcept = default;
46
-
47
- //! Get message as a char const *.
48
- /*! If message is a non-string object, then this function will attempt
49
- * to throw an exception (which it can't do because of the no-throw
50
- * specification).
51
- * \return the underlying C pointer of the underlying message object.
52
- */
53
- virtual char const* what() const noexcept override;
54
-
55
- //! Returns the Ruby exception class
56
- VALUE class_of() const;
57
-
58
- //! Returns an instance of a Ruby exception
59
- VALUE value() const;
60
-
61
- private:
62
- // TODO: Do we need to tell the Ruby gc about an exception instance?
63
- mutable VALUE exception_ = Qnil;
64
- mutable std::string message_;
65
- };
66
- } // namespace Rice
67
-
68
- #endif // Rice__Exception_defn__hpp_
@@ -1,15 +0,0 @@
1
- #ifndef Rice__HandlerRegistration__hpp_
2
- #define Rice__HandlerRegistration__hpp_
3
-
4
- #include "detail/HandlerRegistry.hpp"
5
-
6
- namespace Rice
7
- {
8
- // Register exception handler
9
- template<typename Exception_T, typename Functor_T>
10
- detail::HandlerRegistry register_handler(Functor_T functor)
11
- {
12
- return detail::Registries::instance.handlers.add<Exception_T, Functor_T>(std::forward<Functor_T>(functor));
13
- }
14
- }
15
- #endif // Rice__HandlerRegistration__hpp_
data/rice/Identifier.hpp DELETED
@@ -1,50 +0,0 @@
1
- #ifndef Rice__Identifier__hpp_
2
- #define Rice__Identifier__hpp_
3
-
4
- #include <string>
5
-
6
- namespace Rice
7
- {
8
- class Symbol;
9
-
10
- //! A wrapper for the ID type
11
- /*! An ID is ruby's internal representation of a Symbol object.
12
- */
13
- class Identifier
14
- {
15
- public:
16
- //! Construct a new Identifier from an ID.
17
- Identifier(ID id);
18
-
19
- //! Construct a new Identifier from a Symbol.
20
- Identifier(Symbol const& symbol);
21
-
22
- //! Construct a new Identifier from a c string.
23
- Identifier(char const* s);
24
-
25
- //! Construct a new Identifier from a string.
26
- Identifier(std::string const& string);
27
-
28
- //! Return a string representation of the Identifier.
29
- char const* c_str() const;
30
-
31
- //! Return a string representation of the Identifier.
32
- std::string str() const;
33
-
34
- //! Return the underlying ID
35
- ID id() const { return id_; }
36
-
37
- //! Return the underlying ID
38
- operator ID() const { return id_; }
39
-
40
- //! Return the ID as a Symbol
41
- VALUE to_sym() const;
42
-
43
- private:
44
- ID id_;
45
- };
46
- } // namespace Rice
47
-
48
- #include "Identifier.ipp"
49
-
50
- #endif // Rice__Identifier__hpp_
data/rice/Identifier.ipp DELETED
@@ -1,29 +0,0 @@
1
- namespace Rice
2
- {
3
- inline Identifier::Identifier(ID id) : id_(id)
4
- {
5
- }
6
-
7
- inline Identifier::Identifier(char const* s) : id_(rb_intern(s))
8
- {
9
- }
10
-
11
- inline Identifier::Identifier(std::string const& s) : id_(rb_intern2(s.c_str(), s.size()))
12
- {
13
- }
14
-
15
- inline char const* Identifier::c_str() const
16
- {
17
- return detail::protect(rb_id2name, id_);
18
- }
19
-
20
- inline std::string Identifier::str() const
21
- {
22
- return c_str();
23
- }
24
-
25
- inline VALUE Identifier::to_sym() const
26
- {
27
- return ID2SYM(id_);
28
- }
29
- }
@@ -1,8 +0,0 @@
1
- #ifndef Rice__detail__ExceptionHandler__hpp_
2
- #define Rice__detail__ExceptionHandler__hpp_
3
-
4
- #include "ExceptionHandler_defn.hpp"
5
- #include "ExceptionHandler.ipp"
6
-
7
- #endif // Rice__detail__ExceptionHandler__hpp_
8
-
@@ -1,28 +0,0 @@
1
- namespace Rice::detail
2
- {
3
- inline VALUE Rice::detail::DefaultExceptionHandler::handle() const
4
- {
5
- throw;
6
- }
7
-
8
- template <typename Exception_T, typename Functor_T>
9
- inline Rice::detail::CustomExceptionHandler<Exception_T, Functor_T>::
10
- CustomExceptionHandler(Functor_T handler, std::shared_ptr<ExceptionHandler> nextHandler)
11
- : handler_(handler), nextHandler_(nextHandler)
12
- {
13
- }
14
-
15
- template <typename Exception_T, typename Functor_T>
16
- inline VALUE Rice::detail::CustomExceptionHandler<Exception_T, Functor_T>::handle() const
17
- {
18
- try
19
- {
20
- return this->nextHandler_->handle();
21
- }
22
- catch (Exception_T const& ex)
23
- {
24
- handler_(ex);
25
- throw;
26
- }
27
- }
28
- }
@@ -1,77 +0,0 @@
1
- #ifndef Rice__detail__ExceptionHandler_defn__hpp_
2
- #define Rice__detail__ExceptionHandler_defn__hpp_
3
-
4
- #include <memory>
5
- #include "ruby.hpp"
6
-
7
- namespace Rice::detail
8
- {
9
- /* An abstract class for converting C++ exceptions to ruby exceptions. It's used
10
- like this:
11
-
12
- try
13
- {
14
- }
15
- catch(...)
16
- {
17
- handler->handle();
18
- }
19
-
20
- If an exception is thrown the handler will pass the exception up the
21
- chain, then the last handler in the chain will throw the exception
22
- down the chain until a lower handler can handle it, e.g.:
23
-
24
- try
25
- {
26
- return call_next_ExceptionHandler();
27
- }
28
- catch(MyException const & ex)
29
- {
30
- throw Rice::Exception(rb_cMyException, "%s", ex.what());
31
- }
32
-
33
- Memory management. Handlers are created by the ModuleBase constructor. When the
34
- module defines a new Ruby method, metadata is stored on the Ruby klass including
35
- the exception handler. Since the metadata outlives the module, handlers are stored
36
- using std::shared_ptr. Thus the Module (or its inherited children) can be destroyed
37
- without corrupting the metadata references to the shared exception handler. */
38
-
39
- class ExceptionHandler
40
- {
41
- public:
42
- ExceptionHandler() = default;
43
- virtual ~ExceptionHandler() = default;
44
-
45
- // Don't allow copying or assignment
46
- ExceptionHandler(const ExceptionHandler& other) = delete;
47
- ExceptionHandler& operator=(const ExceptionHandler& other) = delete;
48
-
49
- virtual VALUE handle() const = 0;
50
- };
51
-
52
- // The default exception handler just rethrows the exception. If there
53
- // are other handlers in the chain, they will try to handle the rethrown
54
- // exception.
55
- class DefaultExceptionHandler : public ExceptionHandler
56
- {
57
- public:
58
- virtual VALUE handle() const override;
59
- };
60
-
61
- // An exception handler that takes a functor as an argument. The
62
- // functor should throw a Rice::Exception to handle the exception. If
63
- // the functor does not handle the exception, the exception will be
64
- // re-thrown.
65
- template <typename Exception_T, typename Functor_T>
66
- class CustomExceptionHandler : public ExceptionHandler
67
- {
68
- public:
69
- CustomExceptionHandler(Functor_T handler, std::shared_ptr<ExceptionHandler> nextHandler);
70
- virtual VALUE handle() const override;
71
-
72
- private:
73
- Functor_T handler_;
74
- std::shared_ptr<ExceptionHandler> nextHandler_;
75
- };
76
- }
77
- #endif // Rice__detail__ExceptionHandler_defn__hpp_
@@ -1,21 +0,0 @@
1
- #ifndef Rice__detail__Jump_Tag__hpp_
2
- #define Rice__detail__Jump_Tag__hpp_
3
-
4
- namespace Rice
5
- {
6
- //! A placeholder for Ruby longjmp data.
7
- /*! When a Ruby exception is caught, the tag used for the longjmp is stored in
8
- * a Jump_Tag, then later passed to rb_jump_tag() when there is no more
9
- * C++ code to pass over.
10
- */
11
- struct Jump_Tag
12
- {
13
- //! Construct a Jump_Tag with tag t.
14
- Jump_Tag(int t) : tag(t) {}
15
-
16
- //! The tag being held.
17
- int tag;
18
- };
19
- } // namespace Rice
20
-
21
- #endif // Rice__detail__Jump_Tag__hpp_
@@ -1,64 +0,0 @@
1
- #ifndef Rice__detail__Native_Attribute__hpp_
2
- #define Rice__detail__Native_Attribute__hpp_
3
-
4
- #include "ruby.hpp"
5
- #include "../traits/attribute_traits.hpp"
6
-
7
- namespace Rice
8
- {
9
- enum class AttrAccess
10
- {
11
- ReadWrite,
12
- Read,
13
- Write
14
- };
15
-
16
- namespace detail
17
- {
18
- template<typename Attribute_T>
19
- class NativeAttribute
20
- {
21
- public:
22
- using NativeAttribute_T = NativeAttribute<Attribute_T>;
23
-
24
- using T = typename attribute_traits<Attribute_T>::attr_type;
25
- using T_Unqualified = remove_cv_recursive_t<T>;
26
- using Receiver_T = typename attribute_traits<Attribute_T>::class_type;
27
-
28
- public:
29
- // Register attribute getter/setter with Ruby
30
- static void define(VALUE klass, std::string name, Attribute_T attribute, AttrAccess access = AttrAccess::ReadWrite);
31
-
32
- // Static member functions that Ruby calls to read an attribute value
33
- static VALUE get(VALUE self);
34
-
35
- // Static member functions that Ruby calls to write an attribute value
36
- static VALUE set(VALUE self, VALUE value);
37
-
38
- public:
39
- // Disallow creating/copying/moving
40
- NativeAttribute() = delete;
41
- NativeAttribute(const NativeAttribute_T&) = delete;
42
- NativeAttribute(NativeAttribute_T&&) = delete;
43
- void operator=(const NativeAttribute_T&) = delete;
44
- void operator=(NativeAttribute_T&&) = delete;
45
-
46
- protected:
47
- NativeAttribute(VALUE klass, std::string name, Attribute_T attr, AttrAccess access = AttrAccess::ReadWrite);
48
-
49
- // Invokes the wrapped function
50
- VALUE read(VALUE self);
51
- VALUE write(VALUE self, VALUE value);
52
-
53
- private:
54
- VALUE klass_;
55
- std::string name_;
56
- Attribute_T attribute_;
57
- AttrAccess access_;
58
- };
59
- } // detail
60
- } // Rice
61
-
62
- #include "NativeAttribute.ipp"
63
-
64
- #endif // Rice__detail__Native_Attribute__hpp_
@@ -1,112 +0,0 @@
1
- #include <array>
2
- #include <algorithm>
3
-
4
- #include "../traits/rice_traits.hpp"
5
- #include "NativeRegistry.hpp"
6
- #include "to_ruby_defn.hpp"
7
- #include "cpp_protect.hpp"
8
-
9
- namespace Rice::detail
10
- {
11
- template<typename Attribute_T>
12
- void NativeAttribute<Attribute_T>::define(VALUE klass, std::string name, Attribute_T attribute, AttrAccess access)
13
- {
14
- // Create a NativeAttribute that Ruby will call to read/write C++ variables
15
- NativeAttribute_T* native = new NativeAttribute_T(klass, name, std::forward<Attribute_T>(attribute), access);
16
-
17
- if (access == AttrAccess::ReadWrite || access == AttrAccess::Read)
18
- {
19
- // Tell Ruby to invoke the static method read to get the attribute value
20
- detail::protect(rb_define_method, klass, name.c_str(), (RUBY_METHOD_FUNC)&NativeAttribute_T::get, 0);
21
-
22
- // Add to native registry
23
- detail::Registries::instance.natives.add(klass, Identifier(name).id(), native);
24
- }
25
-
26
- if (access == AttrAccess::ReadWrite || access == AttrAccess::Write)
27
- {
28
- if (std::is_const_v<std::remove_pointer_t<T>>)
29
- {
30
- throw std::runtime_error(name + " is readonly");
31
- }
32
-
33
- // Define the write method name
34
- std::string setter = name + "=";
35
-
36
- // Tell Ruby to invoke the static method write to get the attribute value
37
- detail::protect(rb_define_method, klass, setter.c_str(), (RUBY_METHOD_FUNC)&NativeAttribute_T::set, 1);
38
-
39
- // Add to native registry
40
- detail::Registries::instance.natives.add(klass, Identifier(setter).id(), native);
41
- }
42
- }
43
-
44
- template<typename Attribute_T>
45
- inline VALUE NativeAttribute<Attribute_T>::get(VALUE self)
46
- {
47
- return cpp_protect([&]
48
- {
49
- using Native_Attr_T = NativeAttribute<Attribute_T>;
50
- Native_Attr_T* attr = detail::Registries::instance.natives.lookup<Native_Attr_T*>();
51
- return attr->read(self);
52
- });
53
- }
54
-
55
- template<typename Attribute_T>
56
- inline VALUE NativeAttribute<Attribute_T>::set(VALUE self, VALUE value)
57
- {
58
- return cpp_protect([&]
59
- {
60
- using Native_Attr_T = NativeAttribute<Attribute_T>;
61
- Native_Attr_T* attr = detail::Registries::instance.natives.lookup<Native_Attr_T*>();
62
- return attr->write(self, value);
63
- });
64
- }
65
-
66
- template<typename Attribute_T>
67
- NativeAttribute<Attribute_T>::NativeAttribute(VALUE klass, std::string name,
68
- Attribute_T attribute, AttrAccess access)
69
- : klass_(klass), name_(name), attribute_(attribute), access_(access)
70
- {
71
- }
72
-
73
- template<typename Attribute_T>
74
- inline VALUE NativeAttribute<Attribute_T>::read(VALUE self)
75
- {
76
- using T_Unqualified = remove_cv_recursive_t<T>;
77
- if constexpr (std::is_member_object_pointer_v<Attribute_T>)
78
- {
79
- Receiver_T* nativeSelf = From_Ruby<Receiver_T*>().convert(self);
80
- return To_Ruby<T_Unqualified>().convert(nativeSelf->*attribute_);
81
- }
82
- else
83
- {
84
- return To_Ruby<T_Unqualified>().convert(*attribute_);
85
- }
86
- }
87
-
88
- template<typename Attribute_T>
89
- inline VALUE NativeAttribute<Attribute_T>::write(VALUE self, VALUE value)
90
- {
91
- if constexpr (std::is_fundamental_v<intrinsic_type<T>> && std::is_pointer_v<T>)
92
- {
93
- static_assert(true, "An fundamental value, such as an integer, cannot be assigned to an attribute that is a pointer");
94
- }
95
- else if constexpr (std::is_same_v<intrinsic_type<T>, std::string> && std::is_pointer_v<T>)
96
- {
97
- static_assert(true, "An string cannot be assigned to an attribute that is a pointer");
98
- }
99
-
100
- if constexpr (!std::is_null_pointer_v<Receiver_T>)
101
- {
102
- Receiver_T* nativeSelf = From_Ruby<Receiver_T*>().convert(self);
103
- nativeSelf->*attribute_ = From_Ruby<T_Unqualified>().convert(value);
104
- }
105
- else if constexpr (!std::is_const_v<std::remove_pointer_t<T>>)
106
- {
107
- *attribute_ = From_Ruby<T_Unqualified>().convert(value);
108
- }
109
-
110
- return value;
111
- }
112
- } // Rice
@@ -1,38 +0,0 @@
1
- #ifndef Rice__detail__from_ruby_defn__hpp_
2
- #define Rice__detail__from_ruby_defn__hpp_
3
-
4
- #include <type_traits>
5
-
6
- #include "ruby.hpp"
7
-
8
- namespace Rice::detail
9
- {
10
- //! Convert a Ruby object to C++.
11
- /*! If the Ruby object can be converted to an immediate value, returns a
12
- * copy of the Ruby object. If the Ruby object is holding a C++
13
- * object and the type specified is a pointer to that type, returns a
14
- * pointer to that object.
15
- *
16
- * Conversions from ruby to a pointer type are automatically generated
17
- * when a type is bound using Data_Type. If no conversion exists an
18
- * exception is thrown.
19
- *
20
- * \param T the C++ type to which to convert.
21
- * \param x the Ruby object to convert.
22
- * \return a C++ representation of the Ruby object.
23
- *
24
- * Example:
25
- * \code
26
- * Object x = INT2NUM(42);
27
- * std::cout << From_Ruby<int>::convert(x);
28
- *
29
- * Data_Object<Foo> foo(new Foo);
30
- * std::cout << *From_Ruby<Foo *>(foo) << std::endl;
31
- * \endcode
32
- */
33
-
34
- template <typename T>
35
- class From_Ruby;
36
- }
37
-
38
- #endif // Rice__detail__From_Ruby2_defn__hpp_
@@ -1,48 +0,0 @@
1
- #ifndef Rice__detail__to_ruby_defn__hpp_
2
- #define Rice__detail__to_ruby_defn__hpp_
3
-
4
- #include "../traits/rice_traits.hpp"
5
-
6
- namespace Rice
7
- {
8
- namespace detail
9
- {
10
- //! Convert a C++ object to Ruby.
11
- /*! If x is a pointer, wraps the pointee as a Ruby object. If x is an
12
- * Object, returns x.
13
- *
14
- * If no conversion exists a compile-time error is generated.
15
- *
16
- * \param x the object to convert.
17
- * \return a Ruby representation of the C++ object.
18
- *
19
- * Example:
20
- * \code
21
- * rb_p(to_ruby(42));
22
- *
23
- * Foo * p_foo = new Foo();
24
- * rb_p(to_ruby(p_foo));
25
- * \endcode
26
- */
27
- template <typename T>
28
- class To_Ruby;
29
-
30
- // Helper template function that let's users avoid having to specify the template type - its deduced
31
- template <typename T>
32
- VALUE to_ruby(T&& x)
33
- {
34
- using Unqualified_T = remove_cv_recursive_t<T>;
35
- return To_Ruby<Unqualified_T>().convert(std::forward<T>(x));
36
- }
37
-
38
- // Helper template function that let's users avoid having to specify the template type - its deduced
39
- template <typename T>
40
- VALUE to_ruby(T* x)
41
- {
42
- using Unqualified_T = remove_cv_recursive_t<T>;
43
- return To_Ruby<Unqualified_T*>().convert(x);
44
- }
45
- } // detail
46
- } // Rice
47
-
48
- #endif // Rice__detail__to_ruby_defn__hpp_
@@ -1,17 +0,0 @@
1
- #include "unittest.hpp"
2
- #include <rice/rice.hpp>
3
-
4
- using namespace Rice;
5
-
6
- TESTSUITE(Jump_Tag);
7
-
8
- SETUP(Jump_Tag)
9
- {
10
- }
11
-
12
- TESTCASE(construct)
13
- {
14
- Jump_Tag jump_tag(42);
15
- ASSERT_EQUAL(42, jump_tag.tag);
16
- }
17
-