|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.0 (the 'License'). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License."
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /* NXPropertyList.h
25: Basic protocol for property lists
26: Copyright 1991, NeXT, Inc.
27: Bertrand, August 1991
28: */
29:
30: #import "NXString.h"
31: #import "hashtable.h"
32: #import "maptable.h"
33: #import "List.h"
34:
35: /******** The basic property list protocol ********/
36:
37: @protocol NXPropertyList
38: - (unsigned)count;
39: - (BOOL)member:(NXString *)key;
40: - get:(NXString *)key;
41: /* returns nil or value */
42: - insert:(NXString *)key value:value;
43: /* returns nil or previous value;
44: caller is responsible for freing previous value */
45: - remove:(NXString *)key;
46: /* returns nil or previous value;
47: caller is responsible for freing previous value */
48: - empty;
49: - (NXMapState)initEnumeration;
50: /* To enumerate use something like:
51: NXMapState state = [self initEnumeration];
52: NXString *key;
53: id value;
54: while ([self enumerate:&state key:&key value:&value]) {
55: ...
56: }
57: */
58: - (BOOL)enumerate:(NXMapState *)state key:(NXString **)refKey value:(id *)refValue;
59:
60: @end
61:
62: /******** A class implementing it ********/
63:
64: @interface NXPropertyList:Object <NXPropertyList> {
65: NXMapTable *table;
66: }
67: @end
68:
69: /******** Basic ASCII read/write of property lists ********/
70:
71: @interface NXPropertyList (Basic_IO)
72: - initFromStream:(NXStream *)stream;
73: - initFromPath:(NXString *)path;
74: /* all init methods must be called just after alloc;
75: they may return nil in case of inexistant file or syntax error;
76: Only syntax errors are logged on console */
77:
78: - (void)writeToStream:(NXStream *)stream;
79: - (BOOL)writeToPath:(NXString *)path safely:(BOOL)safe;
80: /* uses a temporary ~ file, and then atomically moves the file */
81: - (BOOL)writeToPath:(NXString *)path;
82: /* All basic write function do indenting;
83: BOOL returned indicates success */
84:
85: @end
86:
87: /******** A list that really frees its elements ********/
88:
89: @interface NXCleanList:List
90: - free;
91: /* sends free to each of its objects */
92: @end
93:
94: /******** Fancy ASCII read/write of property lists ********/
95:
96: typedef struct _NXPropertyListReadContext {
97: unsigned line; /* for error messages */
98: NXMutableString *buffer; /* for efficiency */
99: id keyFactory; /* e.g. [NXCollectedString class] */
100: id stringValueFactory; /* e.g. [NXReadOnlyString class] */
101: id listValueFactory; /* e.g. [List class]; nil OK */
102: id propertyListValueFactory; /* e.g. [NXPropertyList class]; nil OK */
103: BOOL noValueIsSame; /* if = missing, either key or nil */
104: NXZone *zone; /* zone used for reading; may be NULL */
105: NXHashTable *uniquingTable; /* used to unique strings */
106: } NXPropertyListReadContext;
107:
108: typedef struct _NXPropertyListWriteContext {
109: unsigned indentDelta; /* 0 => dont add white spaces */
110: unsigned indent; /* current number of spaces */
111: BOOL topLevelBrackets; /* the outer {} */
112: const char *pairSeparator; /* after each pair (after the ';') */
113: // not an NXString because bug cc!
114: } NXPropertyListWriteContext;
115:
116: @protocol NXPropertyListFancyIO
117: - initFromStream:(NXStream *)stream context:(NXPropertyListReadContext *)context;
118: - (void)writeToStream:(NXStream *)stream context:(NXPropertyListWriteContext *)context;
119: @end
120:
121: @interface NXPropertyList (Fancy_IO)
122: - initFromStream:(NXStream *)stream context:(NXPropertyListReadContext *)context; //?? use protocol when possible in ObjC
123: - (void)writeToStream:(NXStream *)stream context:(NXPropertyListWriteContext *)context; //?? use protocol when possible in ObjC
124: - initFromPath:(NXString *)path context:(NXPropertyListReadContext *)context;
125: @end
126:
127: @interface NXCleanList (Fancy_IO)
128: - initFromStream:(NXStream *)stream context:(NXPropertyListReadContext *)context; //?? use protocol when possible in ObjC
129: - (void)writeToStream:(NXStream *)stream context:(NXPropertyListWriteContext *)context; //?? use protocol when possible in ObjC
130: @end
131:
132: @interface NXString (Fancy_IO)
133: - initFromStream:(NXStream *)stream context:(NXPropertyListReadContext *)context; //?? use protocol when possible in ObjC
134: - (void)writeToStream:(NXStream *)stream context:(NXPropertyListWriteContext *)context; //?? use protocol when possible in ObjC
135: @end
136:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.