3 Created by: Andrey BETENEV
4 Copyright (c) 2011-2014 OPEN CASCADE SAS
6 This file is part of Open CASCADE Technology software library.
8 This library is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License version 2.1 as published
10 by the Free Software Foundation, with special exception defined in the file
11 OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 distribution for complete text of the license and disclaimer of any warranty.
14 Alternatively, this file may be used under the terms of Open CASCADE
15 commercial license or contractual agreement.
18 #if ! defined(_MSC_VER) || ! defined(_MANAGED)
19 #error This file is usable only in C++/CLI (.NET) programs
24 using namespace System;
25 using namespace System::Collections::Generic;
27 //! Template CLI class providing the way to encapsulate instance of C++
28 //! class as a field in the C++/CLI (ref) class.
30 //! It can be helpful to encapsulate OCCT Handles, maps, arrays, etc.
32 //! Use of variable of the Haft type is very similar to that of encapsulated
34 //! - Default constructor creates default-constructed C++ instance
35 //! - Non-default construction is possible by copy or by initialization from
36 //! compatible pointer (e.g. Haft for Handle can be initialized by pointer
37 //! returned by operator new for a handled class)
38 //! - Underlying C++ instance is accessed by operator ()
40 template <class CPPClass>
41 public ref class NCollection_Haft
44 //! Initialize CLI Haft object by default-constructed C++ object
50 //! Initialize CLI Haft object by compatible C++ pointer
52 NCollection_Haft (const T* aPtr)
54 myPtr = new CPPClass (aPtr);
57 //! Initialize CLI Haft object by C++ class object
58 NCollection_Haft (const CPPClass& aPtr)
60 myPtr = new CPPClass (aPtr);
63 //! Destructor - invoked explicitly by delete, or automatically
64 //! when local variable is scoped out
70 //! Finalizer - called undeterministically by garbage collector
76 //! Function call operator is provided to access underlying C++ object
77 CPPClass& operator () () { return *myPtr; }
80 //! Invalidate the haft