CONFIG LIB  1.5
Configuration Files Library (by TGG 2020)
memfun.h File Reference
#include <memory>
#include <cstdlib>
#include <cstring>
#include <iostream>

Go to the source code of this file.

Classes

class  MEMFUN
 class with overloaded "new" operator initializing object with zeros More...
 

Macros

#define NEW_TAB(Var, Typ, Len)
 Macro for initializing array with zeros. More...
 
#define DELETE_(OBJ)
 Macro for safe deleteing the object and sets the pointer to zero. More...
 
#define DELETE_TAB(OBJ)
 Macro for safe deleteing the array and sets the pointer to zero. More...
 

Functions

template<class typ >
void ERASE (typ **ptr, const char *text="(No name specified)")
 Safe erasing of the object and sets the pointer to zero. More...
 

Detailed Description

This file contains some smart functions, operators, macros for safe initializing end erasing the memory

Definition in file memfun.h.

Macro Definition Documentation

◆ DELETE_

#define DELETE_ (   OBJ)
Value:
{ \
if( OBJ ) {delete OBJ; OBJ = NULL;} \
}

Macro for safe deleteing the object and sets the pointer to zero.

Parameters
OBJ- pointer to the object

Definition at line 85 of file memfun.h.

◆ DELETE_TAB

#define DELETE_TAB (   OBJ)
Value:
{ \
if( OBJ ) std::cerr << " Delete tab: " << #OBJ << " address = " << OBJ << std::endl; \
if( OBJ ) {delete [] OBJ; OBJ = NULL;} \
}

Macro for safe deleteing the array and sets the pointer to zero.

Parameters
OBJ- pointer to the array

Definition at line 98 of file memfun.h.

◆ NEW_TAB

#define NEW_TAB (   Var,
  Typ,
  Len 
)
Value:
{ \
(Var) = new Typ[Len]; \
std::cerr << " Creating object: " << #Var << " address = " << Var << " typ: " << #Typ << " size (type units) = " << Len << std::endl; \
memset( (Var), 0, sizeof(Typ)*(Len) ); \
}

Macro for initializing array with zeros.

Parameters
Var- pointer to the array
Typ- type of array (e.g. double)
Len- legth of array

Definition at line 72 of file memfun.h.

Function Documentation

◆ ERASE()

template<class typ >
void ERASE ( typ **  ptr,
const char *  text = "(No name specified)" 
)

Safe erasing of the object and sets the pointer to zero.

Parameters
ptr- reference to the object pointer
text- optional comment to be printed to stderr

Definition at line 52 of file memfun.h.

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 }