C++: Add sanity checks in StructureWrapper.
This commit is contained in:
parent
2fe07d3fb5
commit
78132e2a13
|
@ -148,6 +148,8 @@ public:
|
||||||
shared_ptr<StructureWrapper<Parent, Struct> >
|
shared_ptr<StructureWrapper<Parent, Struct> >
|
||||||
get_shared_pointer(Parent *parent)
|
get_shared_pointer(Parent *parent)
|
||||||
{
|
{
|
||||||
|
if (!parent)
|
||||||
|
throw Error(SR_ERR_BUG);
|
||||||
this->parent = static_pointer_cast<Parent>(parent->shared_from_this());
|
this->parent = static_pointer_cast<Parent>(parent->shared_from_this());
|
||||||
return shared_ptr<StructureWrapper<Parent, Struct> >(
|
return shared_ptr<StructureWrapper<Parent, Struct> >(
|
||||||
this, reset_parent);
|
this, reset_parent);
|
||||||
|
@ -155,6 +157,8 @@ public:
|
||||||
shared_ptr<StructureWrapper<Parent, Struct> >
|
shared_ptr<StructureWrapper<Parent, Struct> >
|
||||||
get_shared_pointer(shared_ptr<Parent> parent)
|
get_shared_pointer(shared_ptr<Parent> parent)
|
||||||
{
|
{
|
||||||
|
if (!parent)
|
||||||
|
throw Error(SR_ERR_BUG);
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
return shared_ptr<StructureWrapper<Parent, Struct> >(
|
return shared_ptr<StructureWrapper<Parent, Struct> >(
|
||||||
this, reset_parent);
|
this, reset_parent);
|
||||||
|
@ -162,6 +166,8 @@ public:
|
||||||
protected:
|
protected:
|
||||||
static void reset_parent(StructureWrapper<Parent, Struct> *object)
|
static void reset_parent(StructureWrapper<Parent, Struct> *object)
|
||||||
{
|
{
|
||||||
|
if (!object->parent)
|
||||||
|
throw Error(SR_ERR_BUG);
|
||||||
object->parent.reset();
|
object->parent.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue