Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

CounterConstDestr.h

00001 /*
00002  *
00003  *  Copyright (c) 2000, TNO TPD, The Netherlands.
00004  *  All rights reserved. No part of this software may be handed to or used by persons 
00005  *  or organisation outside Kenniscentrum Watergraafsmeer (UvA-ISIS, TNO TPD) without 
00006  *  the written permission of TNO TPD.
00007  *
00008  *  Author(s):
00009  *      Jan Baan (baan@tpd.tno.nl)
00010  *
00011  *
00012  *
00013  *  Counts Constructor and Destructor calls
00014  * 
00015  *  Purpose: to count the constructor and destructor calls to check that
00016  *      at the end of the program all objects are destructed.
00017  *
00018  *  Use: 
00019  *      -   add to the yourclass which you want to be checked the class 
00020  *          CounterConstDestr<yourclass> as Base class (in which yourclass 
00021  * is the name of 
00022  *          your class). (This will be in the header file)
00023  *      -   add to the source file:
00024  *          #include <string>
00025  *          std::string CounterConstDestr<yourclass>.Mess = "yourclass".
00026  *      
00027  *
00028  */
00029 
00030 
00031 #ifndef __COUNTERCLASS__HPP
00032 #define __COUNTERCLASS__HPP
00033 
00034 #pragma warning( disable : 4786 )  
00035 
00036 #include <string>
00037 #include <vector>
00038 
00039 
00040 class MainCounterConstDestr{
00041 public:
00042     MainCounterConstDestr();
00043     ~MainCounterConstDestr();
00044 
00045     void AddCounter(const int* C, const std::string& Mess);
00046     
00047 private:
00048     std::vector<const int*> Lijst;
00049     std::vector<std::string> LijstMess;
00050 };
00051 
00052 
00053 static MainCounterConstDestr MainCounterConstDestrVar;
00054 
00055 
00056 template<class Type> class CounterConstDestr
00057 {
00058 public:
00059     CounterConstDestr();
00060     ~CounterConstDestr();
00061     static std::string Mess;
00062     
00063 private:
00064     static int number;
00065     static bool init;
00066 };
00067 
00068 
00069 template<class Type> 
00070 inline CounterConstDestr<Type>::CounterConstDestr()
00071 {
00072     if(init==false)
00073     {
00074         MainCounterConstDestrVar.AddCounter(&number, Mess);
00075         init = true;
00076     }
00077 
00078     number++;
00079 }
00080 
00081 
00082 template<class Type> 
00083 inline CounterConstDestr<Type>::~CounterConstDestr()
00084 {
00085     number--;
00086 }
00087 
00088 template<class Type> int CounterConstDestr<Type>::number = 0;
00089 template<class Type> std::string CounterConstDestr<Type>::Mess = "Unknown";
00090 template<class Type> bool CounterConstDestr<Type>::init = false;
00091 
00092 
00093 #endif

Generated on Tue Feb 3 14:18:31 2004 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001