Flutter Engine
The Flutter Engine
scoped_block.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_FML_PLATFORM_DARWIN_SCOPED_BLOCK_H_
6#define FLUTTER_FML_PLATFORM_DARWIN_SCOPED_BLOCK_H_
7
8#include <Block.h>
9
10#include "flutter/fml/compiler_specific.h"
11#include "flutter/fml/platform/darwin/scoped_typeref.h"
12
13#if defined(__has_feature) && __has_feature(objc_arc)
14#define BASE_MAC_BRIDGE_CAST(TYPE, VALUE) (__bridge TYPE)(VALUE)
15#else
16#define BASE_MAC_BRIDGE_CAST(TYPE, VALUE) VALUE
17#endif
18
19namespace fml {
20
21namespace internal {
22
23template <typename B>
25 static B InvalidValue() { return nullptr; }
26 static B Retain(B block) {
28 B, Block_copy(BASE_MAC_BRIDGE_CAST(const void*, block)));
29 }
30 static void Release(B block) {
31 Block_release(BASE_MAC_BRIDGE_CAST(const void*, block));
32 }
33};
34
35} // namespace internal
36
37// ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
38// Block_release() instead of CFRetain() and CFRelease().
39
40template <typename B>
42
43} // namespace fml
44
45#undef BASE_MAC_BRIDGE_CAST
46
47#endif // FLUTTER_FML_PLATFORM_DARWIN_SCOPED_BLOCK_H_
Definition: ascii_trie.cc:9
#define BASE_MAC_BRIDGE_CAST(TYPE, VALUE)
Definition: scoped_block.h:16
static void Release(B block)
Definition: scoped_block.h:30