Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
src
base
SkScopeExit.h
Go to the documentation of this file.
1
/*
2
* Copyright 2016 Google Inc.
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 SkScopeExit_DEFINED
9
#define SkScopeExit_DEFINED
10
11
#include "
include/private/base/SkMacros.h
"
12
13
#include <functional>
14
#include <utility>
15
16
/** SkScopeExit calls a std:::function<void()> in its destructor. */
17
class
SkScopeExit
{
18
public
:
19
SkScopeExit
() =
default
;
20
SkScopeExit
(std::function<
void
()> f) : fFn(
std
::move(f)) {}
21
SkScopeExit
(
SkScopeExit
&& that) : fFn(
std
::move(that.fFn)) {}
22
23
~SkScopeExit
() {
24
if
(fFn) {
25
fFn();
26
}
27
}
28
29
void
clear
() { fFn = {}; }
30
31
SkScopeExit
&
operator=
(
SkScopeExit
&& that) {
32
fFn = std::move(that.fFn);
33
return
*
this
;
34
}
35
36
private
:
37
std::function<void()> fFn;
38
39
SkScopeExit
(
const
SkScopeExit
& ) =
delete
;
40
SkScopeExit
&
operator=
(
const
SkScopeExit
& ) =
delete
;
41
};
42
43
/**
44
* SK_AT_SCOPE_EXIT(stmt) evaluates stmt when the current scope ends.
45
*
46
* E.g.
47
* {
48
* int x = 5;
49
* {
50
* SK_AT_SCOPE_EXIT(x--);
51
* SkASSERT(x == 5);
52
* }
53
* SkASSERT(x == 4);
54
* }
55
*/
56
#define SK_AT_SCOPE_EXIT(stmt) \
57
SkScopeExit SK_MACRO_APPEND_LINE(at_scope_exit_)([&]() { stmt; })
58
59
#endif
// SkScopeExit_DEFINED
SkMacros.h
SkScopeExit
Definition
SkScopeExit.h:17
SkScopeExit::clear
void clear()
Definition
SkScopeExit.h:29
SkScopeExit::~SkScopeExit
~SkScopeExit()
Definition
SkScopeExit.h:23
SkScopeExit::SkScopeExit
SkScopeExit()=default
SkScopeExit::SkScopeExit
SkScopeExit(SkScopeExit &&that)
Definition
SkScopeExit.h:21
SkScopeExit::SkScopeExit
SkScopeExit(std::function< void()> f)
Definition
SkScopeExit.h:20
SkScopeExit::operator=
SkScopeExit & operator=(SkScopeExit &&that)
Definition
SkScopeExit.h:31
std
Definition
ref_ptr.h:256
Generated on Fri Apr 26 2024 06:16:32 for Flutter Engine by
1.9.8