0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / NCollection / NCollection_Haft.h
CommitLineData
b311480e 1/*
2 Created on: 2011-06-02
3 Created by: Andrey BETENEV
973c2be1 4 Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 5
973c2be1 6 This file is part of Open CASCADE Technology software library.
b311480e 7
d5f74e42 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
973c2be1 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.
b311480e 13
973c2be1 14 Alternatively, this file may be used under the terms of Open CASCADE
15 commercial license or contractual agreement.
b311480e 16*/
9a0a1cb8
A
17
18#if ! defined(_MSC_VER) || ! defined(_MANAGED)
19#error This file is usable only in C++/CLI (.NET) programs
20#endif
21
22#pragma once
23
24using namespace System;
25using namespace System::Collections::Generic;
26
27//! Template CLI class providing the way to encapsulate instance of C++
28//! class as a field in the C++/CLI (ref) class.
29//!
30//! It can be helpful to encapsulate OCCT Handles, maps, arrays, etc.
31//!
32//! Use of variable of the Haft type is very similar to that of encapsulated
33//! class:
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 ()
39
40template <class CPPClass>
41public ref class NCollection_Haft
42{
43public:
44 //! Initialize CLI Haft object by default-constructed C++ object
45 NCollection_Haft ()
46 {
47 myPtr = new CPPClass;
48 }
49
50 //! Initialize CLI Haft object by compatible C++ pointer
51 template <class T>
52 NCollection_Haft (const T* aPtr)
53 {
54 myPtr = new CPPClass (aPtr);
55 }
56
57 //! Initialize CLI Haft object by C++ class object
58 NCollection_Haft (const CPPClass& aPtr)
59 {
60 myPtr = new CPPClass (aPtr);
61 }
62
63 //! Destructor - invoked explicitly by delete, or automatically
64 //! when local variable is scoped out
65 ~NCollection_Haft ()
66 {
67 this->Nullify();
68 }
69
70 //! Finalizer - called undeterministically by garbage collector
71 !NCollection_Haft ()
72 {
73 this->Nullify();
74 }
75
76 //! Function call operator is provided to access underlying C++ object
77 CPPClass& operator () () { return *myPtr; }
78
79protected:
80 //! Invalidate the haft
81 void Nullify ()
82 {
83 delete myPtr;
84 myPtr = 0;
85 }
86
87protected:
88 CPPClass* myPtr;
89};