MantisBT - Community
View Issue Details
0025444Community[OCCT] OCCT:Foundation Classespublic2014-11-02 10:042017-08-14 17:18
Roman Lygin 
abv 
normalintegration request 
resolvedopen 
[OCCT] 6.8.0 
[OCCT] Unscheduled 
0025444: Enabling user-defined deleter for NCollection_Handle
Until this enhancement NCollection_Handle would enforce deletion of the object passed to its constructor. However this must not be done in the scenario when the handle does not own but just wraps the object.

Consider the following scenario:

class MyType; //not manipulated by handle

class MyTypeOwner
{
public:
    std::unique_ptr<MyType> myObject;
};

std::vector<Handle_Standard_Transient> v; //holds OCC handles and need to store raw pointers MyType*.

v.push_back (new Geom_Circle (...));
...
const MyTypeOwner& o = ...;
NCollection_Handle<MyType> h (o.myObject.get());
v.push_back (h);
//upon leaving the scope, v will nullify handles, each handle will attempt to delete MyType pointers although it does not own it

The enhancement introduces user-defined deleters similar to what C++ standard smart pointers do. The current behavior is preserved by using NCollection_Handle_DefaultDelete as default template parameter.

The above code can be now reworked as follows:
NCollection_Handle<MyType,NCollection_Handle_EmptyDelete<MyType> > h (o.myObject.get());


Unlike C++ standard, deleters objects cannot be passed as constructor arguments. For simplicity they are always internally created and thus must meet DefaultConstructible requirement. If stronger standard compliance is required and deleters object are to be stored then implementation must foresee size optimization (e.g. as described here http://talesofcpp.fusionfenix.com/post-18/episode-ten-when-size-does-matter [^]).
No tags attached.
Issue History
2014-11-02 10:04Roman LyginNew Issue
2014-11-02 10:04Roman LyginAssigned To => abv
2014-11-02 10:10gitNote Added: 0034002
2014-11-02 10:12Roman LyginStatusnew => resolved
2014-11-05 09:15abvTarget Version6.8.0 => 7.0.0
2015-12-14 22:39abvTarget Version7.0.0 => 7.1.0
2016-11-03 17:07abvTarget Version7.1.0 => 7.2.0
2017-08-14 17:18abvTarget Version7.2.0 => Unscheduled

Notes
(0034002)
git   
2014-11-02 10:10   
Branch CR25444 has been created by Roman Lygin.

SHA-1: 9e18d3785e1c59a7f12f2f6f1a6819ecdd31eda8


Detailed log of new commits:

Author: Roman Lygin
Date: Sun Nov 2 10:10:36 2014 +0400

    0025444: Enabling user-defined deleter for NCollection_Handle