Skip to content

Commit

Permalink
Big header cleanup - separate hpp and ipp files. Thus remove defn.hpp…
Browse files Browse the repository at this point in the history
… 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
cfis committed Dec 9, 2024
1 parent e0b4cd8 commit fe15468
Show file tree
Hide file tree
Showing 85 changed files with 5,735 additions and 6,164 deletions.
9,452 changes: 4,651 additions & 4,801 deletions include/rice/rice.hpp

Large diffs are not rendered by default.

75 changes: 72 additions & 3 deletions rice/Address_Registration_Guard.hpp
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_
79 changes: 0 additions & 79 deletions rice/Address_Registration_Guard_defn.hpp

This file was deleted.

2 changes: 0 additions & 2 deletions rice/Arg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,4 @@ namespace Rice
};
} // Rice

#include "Arg.ipp"

#endif // Rice__Arg__hpp_
3 changes: 0 additions & 3 deletions rice/Constructor.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef Rice__Constructor__hpp_
#define Rice__Constructor__hpp_

#include "detail/Wrapper.hpp"
#include "cpp_api/Object_defn.hpp"

namespace Rice
{
//! Define a Type's Constructor and it's arguments.
Expand Down
76 changes: 73 additions & 3 deletions rice/Data_Object.hpp
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_
5 changes: 0 additions & 5 deletions rice/Data_Object.ipp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#ifndef Rice__Data_Object__ipp_
#define Rice__Data_Object__ipp_

#include "Data_Type_defn.hpp"

#include <algorithm>

Expand Down Expand Up @@ -656,4 +652,3 @@ namespace Rice::detail
Arg* arg_ = nullptr;
};
}
#endif // Rice__Data_Object__ipp_
85 changes: 0 additions & 85 deletions rice/Data_Object_defn.hpp

This file was deleted.

Loading

0 comments on commit fe15468

Please sign in to comment.