blob: 80eb537ca405f1b753c41c751aa762b6c26fc7a0 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrKey_DEFINED
12#define GrKey_DEFINED
13
14#include "GrRefCnt.h"
15
16class GrKey : public GrRefCnt {
17public:
reed@google.comfa35e3d2012-06-26 20:16:17 +000018 SK_DECLARE_INST_COUNT(GrKey)
19
reed@google.comac10a2d2010-12-22 21:39:39 +000020 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
33protected:
34 virtual bool lt(const GrKey& rh) const = 0;
35 virtual bool eq(const GrKey& rh) const = 0;
36
37private:
38 const Hash fHash;
reed@google.comfa35e3d2012-06-26 20:16:17 +000039
40 typedef GrRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000041};
42
43#endif