1 |
|
---|
2 | /*
|
---|
3 |
|
---|
4 | Copyright 1995, 1998 The Open Group
|
---|
5 |
|
---|
6 | Permission to use, copy, modify, distribute, and sell this software and its
|
---|
7 | documentation for any purpose is hereby granted without fee, provided that
|
---|
8 | the above copyright notice appear in all copies and that both that
|
---|
9 | copyright notice and this permission notice appear in supporting
|
---|
10 | documentation.
|
---|
11 |
|
---|
12 | The above copyright notice and this permission notice shall be
|
---|
13 | included in all copies or substantial portions of the Software.
|
---|
14 |
|
---|
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
---|
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
---|
18 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
---|
19 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
---|
20 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
21 | OTHER DEALINGS IN THE SOFTWARE.
|
---|
22 |
|
---|
23 | Except as contained in this notice, the name of The Open Group shall
|
---|
24 | not be used in advertising or otherwise to promote the sale, use or
|
---|
25 | other dealings in this Software without prior written authorization
|
---|
26 | from The Open Group.
|
---|
27 |
|
---|
28 | */
|
---|
29 | /* $XFree86$ */
|
---|
30 |
|
---|
31 | /*
|
---|
32 | A Set Abstract Data Type (ADT) for the RECORD Extension
|
---|
33 | David P. Wiggins
|
---|
34 | 7/25/95
|
---|
35 |
|
---|
36 | The RECORD extension server code needs to maintain sets of numbers
|
---|
37 | that designate protocol message types. In most cases the interval of
|
---|
38 | numbers starts at 0 and does not exceed 255, but in a few cases (minor
|
---|
39 | opcodes of extension requests) the maximum is 65535. This disparity
|
---|
40 | suggests that a single set representation may not be suitable for all
|
---|
41 | sets, especially given that server memory is precious. We introduce a
|
---|
42 | set ADT to hide implementation differences so that multiple
|
---|
43 | simultaneous set representations can exist. A single interface is
|
---|
44 | presented to the set user regardless of the implementation in use for
|
---|
45 | a particular set.
|
---|
46 |
|
---|
47 | The existing RECORD SI appears to require only four set operations:
|
---|
48 | create (given a list of members), destroy, see if a particular number
|
---|
49 | is a member of the set, and iterate over the members of a set. Though
|
---|
50 | many more set operations are imaginable, to keep the code space down,
|
---|
51 | we won't provide any more operations than are needed.
|
---|
52 |
|
---|
53 | The following types and functions/macros define the ADT.
|
---|
54 | */
|
---|
55 |
|
---|
56 | /* an interval of set members */
|
---|
57 | typedef struct {
|
---|
58 | CARD16 first;
|
---|
59 | CARD16 last;
|
---|
60 | } RecordSetInterval;
|
---|
61 |
|
---|
62 | typedef struct _RecordSetRec *RecordSetPtr; /* primary set type */
|
---|
63 |
|
---|
64 | typedef void *RecordSetIteratePtr;
|
---|
65 |
|
---|
66 | /* table of function pointers for set operations.
|
---|
67 | set users should never declare a variable of this type.
|
---|
68 | */
|
---|
69 | typedef struct {
|
---|
70 | void (*DestroySet)(
|
---|
71 | RecordSetPtr pSet
|
---|
72 | );
|
---|
73 | unsigned long (*IsMemberOfSet)(
|
---|
74 | RecordSetPtr pSet,
|
---|
75 | int possible_member
|
---|
76 | );
|
---|
77 | RecordSetIteratePtr (*IterateSet)(
|
---|
78 | RecordSetPtr pSet,
|
---|
79 | RecordSetIteratePtr pIter,
|
---|
80 | RecordSetInterval *interval
|
---|
81 | );
|
---|
82 | } RecordSetOperations;
|
---|
83 |
|
---|
84 | /* "base class" for sets.
|
---|
85 | set users should never declare a variable of this type.
|
---|
86 | */
|
---|
87 | typedef struct _RecordSetRec {
|
---|
88 | RecordSetOperations *ops;
|
---|
89 | } RecordSetRec;
|
---|
90 |
|
---|
91 | RecordSetPtr RecordCreateSet(
|
---|
92 | RecordSetInterval *intervals,
|
---|
93 | int nintervals,
|
---|
94 | void *pMem,
|
---|
95 | int memsize
|
---|
96 | );
|
---|
97 | /*
|
---|
98 | RecordCreateSet creates and returns a new set having members specified
|
---|
99 | by intervals and nintervals. nintervals is the number of RecordSetInterval
|
---|
100 | structures pointed to by intervals. The elements belonging to the new
|
---|
101 | set are determined as follows. For each RecordSetInterval structure, the
|
---|
102 | elements between first and last inclusive are members of the new set.
|
---|
103 | If a RecordSetInterval's first field is greater than its last field, the
|
---|
104 | results are undefined. It is valid to create an empty set (nintervals ==
|
---|
105 | 0). If RecordCreateSet returns NULL, the set could not be created due
|
---|
106 | to resource constraints.
|
---|
107 | */
|
---|
108 |
|
---|
109 | int RecordSetMemoryRequirements(
|
---|
110 | RecordSetInterval * /*pIntervals*/,
|
---|
111 | int /*nintervals*/,
|
---|
112 | int * /*alignment*/
|
---|
113 | );
|
---|
114 |
|
---|
115 | #define RecordDestroySet(_pSet) \
|
---|
116 | /* void */ (*_pSet->ops->DestroySet)(/* RecordSetPtr */ _pSet)
|
---|
117 | /*
|
---|
118 | RecordDestroySet frees all resources used by _pSet. _pSet should not be
|
---|
119 | used after it is destroyed.
|
---|
120 | */
|
---|
121 |
|
---|
122 | #define RecordIsMemberOfSet(_pSet, _m) \
|
---|
123 | /* unsigned long */ (*_pSet->ops->IsMemberOfSet)(/* RecordSetPtr */ _pSet, \
|
---|
124 | /* int */ _m)
|
---|
125 | /*
|
---|
126 | RecordIsMemberOfSet returns a non-zero value if _m is a member of
|
---|
127 | _pSet, else it returns zero.
|
---|
128 | */
|
---|
129 |
|
---|
130 | #define RecordIterateSet(_pSet, _pIter, _interval) \
|
---|
131 | /* RecordSetIteratePtr */ (*_pSet->ops->IterateSet)(/* RecordSetPtr */ _pSet,\
|
---|
132 | /* RecordSetIteratePtr */ _pIter, /* RecordSetInterval */ _interval)
|
---|
133 | /*
|
---|
134 | RecordIterateSet returns successive intervals of members of _pSet. If
|
---|
135 | _pIter is NULL, the first interval of set members is copied into _interval.
|
---|
136 | The return value should be passed as _pIter in the next call to
|
---|
137 | RecordIterateSet to obtain the next interval. When the return value is
|
---|
138 | NULL, there were no more intervals in the set, and nothing is copied into
|
---|
139 | the _interval parameter. Intervals appear in increasing numerical order
|
---|
140 | with no overlap between intervals. As such, the list of intervals produced
|
---|
141 | by RecordIterateSet may not match the list of intervals that were passed
|
---|
142 | in RecordCreateSet. Typical usage:
|
---|
143 |
|
---|
144 | pIter = NULL;
|
---|
145 | while (pIter = RecordIterateSet(pSet, pIter, &interval))
|
---|
146 | {
|
---|
147 | process interval;
|
---|
148 | }
|
---|
149 | */
|
---|