summaryrefslogtreecommitdiffstats
path: root/3rdparty/clucene/src/CLucene/debug/lucenebase.h
blob: 86cdae1c530757e098f590ca60d0a7991657e583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
* 
* Distributable under the terms of either the Apache License (Version 2.0) or 
* the GNU Lesser General Public License, as specified in the COPYING file.
------------------------------------------------------------------------------*/
#ifndef _lucene_debug_lucenebase_
#define _lucene_debug_lucenebase_

#ifdef _LUCENE_PRAGMA_ONCE
# pragma once
#endif

CL_NS_DEF(debug)

//Lucenebase is the superclass of all clucene objects. It provides
//memory debugging tracking and/or reference counting
class LuceneBase{
public:
#ifdef LUCENE_ENABLE_MEMLEAKTRACKING
	static void* operator new (size_t size);
	static void operator delete (void *p);
	int32_t __cl_initnum; ///< The order that the object was created at. This is then used to do a lookup in the objects list

	static void* operator new (size_t size, char const * file, int32_t line);
	static void operator delete (void *p, char const * file, int32_t line);

	static void* __cl_voidpadd(void* data, const char* file, int line, size_t size); ///<add arbitary data to the lucenbase_list and returns the same data
	static void __cl_voidpremove(const void* data, const char* file, int line);///<remove arbitary data to the lucenbase_list
	static void __cl_unregister(const void* obj); ///<un register object from the mem leak and ref count system

	static int32_t __cl_GetUnclosedObjectsCount();  ///< gets the number of unclosed objects
	static const char* __cl_GetUnclosedObject(int32_t item);  ///< get the name of the nth unclosed object
	static char* __cl_GetUnclosedObjects();  ///< get a string with the names of the unclosed objects
	static void __cl_PrintUnclosedObjects(); ///< print unclosed objects to the stdout
  
  	///This will clear memory relating to refcounting
	///other tools can be used to more accurately identify
	///memory leaks. This should only be called just
	///before closing, and after retrieving the
	///unclosed object list
  	static void __cl_ClearMemory();

#endif //LUCENE_ENABLE_MEMLEAKTRACKING

	int __cl_refcount;
	LuceneBase(){
		__cl_refcount=1;
	}
	inline int __cl_getref(){
		return __cl_refcount;
	}
	inline int __cl_addref(){
		__cl_refcount++;
		return __cl_refcount;
	}
	inline int __cl_decref(){
		__cl_refcount--;
		return __cl_refcount;
	}
    virtual ~LuceneBase(){};
};

class LuceneVoidBase{
	public:
	#ifdef _DEBUG
		//a compile time check to make sure that _CLDELETE and _CLDECDELETE is being
		//used correctly.
		int dummy__see_mem_h_for_details; 
	#endif
        virtual ~LuceneVoidBase(){};
};

CL_NS_END
#endif //_lucene_debug_lucenebase_