OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2013 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SkHashDigest_DEFINED | |
9 #define SkHashDigest_DEFINED | |
10 | |
11 #include "SkData.h" | |
12 | |
13 /** | |
14 * A mutable hash digest; it can be filled with a bytearray of any | |
15 * length, anytime. | |
16 */ | |
17 class SkHashDigest { | |
18 public: | |
19 SkHashDigest() : fSkDataPtr(SkData::NewEmpty()) {} | |
20 SkHashDigest(const void *data, size_t length) : fSkDataPtr(SkData::NewWithCo py(data, length)) {} | |
21 | |
22 /** | |
23 * Destructor: if this object is the only one with a reference to the data | |
24 * that makes up the hash digest, then that data will be freed. | |
25 */ | |
26 ~SkHashDigest() { | |
27 SkSafeUnref(fSkDataPtr); | |
28 } | |
29 | |
30 /** | |
31 * Replace the hash digest data held by this object with a copy of the | |
32 * data from this pointer/length. | |
33 */ | |
34 void copyFrom(void *data, size_t length) { | |
epoger
2013/04/15 19:17:03
patchset 2: renamed SkHashDigest::set() to SkHashD
| |
35 fSkDataPtr->unref(); | |
36 fSkDataPtr = SkData::NewWithCopy(data, length); | |
37 } | |
38 | |
39 /** | |
40 * Return a pointer to the SkData object holding the hash digest data. | |
41 * | |
42 * The SkData object's reference counter will be bumped to account for this call, | |
43 * so the caller must call unref() on it once it is no longer needed! | |
44 * | |
45 * For example: | |
46 * { | |
47 * SkData *skDataPtr = digest.skDataPtr(); | |
48 * const uint8_t* bytes = skDataPtr->bytes(); | |
49 * ... | |
50 * skDataPtr->unref(); | |
51 * } | |
52 */ | |
53 SkData *skDataPtr() const { | |
54 fSkDataPtr->ref(); | |
55 return fSkDataPtr; | |
56 } | |
57 | |
58 size_t size() const { | |
59 return fSkDataPtr->size(); | |
60 } | |
61 | |
62 bool equals(const SkHashDigest &other) const { | |
63 return fSkDataPtr->equals(other.fSkDataPtr); | |
64 } | |
65 | |
66 private: | |
67 | |
68 // fSkDataPtr may change over the lifetime of the SkHashDigest object, | |
69 // but it will never be set to NULL. | |
70 // (Every SkHashDigest constructor initializes it to point at *some* SkData object.) | |
71 SkData *fSkDataPtr; | |
72 }; | |
73 | |
74 #endif | |
OLD | NEW |