MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
destr.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbutil/destr.h,v 1.18 2017/01/12 14:44:04 masarati Exp $ */
2 /*
3  * This library comes with MBDyn (C), a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  *
10  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
11  * via La Masa, 34 - 20156 Milano, Italy
12  * http://www.aero.polimi.it
13  *
14  * Changing this copyright notice is forbidden.
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation (version 2 of the License).
19  *
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  */
30 
31 #ifndef DESTR_H
32 #define DESTR_H
33 
34 #include "myassert.h"
35 #include "mynewmem.h"
36 
37 template <class T>
38 class Destructor {
39 public:
40  Destructor(void) {
41  NO_OP;
42  };
43 
44  virtual ~Destructor(void) {
45  NO_OP;
46  };
47 
48  virtual void Destroy(T*&) const = 0;
49 };
50 
51 
52 template <class T>
53 class LinkDestructor : public Destructor<T> {
54 public:
55  LinkDestructor(void) : Destructor<T>() {
56  NO_OP;
57  };
58 
59  ~LinkDestructor(void) {
60  NO_OP;
61  };
62 
63  void Destroy(T*& pnt) const {
64  NO_OP;
65  };
66 };
67 
68 
69 template <class T>
70 class HardDestructor : public Destructor<T> {
71 public:
72  HardDestructor(void) : Destructor<T>() {
73  NO_OP;
74  };
75 
76  ~HardDestructor(void) {
77  NO_OP;
78  };
79 
80  void Destroy(T*& pnt) const {
81  if (pnt != NULL) {
82  SAFEDELETE(pnt);
83  pnt = NULL;
84  }
85  };
86 };
87 
88 template <class T>
89 class ArrayHardDestructor : public Destructor<T> {
90 public:
92  NO_OP;
93  };
94 
96  NO_OP;
97  };
98 
99  void Destroy(T*& pnt) const {
100  if (pnt != NULL) {
101  SAFEDELETEARR(pnt);
102  pnt = NULL;
103  }
104  };
105 };
106 
107 #define LINKDESTRUCTOR(d, type, m) LinkDestructor<type> d
108 #define HARDDESTRUCTOR(d, type, m) HardDestructor<type> d
109 #define ARRAYHARDDESTRUCTOR(d, type, m) ArrayHardDestructor<type> d
110 
111 #endif /* DESTR_H */
112 
LinkDestructor(void)
Definition: destr.h:55
void Destroy(T *&pnt) const
Definition: destr.h:63
void Destroy(T *&pnt) const
Definition: destr.h:80
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
#define NO_OP
Definition: myassert.h:74
void Destroy(T *&pnt) const
Definition: destr.h:99
~ArrayHardDestructor(void)
Definition: destr.h:95
~LinkDestructor(void)
Definition: destr.h:59
ArrayHardDestructor(void)
Definition: destr.h:91
~HardDestructor(void)
Definition: destr.h:76
virtual void Destroy(T *&) const =0
Destructor(void)
Definition: destr.h:40
virtual ~Destructor(void)
Definition: destr.h:44
HardDestructor(void)
Definition: destr.h:72
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710