• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors
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 BASE_MAC_SCOPED_BLOCK_H_
6 #define BASE_MAC_SCOPED_BLOCK_H_
7 
8 #include <Block.h>
9 
10 #include "base/mac/scoped_typeref.h"
11 
12 #if defined(__has_feature) && __has_feature(objc_arc)
13 #error "Cannot include base/mac/scoped_block.h in file built with ARC."
14 #endif
15 
16 namespace base::mac {
17 
18 namespace internal {
19 
20 template <typename B>
21 struct ScopedBlockTraits {
InvalidValueScopedBlockTraits22   static B InvalidValue() { return nullptr; }
RetainScopedBlockTraits23   static B Retain(B block) { return Block_copy(block); }
ReleaseScopedBlockTraits24   static void Release(B block) { Block_release(block); }
25 };
26 
27 }  // namespace internal
28 
29 // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
30 // Block_release() instead of CFRetain() and CFRelease().
31 template <typename B>
32 using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>;
33 
34 }  // namespace base::mac
35 
36 #endif  // BASE_MAC_SCOPED_BLOCK_H_
37