2 * Copyright 2010 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrTemplates_DEFINED
9 #define GrTemplates_DEFINED
14 * Use to cast a ptr to a different type, and maintain strict-aliasing
16 template <typename Dst, typename Src> Dst GrTCast(Src src) {
26 * takes a T*, saves the value it points to, in and restores the value in the
30 * GrAutoTRestore<int*> autoCountRestore;
32 * autoCountRestore.reset(&fCount);
33 * fCount += fExtraCount;
36 * } // fCount is restored
38 template <typename T> class GrAutoTRestore : public SkNoncopyable {
40 GrAutoTRestore() : fPtr(NULL), fVal() {}
42 GrAutoTRestore(T* ptr) {
55 // restores previously saved value (if any) and saves value for passed T*