Throw exception in debug mode when thisRef()/thisWeakRef() is called from the object's constructor.
This commit is contained in:
parent
5c3e21ee1d
commit
8cae762d46
@ -104,24 +104,68 @@ void object::releaseWeak(utility::weak_ref_base* w) const
|
|||||||
|
|
||||||
ref <object> object::thisRef()
|
ref <object> object::thisRef()
|
||||||
{
|
{
|
||||||
|
#if VMIME_DEBUG
|
||||||
|
if (m_strongCount == 0)
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "ERROR: thisRef() MUST NOT be called from the object constructor."
|
||||||
|
<< " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl;
|
||||||
|
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
#endif // VMIME_DEBUG
|
||||||
|
|
||||||
return ref <object>::fromPtr(this);
|
return ref <object>::fromPtr(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ref <const object> object::thisRef() const
|
ref <const object> object::thisRef() const
|
||||||
{
|
{
|
||||||
|
#if VMIME_DEBUG
|
||||||
|
if (m_strongCount == 0)
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "ERROR: thisRef() MUST NOT be called from the object constructor."
|
||||||
|
<< " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl;
|
||||||
|
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
#endif // VMIME_DEBUG
|
||||||
|
|
||||||
return ref <const object>::fromPtr(this);
|
return ref <const object>::fromPtr(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
weak_ref <object> object::thisWeakRef()
|
weak_ref <object> object::thisWeakRef()
|
||||||
{
|
{
|
||||||
|
#if VMIME_DEBUG
|
||||||
|
if (m_strongCount == 0)
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "ERROR: thisWeakRef() MUST NOT be called from the object constructor."
|
||||||
|
<< " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl;
|
||||||
|
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
#endif // VMIME_DEBUG
|
||||||
|
|
||||||
return weak_ref <object>(thisRef());
|
return weak_ref <object>(thisRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
weak_ref <const object> object::thisWeakRef() const
|
weak_ref <const object> object::thisWeakRef() const
|
||||||
{
|
{
|
||||||
|
#if VMIME_DEBUG
|
||||||
|
if (m_strongCount == 0)
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "ERROR: thisWeakRef() MUST NOT be called from the object constructor."
|
||||||
|
<< " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl;
|
||||||
|
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
#endif // VMIME_DEBUG
|
||||||
|
|
||||||
return weak_ref <const object>(thisRef());
|
return weak_ref <const object>(thisRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user