5#ifndef FLUTTER_FML_UNIQUE_OBJECT_H_
6#define FLUTTER_FML_UNIQUE_OBJECT_H_
10#include "flutter/fml/compiler_specific.h"
11#include "flutter/fml/logging.h"
12#include "flutter/fml/macros.h"
27template <
typename T,
typename Traits>
36 struct Data :
public Traits {
37 explicit Data(
const T& in) :
generic(in) {}
38 Data(
const T& in,
const Traits& other) : Traits(other),
generic(in) {}
58 reset(other.release());
63 FML_CHECK(data_.generic == Traits::InvalidValue() ||
64 data_.generic !=
value);
66 data_.generic =
value;
74 swap(
static_cast<Traits&
>(data_),
static_cast<Traits&
>(other.data_));
75 swap(data_.generic, other.data_.generic);
82 T old_generic = data_.generic;
83 data_.generic = Traits::InvalidValue();
87 const T&
get()
const {
return data_.generic; }
89 bool is_valid()
const {
return Traits::IsValid(data_.generic); }
99 void FreeIfNecessary() {
100 if (data_.generic != Traits::InvalidValue()) {
101 data_.Free(data_.generic);
102 data_.generic = Traits::InvalidValue();
109 template <
typename T2,
typename Traits2>
110 bool operator==(
const UniqueObject<T2, Traits2>& p2)
const =
delete;
112 template <
typename T2,
typename Traits2>
113 bool operator!=(
const UniqueObject<T2, Traits2>& p2)
const =
delete;
120template <
class T,
class Traits>
125template <
class T,
class Traits>
127 return value ==
object.get();
130template <
class T,
class Traits>
132 return !(
value ==
object.get());
void swap(sk_sp< T > &a, sk_sp< T > &b)
bool operator==(const T &value) const
bool operator!=(const T &value) const
void reset(const T &value=Traits::InvalidValue())
void swap(UniqueObject &other)
const Traits & get_traits() const
UniqueObject & operator=(UniqueObject &&other)
UniqueObject(const T &value, const Traits &traits)
UniqueObject(const T &value)
UniqueObject(UniqueObject &&other)
#define FML_CHECK(condition)
struct PathData * Data(SkPath *path)
bool operator==(C p1, const scoped_nsprotocol< C > &p2)
void swap(scoped_nsprotocol< C > &p1, scoped_nsprotocol< C > &p2)
bool operator!=(C p1, const scoped_nsprotocol< C > &p2)