/core/externals/google-toolbox-for-mac/Foundation/GTMNSAppleEventDescriptor+Foundation.h

http://macfuse.googlecode.com/ · C Header · 102 lines · 31 code · 18 blank · 53 comment · 0 complexity · 83f221ed187e92a36fde7d1f83789f5e MD5 · raw file

  1. //
  2. // GTMNSAppleEventDescriptor+Foundation.h
  3. //
  4. // Copyright 2008 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import <Foundation/Foundation.h>
  19. #import "GTMDefines.h"
  20. #import "GTMFourCharCode.h"
  21. // A category for dealing with NSAppleEventDescriptors and NSArrays.
  22. @interface NSAppleEventDescriptor (GTMAppleEventDescriptorArrayAdditions)
  23. // Used to register the types you know how to convert into
  24. // NSAppleEventDescriptors.
  25. // See examples in GTMNSAppleEventDescriptor+Foundation.
  26. // Args:
  27. // selector - selector to call for any of the types in |types|
  28. // -(NSAppleEventDesc *)selector_name;
  29. // types - an std c array of types of length |count|
  30. // count - number of types in |types|
  31. + (void)gtm_registerSelector:(SEL)selector
  32. forTypes:(DescType*)types
  33. count:(NSUInteger)count;
  34. // Returns an NSObject for any NSAppleEventDescriptor
  35. // Uses types registerd by registerSelector:forTypes:count: to determine
  36. // what type of object to create. If it doesn't know a type, it attempts
  37. // to return [self stringValue].
  38. - (id)gtm_objectValue;
  39. // Return an NSArray for an AEList
  40. // Returns nil on failure.
  41. - (NSArray*)gtm_arrayValue;
  42. // Return an NSDictionary for an AERecord
  43. // Returns nil on failure.
  44. - (NSDictionary*)gtm_dictionaryValue;
  45. // Return an NSNull for a desc of typeNull
  46. // Returns nil on failure.
  47. - (NSNull*)gtm_nullValue;
  48. // Return a NSAppleEventDescriptor for a double value.
  49. + (NSAppleEventDescriptor*)gtm_descriptorWithDouble:(double)real;
  50. // Return a NSAppleEventDescriptor for a float value.
  51. + (NSAppleEventDescriptor*)gtm_descriptorWithFloat:(float)real;
  52. // Return a NSAppleEventDescriptor for a CGFloat value.
  53. + (NSAppleEventDescriptor*)gtm_descriptorWithCGFloat:(CGFloat)real;
  54. // Attempt to extract a double value. Returns NAN on error.
  55. - (double)gtm_doubleValue;
  56. // Attempt to extract a float value. Returns NAN on error.
  57. - (float)gtm_floatValue;
  58. // Attempt to extract a CGFloat value. Returns NAN on error.
  59. - (CGFloat)gtm_cgFloatValue;
  60. // Attempt to extract a NSNumber. Returns nil on error.
  61. - (NSNumber*)gtm_numberValue;
  62. // Attempt to return a GTMFourCharCode. Returns nil on error.
  63. - (GTMFourCharCode*)gtm_fourCharCodeValue;
  64. @end
  65. @interface NSObject (GTMAppleEventDescriptorObjectAdditions)
  66. // A informal protocol that objects can override to return appleEventDescriptors
  67. // for their type. The default is to return [self description] rolled up
  68. // in an NSAppleEventDescriptor. Built in support for:
  69. // NSArray, NSDictionary, NSNull, NSString, NSNumber and NSProcessInfo
  70. - (NSAppleEventDescriptor*)gtm_appleEventDescriptor;
  71. @end
  72. @interface NSAppleEventDescriptor (GTMAppleEventDescriptorAdditions)
  73. // Allows you to send events.
  74. // Returns YES if send was successful.
  75. - (BOOL)gtm_sendEventWithMode:(AESendMode)mode
  76. timeOut:(NSTimeInterval)timeout
  77. reply:(NSAppleEventDescriptor**)reply;
  78. @end
  79. @interface GTMFourCharCode (GTMAppleEventDescriptorObjectAdditions)
  80. // if you call gtm_appleEventDescriptor on GTMFourCharCode it will be of
  81. // type typeType. If you need something different (like typeProperty) this
  82. // allows you to define the type you want.
  83. - (NSAppleEventDescriptor*)gtm_appleEventDescriptorOfType:(DescType)type;
  84. @end