diff options
author | Vincent Richard <[email protected]> | 2005-09-02 10:53:24 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2005-09-02 10:53:24 +0000 |
commit | 8cae762d46755a0588436a29e9a17e3f1971175d (patch) | |
tree | 25ff76e47866a23ca4e712fed998a6dfca8074e7 | |
parent | NEVER call thisRef() from the object's constructor. (diff) | |
download | vmime-8cae762d46755a0588436a29e9a17e3f1971175d.tar.gz vmime-8cae762d46755a0588436a29e9a17e3f1971175d.zip |
Throw exception in debug mode when thisRef()/thisWeakRef() is called from the object's constructor.
-rw-r--r-- | src/object.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/object.cpp b/src/object.cpp index dc4602c7..1d586f49 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -104,24 +104,68 @@ void object::releaseWeak(utility::weak_ref_base* w) const 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); } 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); } 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()); } 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()); } |