DDS-PSM-Cxx 1.0b2 FTF Avatar
  1. OMG Issue

DDSPSMC — Fixing bugs and improving usability of the InstanceHandle class

  • Key: DDSPSMC-7
  • Legacy Issue Number: 16340
  • Status: closed  
  • Source: Real-Time Innovations ( Sumant Tambe)
  • 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

  • Reported: DDS-PSM-Cxx 1.0b1 — Mon, 20 Jun 2011 04:00 GMT
  • Disposition: Resolved — DDS-PSM-Cxx 1.0b2
  • Disposition Summary:

    The following changes have been applied to the TInstanceHandle class to address this issue:
    1. Defined a new constructor for initializing the instance handle with a specific type:
    template <typename ARG0>
    TInstanceHandle(const ARG0& arg0);
    2. Added copy constructor

    The problems 3, 4 , and 5 are rejected since an InstanceHandle is a Value as opposed to a Reference type. As such comparison with null_ref is conceptually non-correct and potentially highly misleading. The current API provides an isNil method to check wether the handle is or isn’t nil. In addition, the InstanceHandle defines the NilHandle to allow proper comparisons. To this hand an operator== for the InstanceHandle has been added.

  • Updated: Fri, 6 Mar 2015 20:58 GMT