-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big header cleanup - separate hpp and ipp files. Thus remove defn.hpp…
… files and do not include .ipp files from .hpp files. Also remove any includes for other rice files (they are not standalone files, so just stop pretending). These changes allows us to use the C++ API (Array, etc) from from_ruby and to_ruby.
- Loading branch information
Showing
85 changed files
with
5,735 additions
and
6,164 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,76 @@ | ||
#ifndef Rice__Address_Registration_Guard__hpp_ | ||
#define Rice__Address_Registration_Guard__hpp_ | ||
|
||
#include "Address_Registration_Guard_defn.hpp" | ||
#include "Address_Registration_Guard.ipp" | ||
namespace Rice | ||
{ | ||
//! A guard to register a given address with the GC. | ||
/*! Calls rb_gc_register_address upon construction and | ||
* rb_gc_unregister_address upon destruction. | ||
* For example: | ||
* \code | ||
* Class Foo | ||
* { | ||
* public: | ||
* Foo() | ||
* : string_(rb_str_new2()) | ||
* , guard_(&string_); | ||
* | ||
* private: | ||
* VALUE string_; | ||
* Address_Registration_Guard guard_; | ||
* }; | ||
* \endcode | ||
*/ | ||
class Address_Registration_Guard | ||
{ | ||
public: | ||
//! Register an address with the GC. | ||
/* \param address The address to register with the GC. The address | ||
* must point to a valid ruby object (RObject). | ||
*/ | ||
Address_Registration_Guard(VALUE* address); | ||
|
||
#endif // Rice__Address_Registration_Guard__hpp_ | ||
//! Register an Object with the GC. | ||
/*! \param object The Object to register with the GC. The object must | ||
* not be destroyed before the Address_Registration_Guard is | ||
* destroyed. | ||
*/ | ||
Address_Registration_Guard(Object* object); | ||
|
||
//! Unregister an address/Object with the GC. | ||
/*! Destruct an Address_Registration_Guard. The address registered | ||
* with the Address_Registration_Guard when it was constructed will | ||
* be unregistered from the GC. | ||
*/ | ||
~Address_Registration_Guard(); | ||
|
||
// Disable copying | ||
Address_Registration_Guard(Address_Registration_Guard const& other) = delete; | ||
Address_Registration_Guard& operator=(Address_Registration_Guard const& other) = delete; | ||
|
||
// Enable moving | ||
Address_Registration_Guard(Address_Registration_Guard&& other); | ||
Address_Registration_Guard& operator=(Address_Registration_Guard&& other); | ||
|
||
//! Get the address that is registered with the GC. | ||
VALUE* address() const; | ||
|
||
/** Called during Ruby's exit process since we should not call | ||
* rb_gc unregister_address there | ||
*/ | ||
static void disable(); | ||
|
||
private: | ||
inline static bool enabled = true; | ||
inline static bool exit_handler_registered = false; | ||
static void registerExitHandler(); | ||
|
||
private: | ||
void registerAddress() const; | ||
void unregisterAddress(); | ||
|
||
VALUE* address_ = nullptr; | ||
}; | ||
} // namespace Rice | ||
|
||
#endif // Rice__Address_Registration_Guard__hpp_ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,4 @@ namespace Rice | |
}; | ||
} // Rice | ||
|
||
#include "Arg.ipp" | ||
|
||
#endif // Rice__Arg__hpp_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,78 @@ | ||
#ifndef Rice__Data_Object__hpp_ | ||
#define Rice__Data_Object__hpp_ | ||
|
||
#include "Data_Object_defn.hpp" | ||
#include "Data_Object.ipp" | ||
/*! \file | ||
* \brief Provides a helper class for wrapping and unwrapping C++ | ||
* objects as Ruby objects. | ||
*/ | ||
|
||
#endif // Rice__Data_Object__hpp_ | ||
namespace Rice | ||
{ | ||
//! A smartpointer-like wrapper for Ruby data objects. | ||
/*! A data object is a ruby object of type T_DATA, which is usually | ||
* created by using the Data_Wrap_Struct or Data_Make_Struct macro. | ||
* This class wraps creation of the data structure, providing a | ||
* type-safe object-oriented interface to the underlying C interface. | ||
* This class works in conjunction with the Data_Type class to ensure | ||
* type safety. | ||
* | ||
* Example: | ||
* \code | ||
* class Foo { }; | ||
* ... | ||
* Data_Type<Foo> rb_cFoo = define_class("Foo"); | ||
* ... | ||
* // Wrap: | ||
* Data_Object<Foo> foo1(new Foo); | ||
* | ||
* // Get value to return: | ||
* VALUE v = foo1.value() | ||
* | ||
* // Unwrap: | ||
* Data_Object<Foo> foo2(v, rb_cFoo); | ||
* \endcode | ||
*/ | ||
template<typename T> | ||
class Data_Object : public Object | ||
{ | ||
static_assert(!std::is_pointer_v<T>); | ||
static_assert(!std::is_reference_v<T>); | ||
static_assert(!std::is_const_v<T>); | ||
static_assert(!std::is_volatile_v<T>); | ||
static_assert(!std::is_void_v<T>); | ||
|
||
public: | ||
static T* from_ruby(VALUE value, bool transferOwnership = false); | ||
|
||
public: | ||
//! Wrap a C++ object. | ||
/*! This constructor is analogous to calling Data_Wrap_Struct. Be | ||
* careful not to call this function more than once for the same | ||
* pointer (in general, it should only be called for newly | ||
* constructed objects that need to be managed by Ruby's garbage | ||
* collector). | ||
* \param obj the object to wrap. | ||
* \param isOwner Should the Data_Object take ownership of the object? | ||
* \param klass the Ruby class to use for the newly created Ruby | ||
* object. | ||
*/ | ||
Data_Object(T* obj, bool isOwner = false, Class klass = Data_Type<T>::klass()); | ||
Data_Object(T& obj, bool isOwner = false, Class klass = Data_Type<T>::klass()); | ||
|
||
//! Unwrap a Ruby object. | ||
/*! This constructor is analogous to calling Data_Get_Struct. Uses | ||
* Data_Type<T>::klass as the class of the object. | ||
* \param value the Ruby object to unwrap. | ||
*/ | ||
Data_Object(Object value); | ||
|
||
T& operator*() const; //!< Return a reference to obj_ | ||
T* operator->() const; //!< Return a pointer to obj_ | ||
T* get() const; //!< Return a pointer to obj_ | ||
|
||
private: | ||
static void check_ruby_type(VALUE value); | ||
}; | ||
} // namespace Rice | ||
|
||
#endif // Rice__Data_Object__hpp_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.