diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/source/Host/macosx/cfcpp/CFCReleaser.h | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.bz2 |
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has
*** two obvious implications:
Firstly, merging this particular commit into a downstream fork may be a huge
effort. Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit. The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;
The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.
Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit. There are alternatives available that will attempt
to look through this change and find the appropriate prior commit. YMMV.
llvm-svn: 280751
Diffstat (limited to 'lldb/source/Host/macosx/cfcpp/CFCReleaser.h')
-rw-r--r-- | lldb/source/Host/macosx/cfcpp/CFCReleaser.h | 218 |
1 files changed, 94 insertions, 124 deletions
diff --git a/lldb/source/Host/macosx/cfcpp/CFCReleaser.h b/lldb/source/Host/macosx/cfcpp/CFCReleaser.h index 67dd2ea..c596d1e 100644 --- a/lldb/source/Host/macosx/cfcpp/CFCReleaser.h +++ b/lldb/source/Host/macosx/cfcpp/CFCReleaser.h @@ -26,133 +26,103 @@ // pointer, it is designed to relinquish ownership of the pointer just // like std:auto_ptr<T>::release() does. //---------------------------------------------------------------------- -template <class T> -class CFCReleaser -{ +template <class T> class CFCReleaser { public: - //---------------------------------------------------------- - // Constructor that takes a pointer to a CF object that is - // to be released when this object goes out of scope - //---------------------------------------------------------- - CFCReleaser(T ptr = NULL) : - _ptr(ptr) - { - } - - //---------------------------------------------------------- - // Copy constructor - // - // Note that copying a CFCReleaser will not transfer - // ownership of the contained pointer, but it will bump its - // reference count. This is where this class differs from - // std::auto_ptr. - //---------------------------------------------------------- - CFCReleaser(const CFCReleaser& rhs) : - _ptr(rhs.get()) - { - if (get()) - ::CFRetain(get()); - } - - - //---------------------------------------------------------- - // The destructor will release the pointer that it contains - // if it has a valid pointer. - //---------------------------------------------------------- - virtual ~CFCReleaser() - { - reset(); - } - - //---------------------------------------------------------- - // Assignment operator. - // - // Note that assigning one CFCReleaser to another will - // not transfer ownership of the contained pointer, but it - // will bump its reference count. This is where this class - // differs from std::auto_ptr. - //---------------------------------------------------------- - CFCReleaser& - operator= (const CFCReleaser<T>& rhs) - { - if (this != &rhs) - { - // Replace our owned pointer with the new one - reset(rhs.get()); - // Retain the current pointer that we own - if (get()) - ::CFRetain(get()); - } - return *this; - } - - //---------------------------------------------------------- - // Get the address of the contained type in case it needs - // to be passed to a function that will fill in a pointer - // value. The function currently will assert if _ptr is not - // NULL because the only time this method should be used is - // if another function will modify the contents, and we - // could leak a pointer if this is not NULL. If the - // assertion fires, check the offending code, or call - // reset() prior to using the "ptr_address()" member to make - // sure any owned objects has CFRelease called on it. - // I had to add the "enforce_null" bool here because some - // API's require the pointer address even though they don't change it. - //---------------------------------------------------------- - T* - ptr_address(bool enforce_null = true) - { - if (enforce_null) - assert (_ptr == NULL); - return &_ptr; - } - - //---------------------------------------------------------- - // Access the pointer itself - //---------------------------------------------------------- - T - get() - { - return _ptr; - } - - const T - get() const - { - return _ptr; - } - - - //---------------------------------------------------------- - // Set a new value for the pointer and CFRelease our old - // value if we had a valid one. - //---------------------------------------------------------- - void - reset(T ptr = NULL) - { - if ((_ptr != NULL) && (ptr != _ptr)) - ::CFRelease(_ptr); - _ptr = ptr; - } - - //---------------------------------------------------------- - // Release ownership without calling CFRelease. This class - // is designed to mimic std::auto_ptr<T>, so the release - // method releases ownership of the contained pointer - // and does NOT call CFRelease. - //---------------------------------------------------------- - T - release() - { - T tmp = _ptr; - _ptr = NULL; - return tmp; + //---------------------------------------------------------- + // Constructor that takes a pointer to a CF object that is + // to be released when this object goes out of scope + //---------------------------------------------------------- + CFCReleaser(T ptr = NULL) : _ptr(ptr) {} + + //---------------------------------------------------------- + // Copy constructor + // + // Note that copying a CFCReleaser will not transfer + // ownership of the contained pointer, but it will bump its + // reference count. This is where this class differs from + // std::auto_ptr. + //---------------------------------------------------------- + CFCReleaser(const CFCReleaser &rhs) : _ptr(rhs.get()) { + if (get()) + ::CFRetain(get()); + } + + //---------------------------------------------------------- + // The destructor will release the pointer that it contains + // if it has a valid pointer. + //---------------------------------------------------------- + virtual ~CFCReleaser() { reset(); } + + //---------------------------------------------------------- + // Assignment operator. + // + // Note that assigning one CFCReleaser to another will + // not transfer ownership of the contained pointer, but it + // will bump its reference count. This is where this class + // differs from std::auto_ptr. + //---------------------------------------------------------- + CFCReleaser &operator=(const CFCReleaser<T> &rhs) { + if (this != &rhs) { + // Replace our owned pointer with the new one + reset(rhs.get()); + // Retain the current pointer that we own + if (get()) + ::CFRetain(get()); } + return *this; + } + + //---------------------------------------------------------- + // Get the address of the contained type in case it needs + // to be passed to a function that will fill in a pointer + // value. The function currently will assert if _ptr is not + // NULL because the only time this method should be used is + // if another function will modify the contents, and we + // could leak a pointer if this is not NULL. If the + // assertion fires, check the offending code, or call + // reset() prior to using the "ptr_address()" member to make + // sure any owned objects has CFRelease called on it. + // I had to add the "enforce_null" bool here because some + // API's require the pointer address even though they don't change it. + //---------------------------------------------------------- + T *ptr_address(bool enforce_null = true) { + if (enforce_null) + assert(_ptr == NULL); + return &_ptr; + } + + //---------------------------------------------------------- + // Access the pointer itself + //---------------------------------------------------------- + T get() { return _ptr; } + + const T get() const { return _ptr; } + + //---------------------------------------------------------- + // Set a new value for the pointer and CFRelease our old + // value if we had a valid one. + //---------------------------------------------------------- + void reset(T ptr = NULL) { + if ((_ptr != NULL) && (ptr != _ptr)) + ::CFRelease(_ptr); + _ptr = ptr; + } + + //---------------------------------------------------------- + // Release ownership without calling CFRelease. This class + // is designed to mimic std::auto_ptr<T>, so the release + // method releases ownership of the contained pointer + // and does NOT call CFRelease. + //---------------------------------------------------------- + T release() { + T tmp = _ptr; + _ptr = NULL; + return tmp; + } private: - T _ptr; + T _ptr; }; -#endif // #ifdef __cplusplus -#endif // #ifndef CoreFoundationCPP_CFReleaser_h_ - +#endif // #ifdef __cplusplus +#endif // #ifndef CoreFoundationCPP_CFReleaser_h_ |