blob: b3e21d22d4c154c1ee0cce5e229d1ba18ff61a89 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrInstanceCounter_DEFINED
12#define GrInstanceCounter_DEFINED
13
14#include "GrTypes.h"
15
16template <typename T> class GrInstanceCounter {
17public:
18 GrInstanceCounter() {
19 ++gCounter;
20 GrPrintf("+ %s %d\n", T::InstanceCounterClassName(), gCounter);
21 }
22
23 ~GrInstanceCounter() {
24 --gCounter;
25 GrPrintf("- %s %d\n", T::InstanceCounterClassName(), gCounter);
26 }
27
28private:
29 static int gCounter;
30};
31
32template <typename T> int GrInstanceCounter<T>::gCounter;
33
34#define DECLARE_INSTANCE_COUNTER(T) \
35 static const char* InstanceCounterClassName() { return #T; } \
36 friend class GrInstanceCounter<T>; \
37 GrInstanceCounter<T> fInstanceCounter
38
39#endif
40