home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Headers / objc / NXPropertyList.h < prev    next >
Text File  |  1996-11-14  |  4KB  |  114 lines

  1. /*    NXPropertyList.h
  2.     Basic protocol for property lists
  3.       Copyright 1991-1996, NeXT Software, Inc.
  4.     Bertrand, August 1991
  5. */
  6.  
  7. #import <objc/NXString.h>
  8. #import <objc/hashtable2.h>
  9. #import <objc/maptable.h>
  10. #import <objc/List.h>
  11.  
  12. /********    The basic property list protocol        ********/
  13.  
  14. @protocol NXPropertyList
  15. - (unsigned)count;
  16. - (BOOL)member:(NXString *)key;
  17. - get:(NXString *)key;
  18.     /* returns nil or value */
  19. - insert:(NXString *)key value:value;
  20.     /* returns nil or previous value; 
  21.     caller is responsible for freing previous value */
  22. - remove:(NXString *)key;
  23.     /* returns nil or previous value; 
  24.     caller is responsible for freing previous value */
  25. - empty;
  26. - (NXMapState)initEnumeration;
  27.     /* To enumerate use something like:
  28.     NXMapState    state = [self initEnumeration];
  29.         NXString    *key;
  30.     id        value;
  31.     while ([self enumerate:&state key:&key value:&value]) {
  32.         ...
  33.     }
  34.     */
  35. - (BOOL)enumerate:(NXMapState *)state key:(NXString **)refKey value:(id *)refValue;
  36.     
  37. @end
  38.  
  39. /********    A class implementing it        ********/
  40.  
  41. @interface NXPropertyList:Object <NXPropertyList> {
  42.     NXMapTable    *table;
  43. }
  44. @end
  45.  
  46. /********    Basic ASCII read/write of property lists    ********/
  47.  
  48. @interface NXPropertyList (Basic_IO)
  49. - initFromStream:(NXStream *)stream;
  50. - initFromPath:(NXString *)path;
  51.     /* all init methods must be called just after alloc; 
  52.     they may return nil in case of inexistant file or syntax error;  
  53.     Only syntax errors are logged on console */
  54.  
  55. - (void)writeToStream:(NXStream *)stream;
  56. - (BOOL)writeToPath:(NXString *)path safely:(BOOL)safe;
  57.     /* uses a temporary ~ file, and then atomically moves the file */
  58. - (BOOL)writeToPath:(NXString *)path;
  59.     /* All basic write function do indenting;
  60.     BOOL returned indicates success */
  61.     
  62. @end
  63.  
  64. /********    A list that really frees its elements    ********/
  65.  
  66. @interface NXCleanList:List
  67. - free;
  68.     /* sends free to each of its objects */
  69. @end
  70.  
  71. /********    Fancy ASCII read/write of property lists    ********/
  72.  
  73. typedef struct _NXPropertyListReadContext {
  74.     unsigned    line;         /* for error messages */
  75.     NXMutableString *buffer;    /* for efficiency */
  76.     id    keyFactory;        /* e.g. [NXCollectedString class] */
  77.     id    stringValueFactory;    /* e.g. [NXReadOnlyString class] */
  78.     id    listValueFactory;    /* e.g. [List class]; nil OK */
  79.     id    propertyListValueFactory; /* e.g. [NXPropertyList class]; nil OK */
  80.     BOOL    noValueIsSame;    /* if = missing, either key or nil */
  81.     NXZone    *zone;        /* zone used for reading; may be NULL */
  82.     NXHashTable    *uniquingTable;    /* used to unique strings */
  83. } NXPropertyListReadContext;
  84.  
  85. typedef struct _NXPropertyListWriteContext {
  86.     unsigned    indentDelta;        /* 0 => dont add white spaces */
  87.     unsigned    indent;            /* current number of spaces */
  88.     BOOL    topLevelBrackets;    /* the outer {} */
  89.     const char    *pairSeparator;        /* after each pair (after the ';') */
  90.     // not an NXString because bug cc!
  91. } NXPropertyListWriteContext;
  92.  
  93. @protocol NXPropertyListFancyIO
  94. - initFromStream:(NXStream *)stream context:(NXPropertyListReadContext *)context;
  95. - (void)writeToStream:(NXStream *)stream context:(NXPropertyListWriteContext *)context;
  96. @end
  97.  
  98. @interface NXPropertyList (Fancy_IO)
  99. - initFromStream:(NXStream *)stream context:(NXPropertyListReadContext *)context; //?? use protocol when possible in ObjC
  100. - (void)writeToStream:(NXStream *)stream context:(NXPropertyListWriteContext *)context; //?? use protocol when possible in ObjC
  101. - initFromPath:(NXString *)path context:(NXPropertyListReadContext *)context;
  102. @end
  103.  
  104. @interface NXCleanList (Fancy_IO)
  105. - initFromStream:(NXStream *)stream context:(NXPropertyListReadContext *)context; //?? use protocol when possible in ObjC
  106. - (void)writeToStream:(NXStream *)stream context:(NXPropertyListWriteContext *)context; //?? use protocol when possible in ObjC
  107. @end
  108.  
  109. @interface NXString (Fancy_IO)
  110. - initFromStream:(NXStream *)stream context:(NXPropertyListReadContext *)context; //?? use protocol when possible in ObjC
  111. - (void)writeToStream:(NXStream *)stream context:(NXPropertyListWriteContext *)context; //?? use protocol when possible in ObjC
  112. @end
  113.  
  114.