mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0024023: Revamp the OCCT Handle -- handle
Macro defining Handle class is replaced by template class implementing the same concept (defined in Standard_Handle.hxx and Standard_Transient.hxx), opencascade::handle<>. Header file Standard_DefineHandle.hxx becomes deprecated: the only useful macro DEFINE_STANDARD_RTTI is defined now in Standard_Type.hxx. Standard_DefineHandle.hxx is kept for compatibility, it defines macros previously used for definition of Handles and RTTI as empty. Macro DEFINE_STANDARD_HANDLE(C1,C2) is also kept for compatibility; now it expands to typedef "Handle_C1" to corresponding handle class. Definitions of macro Handle() and STANDARD_TYPE() moved from Standard_Macro.hxx to Standard_Handle.hxx (new file) and Standard_Type.hxx, respectively. New template class NCollection_Shared added, allowing to define sub-class manipulated by handle, for any non-transient class. Adaptations for compiling with GCC 4.7
This commit is contained in:
@@ -72,7 +72,6 @@ NCollection_SparseArrayBase.cxx
|
||||
NCollection_CellFilter.hxx
|
||||
NCollection_CellFilterNDim.hxx
|
||||
NCollection_Handle.hxx
|
||||
NCollection_Handle.cxx
|
||||
|
||||
NCollection_Comparator.hxx
|
||||
NCollection_QuickSort.hxx
|
||||
@@ -88,3 +87,4 @@ NCollection_Vec4.hxx
|
||||
NCollection_Mat4.hxx
|
||||
|
||||
NCollection_StlIterator.hxx
|
||||
NCollection_Shared.hxx
|
||||
|
@@ -25,7 +25,6 @@
|
||||
// Declaration of Sequence class managed by Handle
|
||||
|
||||
#define DEFINE_HSEQUENCE(HClassName, _SequenceType_) \
|
||||
DEFINE_STANDARD_HANDLE (HClassName, MMgt_TShared) \
|
||||
class HClassName : public _SequenceType_, public MMgt_TShared { \
|
||||
public: \
|
||||
DEFINE_STANDARD_ALLOC \
|
||||
@@ -44,7 +43,8 @@ class HClassName : public _SequenceType_, public MMgt_TShared { \
|
||||
_SequenceType_::Append (theOther->ChangeSequence()); \
|
||||
} \
|
||||
DEFINE_STANDARD_RTTI (HClassName, MMgt_TShared) \
|
||||
};
|
||||
}; \
|
||||
DEFINE_STANDARD_HANDLE (HClassName, MMgt_TShared)
|
||||
|
||||
#define IMPLEMENT_HSEQUENCE(HClassName)
|
||||
|
||||
|
@@ -1,16 +0,0 @@
|
||||
// Created on: 2009-01-30
|
||||
// Created by: Andrey BETENEV (abv)
|
||||
// Copyright (c) 2009-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <NCollection_Handle.hxx>
|
@@ -74,17 +74,23 @@ class NCollection_Handle : public Handle(Standard_Transient)
|
||||
: Handle(Standard_Transient) (theObject ? new Ptr (theObject) : 0) {}
|
||||
|
||||
//! Cast handle to contained type
|
||||
T* operator -> () { return ((Ptr*)ControlAccess())->myPtr; }
|
||||
T* get () { return ((Ptr*)Handle(Standard_Transient)::get())->myPtr; }
|
||||
|
||||
//! Cast handle to contained type
|
||||
const T* get () const { return ((Ptr*)Handle(Standard_Transient)::get())->myPtr; }
|
||||
|
||||
//! Cast handle to contained type
|
||||
T* operator -> () { return get(); }
|
||||
|
||||
//! Cast handle to contained type
|
||||
const T* operator -> () const { return ((Ptr*)ControlAccess())->myPtr; }
|
||||
const T* operator -> () const { return get(); }
|
||||
|
||||
//! Cast handle to contained type
|
||||
T& operator * () { return *((Ptr*)ControlAccess())->myPtr; }
|
||||
T& operator * () { return *get(); }
|
||||
|
||||
//! Cast handle to contained type
|
||||
const T& operator * () const { return *((Ptr*)ControlAccess())->myPtr; }
|
||||
|
||||
const T& operator * () const { return *get(); }
|
||||
|
||||
//! Downcast arbitrary Handle to the argument type if contained
|
||||
//! object is Handle for this type; returns null otherwise
|
||||
static NCollection_Handle<T> DownCast (const Handle(Standard_Transient)& theOther)
|
||||
|
62
src/NCollection/NCollection_Shared.hxx
Normal file
62
src/NCollection/NCollection_Shared.hxx
Normal file
@@ -0,0 +1,62 @@
|
||||
// Created on: 2015-06-26
|
||||
// Created by: Andrey Betenev
|
||||
// Copyright (c) 2015 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef NCollection_Shared_HeaderFile
|
||||
#define NCollection_Shared_HeaderFile
|
||||
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
//! Template defining a class derived from the specified base class and
|
||||
//! Standard_Transient, and supporting OCCT RTTI.
|
||||
//!
|
||||
//! This provides possibility to use Handes for types not initially intended
|
||||
//! to be dynamically allocated.
|
||||
//!
|
||||
//! Current limitation is that only copy and constructors with 1-3 arguments are defined,
|
||||
//! calling those of the argument class (default constructor must be available).
|
||||
//! It can be improved when perfect forwarding of template arguments is supported
|
||||
//! by all compilers used for OCCT.
|
||||
//!
|
||||
//! The intent is similar to std::make_shared<> in STL, except that this
|
||||
//! implementation defines a separate type.
|
||||
|
||||
template <class T, typename = typename std::enable_if<! std::is_base_of<Standard_Transient, T>::value>::type>
|
||||
class NCollection_Shared : public Standard_Transient, public T
|
||||
{
|
||||
public:
|
||||
DEFINE_STANDARD_ALLOC
|
||||
DEFINE_NCOLLECTION_ALLOC
|
||||
|
||||
//! Default constructor
|
||||
NCollection_Shared () {}
|
||||
|
||||
//! Constructor with single argument
|
||||
template <typename T1>
|
||||
NCollection_Shared (T1 arg1) : T(arg1) {}
|
||||
|
||||
//! Constructor with two arguments
|
||||
template <typename T1, typename T2>
|
||||
NCollection_Shared (T1 arg1, T2 arg2) : T(arg1, arg2) {}
|
||||
|
||||
/* this could work...
|
||||
//! Forwarding constructor
|
||||
template<typename... Args>
|
||||
NCollection_Shared (Args&&... args)
|
||||
: T (std::forward<Args>(args)...)
|
||||
{}
|
||||
*/
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user