1 // File: NCollection_Haft.h
2 // Created: 02.06.11 08:12:42
3 // Author: Andrey BETENEV
4 // Copyright: OPEN CASCADE SAS 2011
6 #if ! defined(_MSC_VER) || ! defined(_MANAGED)
7 #error This file is usable only in C++/CLI (.NET) programs
12 using namespace System;
13 using namespace System::Collections::Generic;
15 //! Template CLI class providing the way to encapsulate instance of C++
16 //! class as a field in the C++/CLI (ref) class.
18 //! It can be helpful to encapsulate OCCT Handles, maps, arrays, etc.
20 //! Use of variable of the Haft type is very similar to that of encapsulated
22 //! - Default constructor creates default-constructed C++ instance
23 //! - Non-default construction is possible by copy or by initialization from
24 //! compatible pointer (e.g. Haft for Handle can be initialized by pointer
25 //! returned by operator new for a handled class)
26 //! - Underlying C++ instance is accessed by operator ()
28 template <class CPPClass>
29 public ref class NCollection_Haft
32 //! Initialize CLI Haft object by default-constructed C++ object
38 //! Initialize CLI Haft object by compatible C++ pointer
40 NCollection_Haft (const T* aPtr)
42 myPtr = new CPPClass (aPtr);
45 //! Initialize CLI Haft object by C++ class object
46 NCollection_Haft (const CPPClass& aPtr)
48 myPtr = new CPPClass (aPtr);
51 //! Destructor - invoked explicitly by delete, or automatically
52 //! when local variable is scoped out
58 //! Finalizer - called undeterministically by garbage collector
64 //! Function call operator is provided to access underlying C++ object
65 CPPClass& operator () () { return *myPtr; }
68 //! Invalidate the haft