Flutter Engine
The Flutter Engine
third_party
skia
tools
Registry.h
Go to the documentation of this file.
1
/*
2
* Copyright 2009 The Android Open Source Project
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 sk_tools_Registry_DEFINED
9
#define sk_tools_Registry_DEFINED
10
11
#include "
include/core/SkTypes.h
"
12
#include "
include/private/base/SkNoncopyable.h
"
13
14
namespace
sk_tools
{
15
16
/**
17
* Template class that registers itself (in the constructor) into a linked-list
18
* and provides a function-pointer. This can be used to auto-register a set of
19
* services, e.g. a set of image codecs.
20
*/
21
template
<
typename
T>
class
Registry
:
SkNoncopyable
{
22
public
:
23
explicit
Registry
(
T
value
,
bool
condition =
true
) : fValue(
value
) {
24
if
(condition) {
25
this->linkToRegistryHead();
26
}
27
}
28
29
static
const
Registry
*
Head
() {
return
gHead; }
30
31
const
Registry
*
next
()
const
{
return
fChain; }
32
const
T
&
get
()
const
{
return
fValue; }
33
34
// for (const T& t : sk_tools::Registry<T>::Range()) { process(t); }
35
struct
Range
{
36
struct
Iterator
{
37
const
Registry
*
fPtr
;
38
const
T
&
operator*
() {
return
SkASSERT
(
fPtr
),
fPtr
->
get
(); }
39
void
operator++
() {
if
(
fPtr
) {
fPtr
=
fPtr
->
next
(); } }
40
bool
operator!=
(
const
Iterator
& other)
const
{
return
fPtr
!= other.
fPtr
; }
41
};
42
Iterator
begin
()
const
{
return
Iterator
{
Registry::Head
()}; }
43
Iterator
end
()
const
{
return
Iterator
{
nullptr
}; }
44
};
45
46
private
:
47
void
linkToRegistryHead() {
48
fChain = gHead;
49
gHead =
this
;
50
}
51
52
T
fValue;
53
Registry
* fChain;
54
55
static
Registry
* gHead;
56
};
57
58
// The caller still needs to declare an instance of this somewhere
59
template
<
typename
T> Registry<T>* Registry<T>::gHead;
60
61
}
// namespace sk_tools
62
63
#endif
SkASSERT
#define SkASSERT(cond)
Definition:
SkAssert.h:116
SkNoncopyable.h
SkTypes.h
SkNoncopyable
Definition:
SkNoncopyable.h:18
sk_tools::Registry
Definition:
Registry.h:21
sk_tools::Registry::Head
static const Registry * Head()
Definition:
Registry.h:29
sk_tools::Registry::get
const T & get() const
Definition:
Registry.h:32
sk_tools::Registry::next
const Registry * next() const
Definition:
Registry.h:31
sk_tools::Registry::Registry
Registry(T value, bool condition=true)
Definition:
Registry.h:23
value
uint8_t value
Definition:
fl_standard_message_codec.cc:36
sk_tools
Definition:
ProcStats.h:17
T
#define T
Definition:
precompiler.cc:65
sk_tools::Registry::Range::Iterator
Definition:
Registry.h:36
sk_tools::Registry::Range::Iterator::fPtr
const Registry * fPtr
Definition:
Registry.h:37
sk_tools::Registry::Range::Iterator::operator++
void operator++()
Definition:
Registry.h:39
sk_tools::Registry::Range::Iterator::operator*
const T & operator*()
Definition:
Registry.h:38
sk_tools::Registry::Range::Iterator::operator!=
bool operator!=(const Iterator &other) const
Definition:
Registry.h:40
sk_tools::Registry::Range
Definition:
Registry.h:35
sk_tools::Registry::Range::begin
Iterator begin() const
Definition:
Registry.h:42
sk_tools::Registry::Range::end
Iterator end() const
Definition:
Registry.h:43
Generated on Sun Jun 23 2024 21:56:50 for Flutter Engine by
1.9.4