Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:15:18

0001 /*
0002  Created on: 2011-06-02
0003  Created by: Andrey BETENEV
0004  Copyright (c) 2011-2014 OPEN CASCADE SAS
0005 
0006  This file is part of Open CASCADE Technology software library.
0007 
0008  This library is free software; you can redistribute it and/or modify it under
0009  the terms of the GNU Lesser General Public License version 2.1 as published
0010  by the Free Software Foundation, with special exception defined in the file
0011  OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012  distribution for complete text of the license and disclaimer of any warranty.
0013 
0014  Alternatively, this file may be used under the terms of Open CASCADE
0015  commercial license or contractual agreement.
0016 */
0017 
0018 #if !defined(_MSC_VER) || !defined(_MANAGED)
0019   #error This file is usable only in C++/CLI (.NET) programs
0020 #endif
0021 
0022 #pragma once
0023 
0024 using namespace System;
0025 using namespace System::Collections::Generic;
0026 
0027 //! Template CLI class providing the way to encapsulate instance of C++
0028 //! class as a field in the C++/CLI (ref) class.
0029 //!
0030 //! It can be helpful to encapsulate OCCT Handles, maps, arrays, etc.
0031 //!
0032 //! Use of variable of the Haft type is very similar to that of encapsulated
0033 //! class:
0034 //! - Default constructor creates default-constructed C++ instance
0035 //! - Non-default construction is possible by copy or by initialization from
0036 //!   compatible pointer (e.g. Haft for Handle can be initialized by pointer
0037 //!   returned by operator new for a handled class)
0038 //! - Underlying C++ instance is accessed by operator ()
0039 
0040 template <class CPPClass>
0041 public ref class NCollection_Haft
0042 {
0043 public:
0044   //! Initialize CLI Haft object by default-constructed C++ object
0045   NCollection_Haft() { myPtr = new CPPClass; }
0046 
0047   //! Initialize CLI Haft object by compatible C++ pointer
0048   template <class T>
0049   NCollection_Haft(const T* aPtr)
0050   {
0051     myPtr = new CPPClass(aPtr);
0052   }
0053 
0054   //! Initialize CLI Haft object by C++ class object
0055   NCollection_Haft(const CPPClass& aPtr) { myPtr = new CPPClass(aPtr); }
0056 
0057   //! Destructor - invoked explicitly by delete, or automatically
0058   //! when local variable is scoped out
0059   ~NCollection_Haft() { this->Nullify(); }
0060 
0061   //! Finalizer - called undeterministically by garbage collector
0062   !NCollection_Haft() { this->Nullify(); }
0063 
0064   //! Function call operator is provided to access underlying C++ object
0065   CPPClass& operator()() { return *myPtr; }
0066 
0067 protected:
0068   //! Invalidate the haft
0069   void Nullify()
0070   {
0071     delete myPtr;
0072     myPtr = 0;
0073   }
0074 
0075 protected:
0076   CPPClass* myPtr;
0077 };