00001
00002 #ifndef GIGA_GIGAUTIL_H
00003 #define GIGA_GIGAUTIL_H 1
00004
00005
00006
00007 #include <iostream>
00008 #include <string>
00009 #include <functional>
00010
00011
00012 #include "GaudiKernel/StatusCode.h"
00013 #include "GaudiKernel/System.h"
00014
00015
00016 class IObjManager;
00017 class ISvcLocator;
00018 class IFactory;
00019
00029 namespace GiGaUtil
00030 {
00031
00050 StatusCode SplitTypeAndName ( const std::string& TypeAndName ,
00051 std::string & Type ,
00052 std::string & Name );
00053
00058 template <class TYPE>
00059 inline const std::string ObjTypeName( TYPE obj )
00060 {
00061 return
00062 obj ?
00063 std::string( System::typeinfoName( typeid(*obj) ) ) :
00064 std::string( "'UNKNOWN_type'" );
00065 };
00066
00074 class Delete
00075 {
00076 public:
00077
00082 template <class TYPE>
00083 inline TYPE* operator() ( TYPE* obj ) const
00084 {
00085 if( 0 != obj ) { delete obj ; obj = 0 ; }
00086 return obj ;
00087 };
00088 };
00089
00097 template <class TYPE>
00098 class Eraser: public std::unary_function<TYPE*,TYPE*>
00099 {
00100 public:
00101
00106 inline TYPE* operator() ( TYPE* obj ) const
00107 {
00108 if( 0 != obj ) { delete obj ; obj = 0 ; }
00109 return obj ;
00110 };
00111 };
00112
00122 template <class TYPE>
00123 inline TYPE* Delete_Ptr( TYPE* obj )
00124 {
00125 if( 0 != obj ) { delete obj ; obj = 0 ; }
00126 return obj ;
00127 };
00128
00134 template <class FROM,class TO>
00135 struct FastCast : std::unary_function<FROM*,TO*>
00136 {
00137 public :
00142 inline TO* operator() ( FROM* from ) const
00143 {
00144 if ( 0 == from ) { return (TO*) 0 ; }
00145 #ifdef GIGA_FASTCAST
00146 return static_cast<TO*> ( from ) ;
00147 #else
00148 return dynamic_cast<TO*> ( from ) ;
00149 #endif
00150 };
00151 };
00152
00160 template <class T> class InstanceCounter {
00161 long m_count;
00162 public:
00163 long increment () { return ++m_count; }
00164 long decrement () { return --m_count; }
00165 long count ()const { return m_count; }
00166 InstanceCounter() : m_count(0) {};
00167 virtual ~InstanceCounter()
00168 {
00169 if( 0 != m_count )
00170 {
00171 std::cout << "Number of objects of type: "
00172 << System::typeinfoName(typeid(T))
00173 << " created, but not destroyed:"
00174 << m_count
00175 << std::endl;
00176 }
00177 };
00178 };
00179
00180 };
00181
00182 #endif
00183