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 GrKey_DEFINED 12 #define GrKey_DEFINED 13 14 #include "GrRefCnt.h" 15 16 class GrKey : public GrRefCnt { 17 public: 18 SK_DECLARE_INST_COUNT(GrKey) 19 20 typedef intptr_t Hash; 21 22 explicit GrKey(Hash hash) : fHash(hash) {} 23 24 intptr_t getHash() const { return fHash; } 25 26 bool operator<(const GrKey& rh) const { 27 return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh)); 28 } 29 bool operator==(const GrKey& rh) const { 30 return fHash == rh.fHash && this->eq(rh); 31 } 32 33 protected: 34 virtual bool lt(const GrKey& rh) const = 0; 35 virtual bool eq(const GrKey& rh) const = 0; 36 37 private: 38 const Hash fHash; 39 40 typedef GrRefCnt INHERITED; 41 }; 42 43 #endif 44