Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04: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 ()
0046   {
0047     myPtr = new CPPClass;
0048   }
0049 
0050   //! Initialize CLI Haft object by compatible C++ pointer
0051   template <class T>
0052   NCollection_Haft (const T* aPtr)
0053   {
0054     myPtr = new CPPClass (aPtr);
0055   }
0056 
0057   //! Initialize CLI Haft object by C++ class object
0058   NCollection_Haft (const CPPClass& aPtr)
0059   {
0060     myPtr = new CPPClass (aPtr);
0061   }
0062 
0063   //! Destructor - invoked explicitly by delete, or automatically 
0064   //! when local variable is scoped out
0065   ~NCollection_Haft ()
0066   {
0067     this->Nullify();
0068   }
0069 
0070   //! Finalizer - called undeterministically by garbage collector
0071   !NCollection_Haft ()
0072   {
0073     this->Nullify();
0074   }
0075 
0076   //! Function call operator is provided to access underlying C++ object
0077   CPPClass& operator () () { return *myPtr; }
0078 
0079 protected:
0080   //! Invalidate the haft
0081   void Nullify ()
0082   {
0083     delete myPtr;
0084     myPtr = 0;
0085   }
0086 
0087 protected:
0088   CPPClass* myPtr;
0089 };