2016-09-13 15:09:45 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2018-07-10 21:38:12 +00:00
|
|
|
#include "SkTArray.h"
|
2016-09-13 15:09:45 +00:00
|
|
|
|
|
|
|
template <typename T> class SkRefSet {
|
|
|
|
public:
|
|
|
|
T* get(int index) const {
|
|
|
|
SkASSERT((unsigned)index < (unsigned)fArray.count());
|
2018-07-10 21:38:12 +00:00
|
|
|
return fArray[index].get();
|
2016-09-13 15:09:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 21:38:12 +00:00
|
|
|
bool set(int index, sk_sp<T> value) {
|
|
|
|
if (index < fArray.count()) {
|
|
|
|
fArray[index] = std::move(value);
|
2016-09-13 15:09:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (fArray.count() == index && value) {
|
2018-07-10 21:38:12 +00:00
|
|
|
fArray.emplace_back(std::move(value));
|
2016-09-13 15:09:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkDebugf("SkRefSet: index [%d] out of range %d\n", index, fArray.count());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-09-05 19:41:23 +00:00
|
|
|
SkTArray<sk_sp<T>> fArray;
|
2016-09-13 15:09:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|