CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
memfun.h File Reference

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

#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.
 
#define DELETE_(OBJ)
 Macro for safe deleteing the object and sets the pointer to zero.
 
#define DELETE_TAB(OBJ)
 Macro for safe deleteing the array and sets the pointer to zero.
 

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.
 

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 84 of file memfun.h.

84#define DELETE_( OBJ ) \
85{ \
86 if( OBJ ) {delete OBJ; OBJ = NULL;} \
87}

Referenced by AIRFOIL::ReadNaca().

◆ 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 97 of file memfun.h.

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}

Referenced by AIRFOIL::Clean(), GRID_ARRAYS::DeleteWyn(), and GRID_ARRAYS::~GRID_ARRAYS().

◆ 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 71 of file memfun.h.

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}

Referenced by GRID_ARRAYS::InitCommon(), GRID_ARRAYS::InitForPanukl(), GRID_ARRAYS::InitForPress(), GRID_ARRAYS::InitRob(), GRID_ARRAYS::ReadDAT(), GRID_ARRAYS::ReadDATw(), GRID_ARRAYS::ReadIN1(), GRID_ARRAYS::ReadIN2(), and GRID_ARRAYS::ReadINP().

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}