netgen/libsrc/general/dynamicmem.hpp

104 lines
1.9 KiB
C++
Raw Normal View History

2023-08-05 13:36:20 +05:00
not needed anymore ?
2009-01-13 04:40:13 +05:00
#ifndef FILE_DYNAMICMEM
#define FILE_DYNAMICMEM
/**************************************************************************/
/* File: dynamicmem.hpp */
/* Author: Joachim Schoeberl */
/* Date: 12. Feb. 2003 */
/**************************************************************************/
2009-07-20 14:36:36 +06:00
namespace netgen
{
2009-01-13 04:40:13 +05:00
class BaseDynamicMem
{
private:
static BaseDynamicMem *first, *last;
BaseDynamicMem *prev, *next;
size_t size;
char * ptr;
char * name;
protected:
BaseDynamicMem ();
~BaseDynamicMem ();
void Alloc (size_t s);
void ReAlloc (size_t s);
void Free ();
2012-08-20 20:10:23 +06:00
// char * Ptr() { return ptr; }
char * Ptr() const { return ptr; }
2009-01-13 04:40:13 +05:00
void Swap (BaseDynamicMem & m2);
public:
void SetName (const char * aname);
static void Print ();
static void GetUsed (int nr, char * ch);
};
template <typename T>
class DynamicMem : public BaseDynamicMem
{
public:
DynamicMem ()
: BaseDynamicMem ()
{
;
}
DynamicMem (size_t s)
: BaseDynamicMem ()
{
Alloc (s);
}
void Alloc (size_t s)
{
BaseDynamicMem::Alloc (sizeof(T) * s);
}
void ReAlloc (size_t s)
{
BaseDynamicMem::ReAlloc (sizeof(T) * s);
}
void Free ()
{
BaseDynamicMem::Free ();
}
2012-08-20 20:10:23 +06:00
/*
2009-01-13 04:40:13 +05:00
const T * Ptr() const
{
return reinterpret_cast<const T*> (BaseDynamicMem::Ptr());
}
2012-08-20 20:10:23 +06:00
*/
const T * Ptr()
2009-01-13 04:40:13 +05:00
{
return reinterpret_cast<T*> (BaseDynamicMem::Ptr());
}
2012-08-20 20:10:23 +06:00
/*
2009-01-13 04:40:13 +05:00
operator const T* () const
{
return reinterpret_cast<const T*> (BaseDynamicMem::Ptr());
}
2012-08-20 20:10:23 +06:00
*/
operator T* () const
2009-01-13 04:40:13 +05:00
{
return reinterpret_cast<T*> (BaseDynamicMem::Ptr());
}
void Swap (DynamicMem<T> & m2)
{
BaseDynamicMem::Swap (m2);
}
protected:
DynamicMem (const DynamicMem & m);
DynamicMem & operator= (const DynamicMem & m);
};
2009-07-20 14:36:36 +06:00
}
2009-01-13 04:40:13 +05:00
#endif