diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/media/platforms/apple/AppleUtils.h | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/media/platforms/apple/AppleUtils.h')
-rw-r--r-- | dom/media/platforms/apple/AppleUtils.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/dom/media/platforms/apple/AppleUtils.h b/dom/media/platforms/apple/AppleUtils.h new file mode 100644 index 000000000..9e30aff86 --- /dev/null +++ b/dom/media/platforms/apple/AppleUtils.h @@ -0,0 +1,98 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Utility functions to help with Apple API calls. + +#ifndef mozilla_AppleUtils_h +#define mozilla_AppleUtils_h + +#include "mozilla/Attributes.h" + +namespace mozilla { + +// Wrapper class to call CFRelease on reference types +// when they go out of scope. +template <class T> +class AutoCFRelease { +public: + MOZ_IMPLICIT AutoCFRelease(T aRef) + : mRef(aRef) + { + } + ~AutoCFRelease() + { + if (mRef) { + CFRelease(mRef); + } + } + // Return the wrapped ref so it can be used as an in parameter. + operator T() + { + return mRef; + } + // Return a pointer to the wrapped ref for use as an out parameter. + T* receive() + { + return &mRef; + } + +private: + // Copy operator isn't supported and is not implemented. + AutoCFRelease<T>& operator=(const AutoCFRelease<T>&); + T mRef; +}; + +// CFRefPtr: A CoreFoundation smart pointer. +template <class T> +class CFRefPtr { +public: + explicit CFRefPtr(T aRef) + : mRef(aRef) + { + if (mRef) { + CFRetain(mRef); + } + } + // Copy constructor. + CFRefPtr(const CFRefPtr<T>& aCFRefPtr) + : mRef(aCFRefPtr.mRef) + { + if (mRef) { + CFRetain(mRef); + } + } + // Copy operator + CFRefPtr<T>& operator=(const CFRefPtr<T>& aCFRefPtr) + { + if (mRef == aCFRefPtr.mRef) { + return; + } + if (mRef) { + CFRelease(mRef); + } + mRef = aCFRefPtr.mRef; + if (mRef) { + CFRetain(mRef); + } + return *this; + } + ~CFRefPtr() + { + if (mRef) { + CFRelease(mRef); + } + } + // Return the wrapped ref so it can be used as an in parameter. + operator T() + { + return mRef; + } + +private: + T mRef; +}; + +} // namespace mozilla + +#endif // mozilla_AppleUtils_h |