1 // Copyright (c) 2010 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. 4 5 #ifndef BASE_MAC_SCOPED_AEDESC_H_ 6 #define BASE_MAC_SCOPED_AEDESC_H_ 7 8 #import <CoreServices/CoreServices.h> 9 10 #include "base/macros.h" 11 12 namespace base { 13 namespace mac { 14 15 // The ScopedAEDesc is used to scope AppleEvent descriptors. On creation, 16 // it will store a NULL descriptor. On destruction, it will dispose of the 17 // descriptor. 18 // 19 // This class is parameterized for additional type safety checks. You can use 20 // the generic AEDesc type by not providing a template parameter: 21 // ScopedAEDesc<> desc; 22 template <typename AEDescType = AEDesc> 23 class ScopedAEDesc { 24 public: ScopedAEDesc()25 ScopedAEDesc() { 26 AECreateDesc(typeNull, NULL, 0, &desc_); 27 } 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 DISALLOW_COPY_AND_ASSIGN(ScopedAEDesc); 47 }; 48 49 } // namespace mac 50 } // namespace base 51 52 #endif // BASE_MAC_SCOPED_AEDESC_H_ 53