00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 * 00003 * XPLC - Cross-Platform Lightweight Components 00004 * Copyright (C) 2002, Pierre Phaneuf 00005 * Copyright (C) 2002, Net Integration Technologies, Inc. 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00020 * USA 00021 * 00022 * As a special exception, you may use this file as part of a free 00023 * software library without restriction. Specifically, if other files 00024 * instantiate templates or use macros or inline functions from this 00025 * file, or you compile this file and link it with other files to 00026 * produce an executable, this file does not by itself cause the 00027 * resulting executable to be covered by the GNU Lesser General Public 00028 * License. This exception does not however invalidate any other 00029 * reasons why the executable file might be covered by the GNU Lesser 00030 * General Public License. 00031 */ 00032 00033 #ifndef __XPLC_TRACE_H__ 00034 #define __XPLC_TRACE_H__ 00035 00036 #ifdef DEBUG 00037 00038 #include <stdio.h> 00039 00040 /* 00041 * Mix-in template that trace constructors, destructors and refcount 00042 * to stderr. 00043 */ 00044 template<class Component> 00045 class TraceComponent: public Component { 00046 public: 00047 TraceComponent() { 00048 fprintf(stderr, "%s: instantiated (%p)\n", __PRETTY_FUNCTION__, this); 00049 } 00050 virtual unsigned int addRef() { 00051 unsigned int refcount = Component::addRef(); 00052 00053 fprintf(stderr, "%s = %i (%p)\n", __PRETTY_FUNCTION__, refcount, this); 00054 00055 return refcount; 00056 } 00057 virtual unsigned int release() { 00058 unsigned int refcount = Component::release(); 00059 00060 fprintf(stderr, "%s = %i (%p)\n", __PRETTY_FUNCTION__, refcount, this); 00061 00062 return refcount; 00063 } 00064 virtual ~TraceComponent() { 00065 fprintf(stderr, "%s: destroyed (%p)\n", __PRETTY_FUNCTION__, this); 00066 } 00067 }; 00068 00069 #else /* DEBUG */ 00070 00071 #error "this header should not be used other than for debugging" 00072 00073 #endif /* else DEBUG */ 00074 00075 #endif /* __XPLC_TRACE_H__ */