CONFIG LIB  1.5
Configuration Files Library (by TGG 2020)
memfun.h
Go to the documentation of this file.
1 /*********************************************************************/
2 /* */
3 /* Config files library - (C) TGG 2015 */
4 /* */
5 /*********************************************************************/
6 /* Warsaw 2008 */
7 /*********************************************************************/
8 /* */
9 /* File: memfun.h */
10 /* */
11 /* Written by: F.A.Dul, T.Grabowski */
12 /* */
13 /* Contents: smart memory functions, operators, macros */
14 /* */
15 /*********************************************************************/
16 /* */
17 /* */
18 
23 #ifndef _MEMFUN_H_
24 #define _MEMFUN_H_
25 
26 #include <memory>
27 #include <cstdlib>
28 #include <cstring>
29 #include <iostream>
30 
32 
33 class MEMFUN
34 {
35  public:
36 
42  static void* operator new ( size_t st , const char *text = "(unknown)", int ierr_print = 1 );
43 
44 };
45 
51 
52 template <class typ> void ERASE( typ **ptr , const char *text = "(No name specified)" )
53 {
54  if( *ptr )
55  {
56  //std::cerr << "Delete performed ptr " << (int)*ptr << text << std::endl;
57  delete *ptr;
58  *ptr = NULL;
59  }
60  else
61  std::cerr << "Warning! Pointer to : " << text << " is NULL !!! No delete performed" << std::endl;
62 }
63 
70 
71 #define NEW_TAB( Var, Typ, Len ) \
72 { \
73  (Var) = new Typ[Len]; \
74  std::cerr << " Creating object: " << #Var << " address = " << Var << " typ: " << #Typ << " size (type units) = " << Len << std::endl; \
75  memset( (Var), 0, sizeof(Typ)*(Len) ); \
76 }
77 
82 
83 #ifndef DELETE_
84 #define DELETE_( OBJ ) \
85 { \
86  if( OBJ ) {delete OBJ; OBJ = NULL;} \
87 }
88 #endif
89 // if( OBJ ) std::cerr << " Delete object: " << #OBJ << " address = " << OBJ << std::endl;
90 
95 
96 #ifndef DELETE_TAB
97 #define DELETE_TAB( OBJ ) \
98 { \
99  if( OBJ ) std::cerr << " Delete tab: " << #OBJ << " address = " << OBJ << std::endl; \
100  if( OBJ ) {delete [] OBJ; OBJ = NULL;} \
101 }
102 #endif
103 
104 #endif /*_MEMFUN_H_*/
ERASE
void ERASE(typ **ptr, const char *text="(No name specified)")
Safe erasing of the object and sets the pointer to zero.
Definition: memfun.h:52
MEMFUN
class with overloaded "new" operator initializing object with zeros
Definition: memfun.h:34