Replace managed class with rcp_managed macro

This commit is contained in:
Josh Holtrop 2026-02-23 20:19:37 -05:00
parent f5d52dfe98
commit fac82eaaad
2 changed files with 28 additions and 12 deletions

View File

@ -123,16 +123,14 @@ public:
}
};
template <typename T>
class managed
{
public:
static_assert(std::is_base_of<root, T>::value,
"T must inherit from rcp::root to use rcp::managed<T>");
rcp<T> get_rcp()
{
root * r = (root *)this;
return rcp<T>(r->get_root_rcp());
#define rcp_managed(classname) \
rcp<classname> get_rcp() \
{ \
root * r = (root *)this; \
return rcp<classname>(r->get_root_rcp()); \
} \
template <typename... Args> \
static rcp<classname> create(Args&&... args) \
{ \
return (new classname(std::forward<Args>(args)...))->get_rcp(); \
}
};

View File

@ -1,5 +1,23 @@
#include <rcp.h>
class MyBase : public root
{
protected:
MyBase(int x, int y) {}
public:
rcp_managed(MyBase);
};
class MyDerived : public MyBase
{
protected:
MyDerived(double v) : MyBase(1, 2) {}
public:
rcp_managed(MyDerived)
};
int main(int argc, char * argv[])
{
return 0;