/* libzz
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2000-2006, Toni Thomsson <toni@tonjac.org> 
*/

#ifndef zz_allocmap_h
#define zz_allocmap_h

#include "zz_export.h"

#ifdef _WIN32
    // Debugsymbols longer than 255 chars
    #pragma warning(disable: 4786) 
    #pragma warning(disable: 4251)
    #include "windows.h"
#endif

#include <stddef.h>
#include <malloc.h>
#include <memory.h>
#include <map>

using namespace std;

/** Error message */
#define ZZ_MSG_MEMLEAKS "WARNING, Memory leaks detected!\n"

/**
    List with all CzzBase:s object allocated on the heap.
    This class should not be used in any other way than
    indirectly via CzzBase.

    @author Toni Thomsson, toni@tonjac.org
*/
class ZZ_API CzzAllocMap
{
public:

    /** 
        Construction. Do not use. A list is automatically created
        if your program uses CzzBase based classes and is DEBUG
        compiled
    */
    CzzAllocMap();

    ~CzzAllocMap();

    /**
        Checks if there are any objects on the heap that not have been released

        @returns Number of objects not released
    */
    int CheckMemory( void );

    /**
        Frees a memoryblock
        @param addr Memory address
    */
    void Delete( int addr );
    /**
        Adds a block to the list
        @param addr Memory address
        @param p Pointer to the object
        @param n Size of the object
    */
    void Add( int addr, void* p, size_t n );

private:

    map<int, void* > m_AllocMap;
    map<int, size_t > m_SizeMap;
    map<int, void* >::iterator m_Iterator;
};

#endif