#ifndef SkTemplates_DEFINED
#define SkTemplates_DEFINED
#include "include/private/base/SkAlign.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTLogic.h"
#include "include/private/base/SkTo.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <type_traits>
#include <utility>
template<typename T> inline void sk_ignore_unused_variable(const T&) { … }
template <typename T> static inline T SkTAbs(T value) { … }
template <typename D, typename S> inline D* SkTAfter(S* ptr, size_t count = 1) { … }
template <typename D, typename S> inline D* SkTAddOffset(S* ptr, ptrdiff_t byteOffset) { … }
template <typename T, T* P> struct SkOverloadedFunctionObject { … };
SkFunctionObject;
template <typename T, void (*P)(T*)> class SkAutoTCallVProc
: public std::unique_ptr<T, SkFunctionObject<P>> { … };
namespace skia_private {
template <typename T> class AutoTArray { … };
template <int kCountRequested, typename T> class AutoSTArray { … };
template <typename T,
typename = std::enable_if_t<std::is_trivially_default_constructible<T>::value &&
std::is_trivially_destructible<T>::value>>
class AutoTMalloc {
public:
explicit AutoTMalloc(T* ptr = nullptr) : … { … }
explicit AutoTMalloc(size_t count)
: … { … }
AutoTMalloc(AutoTMalloc&&) = default;
AutoTMalloc& operator=(AutoTMalloc&&) = default;
void realloc(size_t count) { … }
T* reset(size_t count = 0) { … }
T* get() const { … }
operator T*() { return fPtr.get(); }
operator const T*() const { return fPtr.get(); }
T& operator[](int index) { … }
const T& operator[](int index) const { … }
const T* data() const { … }
T* data() { … }
T* release() { … }
private:
std::unique_ptr<T, SkOverloadedFunctionObject<void(void*), sk_free>> fPtr;
};
template <size_t kCountRequested,
typename T,
typename = std::enable_if_t<std::is_trivially_default_constructible<T>::value &&
std::is_trivially_destructible<T>::value>>
class AutoSTMalloc {
public:
AutoSTMalloc() : … { … }
AutoSTMalloc(size_t count) { … }
AutoSTMalloc(AutoSTMalloc&&) = delete;
AutoSTMalloc(const AutoSTMalloc&) = delete;
AutoSTMalloc& operator=(AutoSTMalloc&&) = delete;
AutoSTMalloc& operator=(const AutoSTMalloc&) = delete;
~AutoSTMalloc() { … }
T* reset(size_t count) { … }
T* get() const { … }
operator T*() {
return fPtr;
}
operator const T*() const {
return fPtr;
}
T& operator[](int index) { … }
const T& operator[](int index) const { … }
const T* data() const { … }
T* data() { … }
void realloc(size_t count) { … }
private:
static const size_t kCountWithPadding = SkAlign4(kCountRequested*sizeof(T)) / sizeof(T);
#if defined(SK_BUILD_FOR_GOOGLE3)
static const size_t kMaxBytes = 4 * 1024;
static const size_t kCount = kCountRequested * sizeof(T) > kMaxBytes
? kMaxBytes / sizeof(T)
: kCountWithPadding;
#else
static const size_t kCount = kCountWithPadding;
#endif
T* fPtr;
union {
uint32_t fStorage32[SkAlign4(kCount*sizeof(T)) >> 2];
T fTStorage[1];
};
};
UniqueVoidPtr;
}
template<typename C, std::size_t... Is>
constexpr auto SkMakeArrayFromIndexSequence(C c, std::index_sequence<Is...> is)
-> std::array<decltype(c(std::declval<typename decltype(is)::value_type>())), sizeof...(Is)> { … }
template<size_t N, typename C> constexpr auto SkMakeArray(C c)
-> std::array<decltype(c(std::declval<typename std::index_sequence<N>::value_type>())), N> { … }
#endif