Replace managed class with rcp_managed macro
This commit is contained in:
parent
f5d52dfe98
commit
fac82eaaad
@ -123,16 +123,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
#define rcp_managed(classname) \
|
||||||
class managed
|
rcp<classname> get_rcp() \
|
||||||
{
|
{ \
|
||||||
public:
|
root * r = (root *)this; \
|
||||||
static_assert(std::is_base_of<root, T>::value,
|
return rcp<classname>(r->get_root_rcp()); \
|
||||||
"T must inherit from rcp::root to use rcp::managed<T>");
|
} \
|
||||||
|
template <typename... Args> \
|
||||||
rcp<T> get_rcp()
|
static rcp<classname> create(Args&&... args) \
|
||||||
{
|
{ \
|
||||||
root * r = (root *)this;
|
return (new classname(std::forward<Args>(args)...))->get_rcp(); \
|
||||||
return rcp<T>(r->get_root_rcp());
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|||||||
@ -1,5 +1,23 @@
|
|||||||
#include <rcp.h>
|
#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[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user