1 /*************************************************************************
3 * Copyright 2016 Realm Inc.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 **************************************************************************/
19 #ifndef REALM_UTIL_CF_PTR_HPP
20 #define REALM_UTIL_CF_PTR_HPP
22 #include <realm/util/assert.hpp>
24 #if REALM_PLATFORM_APPLE
26 #include <CoreFoundation/CoreFoundation.h>
34 explicit CFPtr(Ref ref = nullptr) noexcept
39 CFPtr(CFPtr&& rg) noexcept
51 CFPtr& operator=(CFPtr&& rg) noexcept
53 REALM_ASSERT(!m_ref || m_ref != rg.m_ref);
61 explicit operator bool() const noexcept
66 Ref get() const noexcept
71 Ref release() noexcept
78 void reset(Ref ref = nullptr) noexcept
80 REALM_ASSERT(!m_ref || m_ref != ref);
91 CFPtr<Ref> adoptCF(Ref ptr)
93 return CFPtr<Ref>(ptr);
97 CFPtr<Ref> retainCF(Ref ptr)
100 return CFPtr<Ref>(ptr);
106 #endif // REALM_PLATFORM_APPLE
108 #endif // REALM_UTIL_CF_PTR_HPP