Issue 16340: Fixing bugs and improving usability of the InstanceHandle<D> class (dds-psm-cxx-ftf) Source: Real-Time Innovations (Dr. Sumant Tambe, sumant(at)rti.com) Nature: Revision Severity: Significant Summary: The InstanceHandle class in dds-psm-cxx\src\hpp\tdds\core\instancehandle.hpp appears to be incomplete in several ways. 1. A missing constructor InstanceHandle(const DELEGATE & d) : dds::core::Value<DELEGATE>(d) {} There is no way to construct an instance handle except a null one! 2. A missing copy-constructor InstanceHandle(const InstanceHandle& src) : dds::core::Value<DELEGATE>(src.delegate()) { } 3. Typos: a missing return and needs a dot instead of an arrow. InstanceHandle& operator=(const dds::core::null_type& src) { return this->delegate().operator=(src); } 4. Missing comparison operators to allow comparisons like if(dds::null == instance_handle_object) Currently it supports other way round. The proposed solution is to add two overloaded operators in tdds::core namespace. template <class D> bool operator == (dds::core::null_type, InstanceHandle<D> const &ih) { return ih.is_nil(); } template <class D> bool operator != (dds::core::null_type, InstanceHandle<D> const &ih) { return !ih.is_nil(); } 5. Finally, the InstanceHandle<D> class and in general the classes that support comparison with dds::null will benefit from supporting a generic and succinct syntax of the form: if(instance_handle_object). Proposed Solution: An idiomatic way of implenting it is the safe-bool idiom, which has been used widely in standard and boost smart pointer classes, such as std::auto_ptr, boost::shared_ptr. Here is a self-sufficient file that shows one way of implementing the safe bool idiom for the instance handle class: http://cpptruths.googlecode.com/svn/trunk/cpp/instance_handle.cpp Other possible implementation based on the discussions on the boost mailing list is available here: http://codepaste.net/c83uuj Resolution: Revised Text: Actions taken: June 20, 2011: received issue Discussion: End of Annotations:===== m: webmaster@omg.org Date: 20 Jun 2011 00:18:58 -0400 To: Subject: Issue/Bug Report ******************************************************************************* Name: Sumant Tambe Employer: Real-Time Innovations mailFrom: sumant@rti.com Terms_Agreement: I agree Specification: DDS PSM C++ Section: 7 FormalNumber: ptc/2011-01-02 Version: FTF Beta1 Doc_Year: 2011 Doc_Month: January Doc_Day: 01 Page: 4 Title: Fixing bugs and improving usability of the InstanceHandle class Nature: Revision Severity: Significant CODE: 3TMw8 B1: Report Issue Description: The InstanceHandle class in dds-psm-cxx\src\hpp\tdds\core\instancehandle.hpp appears to be incomplete in several ways. 1. A missing constructor InstanceHandle(const DELEGATE & d) : dds::core::Value(d) {} There is no way to construct an instance handle except a null one! 2. A missing copy-constructor InstanceHandle(const InstanceHandle& src) : dds::core::Value(src.delegate()) { } 3. Typos: a missing return and needs a dot instead of an arrow. InstanceHandle& operator=(const dds::core::null_type& src) { return this->delegate().operator=(src); } 4. Missing comparison operators to allow comparisons like if(dds::null == instance_handle_object) Currently it supports other way round. The proposed solution is to add two overloaded operators in tdds::core namespace. template bool operator == (dds::core::null_type, InstanceHandle const &ih) { return ih.is_nil(); } template bool operator != (dds::core::null_type, InstanceHandle const &ih) { return !ih.is_nil(); } 5. Finally, the InstanceHandle class and in general the classes that support comparison with dds::null will benefit from supporting a generic and succinct syntax of the form: if(instance_handle_object). Proposed Solution: An idiomatic way of implenting it is the safe-bool idiom, which has been used widely in standard and boost smart pointer classes, such as std::auto_ptr, boost::shared_ptr. Here is a self-sufficient file that shows one way of implementing the safe bool idiom for the instance handle class: http://cpptruths.googlecode.com/svn/trunk/cpp/instance_handle.cpp Other possible implementation based on the discussions on the boost mailing list is available here: http://codepaste.net/c83uuj