scoped_block.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 {
  12. namespace mac {
  13. namespace internal {
  14. template <typename B>
  15. struct ScopedBlockTraits {
  16. static B InvalidValue() { return nullptr; }
  17. static B Retain(B block) { return Block_copy(block); }
  18. static void Release(B block) { Block_release(block); }
  19. };
  20. } // namespace internal
  21. // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
  22. // Block_release() instead of CFRetain() and CFRelease().
  23. template <typename B>
  24. using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>;
  25. } // namespace mac
  26. } // namespace base
  27. #endif // BASE_MAC_SCOPED_BLOCK_H_