180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2010 Google Inc.
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef GrKey_DEFINED
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GrKey_DEFINED
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
110a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenbergerclass GrKey : public SkRefCnt {
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_DECLARE_INST_COUNT(GrKey)
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    typedef intptr_t Hash;
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    explicit GrKey(Hash hash) : fHash(hash) {}
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    intptr_t getHash() const { return fHash; }
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool operator<(const GrKey& rh) const {
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh));
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool operator==(const GrKey& rh) const {
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return fHash == rh.fHash && this->eq(rh);
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected:
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool lt(const GrKey& rh) const = 0;
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool eq(const GrKey& rh) const = 0;
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const Hash fHash;
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
350a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger    typedef SkRefCnt INHERITED;
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
39