| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 1 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 10 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrInstanceCounter_DEFINED |
| 12 | #define GrInstanceCounter_DEFINED |
| 13 | |
| 14 | #include "GrTypes.h" |
| 15 | |
| 16 | template <typename T> class GrInstanceCounter { |
| 17 | public: |
| 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 | |
| 28 | private: |
| 29 | static int gCounter; |
| 30 | }; |
| 31 | |
| 32 | template <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 | |