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.
5 #ifndef BASE_MAC_SCOPED_BLOCK_H_
6 #define BASE_MAC_SCOPED_BLOCK_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_policy.h"
17 // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
18 // Block_release() instead of CFRetain() and CFRelease().
25 base::scoped_policy::OwnershipPolicy policy
= base::scoped_policy::ASSUME
)
27 if (block_
&& policy
== base::scoped_policy::RETAIN
)
28 block_
= Block_copy(block
);
31 ScopedBlock(const ScopedBlock
<B
>& that
)
32 : block_(that
.block_
) {
34 block_
= Block_copy(block_
);
39 Block_release(block_
);
42 ScopedBlock
& operator=(const ScopedBlock
<B
>& that
) {
43 reset(that
.get(), base::scoped_policy::RETAIN
);
47 void reset(B block
= NULL
,
48 base::scoped_policy::OwnershipPolicy policy
=
49 base::scoped_policy::ASSUME
) {
50 if (block
&& policy
== base::scoped_policy::RETAIN
)
51 block
= Block_copy(block
);
53 Block_release(block_
);
57 bool operator==(B that
) const {
58 return block_
== that
;
61 bool operator!=(B that
) const {
62 return block_
!= that
;
73 void swap(ScopedBlock
& that
) {
79 B
release() WARN_UNUSED_RESULT
{
92 #endif // BASE_MAC_SCOPED_BLOCK_H_