summaryrefslogtreecommitdiffstats
path: root/base/scoped_aedesc.h
blob: 92398878083c3e5308099002dc5e97c618f3542e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_SCOPED_AEDESC_H_
#define BASE_SCOPED_AEDESC_H_
#pragma once

#import <CoreServices/CoreServices.h>

#include "base/basictypes.h"

// The scoped_aedesc is used to scope AppleEvent descriptors.  On creation,
// it will store a NULL descriptor.  On destruction, it will dispose of the
// descriptor.
//
// This class is parameterized for additional type safety checks.  You can use
// the generic AEDesc type by not providing a template parameter:
//  scoped_aedesc<> desc;
template <typename AEDescType = AEDesc>
class scoped_aedesc {
 public:
  scoped_aedesc() {
    AECreateDesc(typeNull, NULL, 0, &desc_);
  }

  ~scoped_aedesc() {
    AEDisposeDesc(&desc_);
  }

  // Used for in parameters.
  operator const AEDescType*() {
    return &desc_;
  }

  // Used for out parameters.
  AEDescType* OutPointer() {
    return &desc_;
  }

 private:
  AEDescType desc_;

  DISALLOW_COPY_AND_ASSIGN(scoped_aedesc);
};

#endif  // BASE_SCOPED_AEDESC_H_