1 // Copyright 2010 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_MAC_SCOPED_AEDESC_H_ 6 #define BASE_MAC_SCOPED_AEDESC_H_ 7 8 #import <CoreServices/CoreServices.h> 9 10 namespace base::mac { 11 12 // The ScopedAEDesc is used to scope AppleEvent descriptors. On creation, 13 // it will store a NULL descriptor. On destruction, it will dispose of the 14 // descriptor. 15 // 16 // This class is parameterized for additional type safety checks. You can use 17 // the generic AEDesc type by not providing a template parameter: 18 // ScopedAEDesc<> desc; 19 template <typename AEDescType = AEDesc> 20 class ScopedAEDesc { 21 public: ScopedAEDesc()22 ScopedAEDesc() { 23 AECreateDesc(typeNull, NULL, 0, &desc_); 24 } 25 26 ScopedAEDesc(const ScopedAEDesc&) = delete; 27 ScopedAEDesc& operator=(const ScopedAEDesc&) = delete; 28 ~ScopedAEDesc()29 ~ScopedAEDesc() { 30 AEDisposeDesc(&desc_); 31 } 32 33 // Used for in parameters. 34 operator const AEDescType*() { 35 return &desc_; 36 } 37 38 // Used for out parameters. OutPointer()39 AEDescType* OutPointer() { 40 return &desc_; 41 } 42 43 private: 44 AEDescType desc_; 45 }; 46 47 } // namespace base::mac 48 49 #endif // BASE_MAC_SCOPED_AEDESC_H_ 50