home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Draw / propertyList.h < prev    next >
C/C++ Source or Header  |  1996-04-05  |  2KB  |  59 lines

  1. /* Convenience methods for Property List-izing */
  2.  
  3. typedef enum { FromPropertyList = 0, ToPropertyList = 1 } ConversionDirection;
  4.  
  5. /* The following functions return autoreleased objects. */
  6.  
  7. extern id propertyListFromArray(NSArray *array);
  8. extern id propertyListFromFloat(float f);
  9. extern id propertyListFromInt(int i);
  10. extern id propertyListFromNSColor(NSColor *color);
  11. extern id propertyListFromNSRect(NSRect rect);
  12. extern id propertyListFromNSSize(NSSize size);
  13. extern id propertyListFromNSPoint(NSPoint point);
  14.  
  15. /* The following functions return retained objects. */
  16.  
  17. extern NSMutableArray *arrayFromPropertyList(id plist, NSString *directory, NSZone *zone);
  18. extern NSColor *colorFromPropertyList(id plist, NSZone *zone);
  19. extern NSRect rectFromPropertyList(id plist);
  20. extern NSSize sizeFromPropertyList(id plist);
  21. extern NSPoint pointFromPropertyList(id plist);
  22.  
  23. #define PL_FLAG(plist, flag, key, direction) \
  24.     if (direction == ToPropertyList) { \
  25.         if (flag) [plist setObject:@"YES" forKey:key]; \
  26.     } else { \
  27.         flag = ([plist objectForKey:key] ? YES : NO); \
  28.     }
  29.  
  30. #define PL_INT(plist, value, key, direction) \
  31.    if (direction == ToPropertyList) { \
  32.        if (value) [plist setObject:propertyListFromInt(value) forKey:key]; \
  33.    } else { \
  34.        value = [[plist objectForKey:key] intValue]; \
  35.        if (![plist objectForKey:key]) value = 0; \
  36.    }
  37.  
  38. #define PL_FLOAT(plist, value, key, direction) \
  39.    if (direction == ToPropertyList) { \
  40.        if (value) [plist setObject:propertyListFromFloat(value) forKey:key]; \
  41.    } else { \
  42.        value = [[plist objectForKey:key] floatValue]; \
  43.        if (![plist objectForKey:key]) value = 0.0; \
  44.    }
  45.  
  46. #define PL_COLOR(plist, value, key, direction, zone) \
  47.    if (direction == ToPropertyList) { \
  48.        if (value) [plist setObject:propertyListFromNSColor(value) forKey:key]; \
  49.    } else { \
  50.        value = colorFromPropertyList([plist objectForKey:key], zone); \
  51.    }
  52.  
  53. #define PL_RECT(plist, value, key, direction) \
  54.    if (direction == ToPropertyList) { \
  55.        [plist setObject:propertyListFromNSRect(value) forKey:key]; \
  56.    } else { \
  57.        value = rectFromPropertyList([plist objectForKey:key]); \
  58.    }
  59.