scoped_aedesc.h 1.2 KB

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