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 GrKey_DEFINED |
| 12 | #define GrKey_DEFINED |
| 13 | |
| 14 | #include "GrRefCnt.h" |
| 15 | |
| 16 | class GrKey : public GrRefCnt { |
| 17 | public: |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 18 | SK_DECLARE_INST_COUNT(GrKey) |
| 19 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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; |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 39 | |
| 40 | typedef GrRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | #endif |