Home | History | Annotate | Download | only in mac
      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 #pragma once
      8 
      9 #import <CoreServices/CoreServices.h>
     10 
     11 #include "base/basictypes.h"
     12 
     13 namespace base {
     14 namespace mac {
     15 
     16 // The ScopedAEDesc is used to scope AppleEvent descriptors.  On creation,
     17 // it will store a NULL descriptor.  On destruction, it will dispose of the
     18 // descriptor.
     19 //
     20 // This class is parameterized for additional type safety checks.  You can use
     21 // the generic AEDesc type by not providing a template parameter:
     22 //  ScopedAEDesc<> desc;
     23 template <typename AEDescType = AEDesc>
     24 class ScopedAEDesc {
     25  public:
     26   ScopedAEDesc() {
     27     AECreateDesc(typeNull, NULL, 0, &desc_);
     28   }
     29 
     30   ~ScopedAEDesc() {
     31     AEDisposeDesc(&desc_);
     32   }
     33 
     34   // Used for in parameters.
     35   operator const AEDescType*() {
     36     return &desc_;
     37   }
     38 
     39   // Used for out parameters.
     40   AEDescType* OutPointer() {
     41     return &desc_;
     42   }
     43 
     44  private:
     45   AEDescType desc_;
     46 
     47   DISALLOW_COPY_AND_ASSIGN(ScopedAEDesc);
     48 };
     49 
     50 }  // namespace mac
     51 }  // namespace base
     52 
     53 #endif  // BASE_MAC_SCOPED_AEDESC_H_
     54