scoped_block.h 1008 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2013 The Chromium 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. #ifndef BASE_MAC_SCOPED_BLOCK_H_
  5. #define BASE_MAC_SCOPED_BLOCK_H_
  6. #include <Block.h>
  7. #include "base/mac/scoped_typeref.h"
  8. #if defined(__has_feature) && __has_feature(objc_arc)
  9. #error "Cannot include base/mac/scoped_block.h in file built with ARC."
  10. #endif
  11. namespace base::mac {
  12. namespace internal {
  13. template <typename B>
  14. struct ScopedBlockTraits {
  15. static B InvalidValue() { return nullptr; }
  16. static B Retain(B block) { return Block_copy(block); }
  17. static void Release(B block) { Block_release(block); }
  18. };
  19. } // namespace internal
  20. // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
  21. // Block_release() instead of CFRetain() and CFRelease().
  22. template <typename B>
  23. using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>;
  24. } // namespace base::mac
  25. #endif // BASE_MAC_SCOPED_BLOCK_H_