WvStreams
|
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 #if defined(__GNUC__) && __GNUC__ > 3 00037 # pragma GCC system_header 00038 #endif 00039 00040 #ifdef DEBUG 00041 00042 #include <stdio.h> 00043 00044 /* 00045 * Mix-in template that trace constructors, destructors and refcount 00046 * to stderr. 00047 */ 00048 template<class Component> 00049 class TraceComponent: public Component { 00050 public: 00051 TraceComponent() { 00052 fprintf(stderr, "%s: instantiated (%p)\n", __PRETTY_FUNCTION__, this); 00053 } 00054 virtual unsigned int addRef() { 00055 unsigned int refcount = Component::addRef(); 00056 00057 fprintf(stderr, "%s = %i (%p)\n", __PRETTY_FUNCTION__, refcount, this); 00058 00059 return refcount; 00060 } 00061 virtual unsigned int release() { 00062 unsigned int refcount = Component::release(); 00063 00064 fprintf(stderr, "%s = %i (%p)\n", __PRETTY_FUNCTION__, refcount, this); 00065 00066 return refcount; 00067 } 00068 virtual ~TraceComponent() { 00069 fprintf(stderr, "%s: destroyed (%p)\n", __PRETTY_FUNCTION__, this); 00070 } 00071 }; 00072 00073 #else /* DEBUG */ 00074 00075 #error "this header should not be used other than for debugging" 00076 00077 #endif /* else DEBUG */ 00078 00079 #endif /* __XPLC_TRACE_H__ */