1/*------------------------------------------------------------------------------
2* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3*
4* Distributable under the terms of either the Apache License (Version 2.0) or
5* the GNU Lesser General Public License, as specified in the COPYING file.
6------------------------------------------------------------------------------*/
7#ifndef _lucene_debug_lucenebase_
8#define _lucene_debug_lucenebase_
9
10#ifdef _LUCENE_PRAGMA_ONCE
11# pragma once
12#endif
13
14CL_NS_DEF(debug)
15
16//Lucenebase is the superclass of all clucene objects. It provides
17//memory debugging tracking and/or reference counting
18class LuceneBase{
19public:
20#ifdef LUCENE_ENABLE_MEMLEAKTRACKING
21 static void* operator new (size_t size);
22 static void operator delete (void *p);
23 int32_t __cl_initnum; ///< The order that the object was created at. This is then used to do a lookup in the objects list
24
25 static void* operator new (size_t size, char const * file, int32_t line);
26 static void operator delete (void *p, char const * file, int32_t line);
27
28 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
29 static void __cl_voidpremove(const void* data, const char* file, int line);///<remove arbitary data to the lucenbase_list
30 static void __cl_unregister(const void* obj); ///<un register object from the mem leak and ref count system
31
32 static int32_t __cl_GetUnclosedObjectsCount(); ///< gets the number of unclosed objects
33 static const char* __cl_GetUnclosedObject(int32_t item); ///< get the name of the nth unclosed object
34 static char* __cl_GetUnclosedObjects(); ///< get a string with the names of the unclosed objects
35 static void __cl_PrintUnclosedObjects(); ///< print unclosed objects to the stdout
36
37 ///This will clear memory relating to refcounting
38 ///other tools can be used to more accurately identify
39 ///memory leaks. This should only be called just
40 ///before closing, and after retrieving the
41 ///unclosed object list
42 static void __cl_ClearMemory();
43
44#endif //LUCENE_ENABLE_MEMLEAKTRACKING
45
46 int __cl_refcount;
47 LuceneBase(){
48 __cl_refcount=1;
49 }
50 inline int __cl_getref(){
51 return __cl_refcount;
52 }
53 inline int __cl_addref(){
54 __cl_refcount++;
55 return __cl_refcount;
56 }
57 inline int __cl_decref(){
58 __cl_refcount--;
59 return __cl_refcount;
60 }
61 virtual ~LuceneBase(){};
62};
63
64class LuceneVoidBase{
65 public:
66 #ifdef _DEBUG
67 //a compile time check to make sure that _CLDELETE and _CLDECDELETE is being
68 //used correctly.
69 int dummy__see_mem_h_for_details;
70 #endif
71 virtual ~LuceneVoidBase(){};
72};
73
74CL_NS_END
75#endif //_lucene_debug_lucenebase_
76