1 2 /* 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. 7 */ 8 9 10 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 41