Chromium Code Reviews| Index: include/private/SkRefSet.h |
| diff --git a/include/private/SkRefSet.h b/include/private/SkRefSet.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5f23ba2191b36afac855da95324436d1e0074a80 |
| --- /dev/null |
| +++ b/include/private/SkRefSet.h |
| @@ -0,0 +1,40 @@ |
| +/* |
| + * Copyright 2016 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef SkRefSet_DEFINED |
| +#define SkRefSet_DEFINED |
| + |
| +#include "SkRefCnt.h" |
| +#include "SkTDArray.h" |
| + |
| +template <typename T> class SkRefSet { |
| +public: |
| + ~SkRefSet() { fArray.unrefAll(); } |
| + |
| + T* get(int index) const { |
| + SkASSERT((unsigned)index < (unsigned)fArray.count()); |
| + return fArray[index]; |
| + } |
| + |
| + bool set(int index, T* value) { |
| + if ((unsigned)index < (unsigned)fArray.count()) { |
| + SkRefCnt_SafeAssign(fArray[index], value); |
| + return true; |
| + } |
| + if (fArray.count() == index && value) { |
| + *fArray.append() = SkRef(value); |
| + return true; |
| + } |
|
mtklein_C
2016/09/12 19:47:58
The particular invariants of this class (values mu
reed1
2016/09/12 21:35:22
Done.
|
| + SkDebugf("SkRefSet: index [%d] out of range %d\n", index, fArray.count()); |
| + return false; |
| + } |
| + |
| +private: |
| + SkTDArray<T*> fArray; |
| +}; |
| + |
| +#endif |