f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncCopyright 1995, 1998 The Open Group
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncPermission to use, copy, modify, distribute, and sell this software and its
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncdocumentation for any purpose is hereby granted without fee, provided that
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncthe above copyright notice appear in all copies and that both that
f78b12e570284aa8291f4ca1add24937fd107403vboxsynccopyright notice and this permission notice appear in supporting
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncdocumentation.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncThe above copyright notice and this permission notice shall be
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncincluded in all copies or substantial portions of the Software.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncOTHER DEALINGS IN THE SOFTWARE.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncExcept as contained in this notice, the name of The Open Group shall
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncnot be used in advertising or otherwise to promote the sale, use or
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncother dealings in this Software without prior written authorization
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncfrom The Open Group.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync A Set Abstract Data Type (ADT) for the RECORD Extension
f78b12e570284aa8291f4ca1add24937fd107403vboxsync David P. Wiggins
f78b12e570284aa8291f4ca1add24937fd107403vboxsync 7/25/95
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync The RECORD extension server code needs to maintain sets of numbers
f78b12e570284aa8291f4ca1add24937fd107403vboxsync that designate protocol message types. In most cases the interval of
f78b12e570284aa8291f4ca1add24937fd107403vboxsync numbers starts at 0 and does not exceed 255, but in a few cases (minor
f78b12e570284aa8291f4ca1add24937fd107403vboxsync opcodes of extension requests) the maximum is 65535. This disparity
f78b12e570284aa8291f4ca1add24937fd107403vboxsync suggests that a single set representation may not be suitable for all
f78b12e570284aa8291f4ca1add24937fd107403vboxsync sets, especially given that server memory is precious. We introduce a
f78b12e570284aa8291f4ca1add24937fd107403vboxsync set ADT to hide implementation differences so that multiple
f78b12e570284aa8291f4ca1add24937fd107403vboxsync simultaneous set representations can exist. A single interface is
f78b12e570284aa8291f4ca1add24937fd107403vboxsync presented to the set user regardless of the implementation in use for
f78b12e570284aa8291f4ca1add24937fd107403vboxsync a particular set.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync The existing RECORD SI appears to require only four set operations:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync create (given a list of members), destroy, see if a particular number
f78b12e570284aa8291f4ca1add24937fd107403vboxsync is a member of the set, and iterate over the members of a set. Though
f78b12e570284aa8291f4ca1add24937fd107403vboxsync many more set operations are imaginable, to keep the code space down,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync we won't provide any more operations than are needed.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync The following types and functions/macros define the ADT.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/* an interval of set members */
f78b12e570284aa8291f4ca1add24937fd107403vboxsynctypedef struct {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync CARD16 first;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync CARD16 last;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync} RecordSetInterval;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsynctypedef struct _RecordSetRec *RecordSetPtr; /* primary set type */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsynctypedef void *RecordSetIteratePtr;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/* table of function pointers for set operations.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync set users should never declare a variable of this type.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsynctypedef struct {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync void (*DestroySet)(
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetPtr pSet
f78b12e570284aa8291f4ca1add24937fd107403vboxsync);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync unsigned long (*IsMemberOfSet)(
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetPtr pSet,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int possible_member
f78b12e570284aa8291f4ca1add24937fd107403vboxsync);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetIteratePtr (*IterateSet)(
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetPtr pSet,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetIteratePtr pIter,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetInterval *interval
f78b12e570284aa8291f4ca1add24937fd107403vboxsync);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync} RecordSetOperations;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/* "base class" for sets.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync set users should never declare a variable of this type.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync */
f78b12e570284aa8291f4ca1add24937fd107403vboxsynctypedef struct _RecordSetRec {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetOperations *ops;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync} RecordSetRec;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncRecordSetPtr RecordCreateSet(
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetInterval *intervals,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int nintervals,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync void *pMem,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int memsize
f78b12e570284aa8291f4ca1add24937fd107403vboxsync);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordCreateSet creates and returns a new set having members specified
f78b12e570284aa8291f4ca1add24937fd107403vboxsync by intervals and nintervals. nintervals is the number of RecordSetInterval
f78b12e570284aa8291f4ca1add24937fd107403vboxsync structures pointed to by intervals. The elements belonging to the new
f78b12e570284aa8291f4ca1add24937fd107403vboxsync set are determined as follows. For each RecordSetInterval structure, the
f78b12e570284aa8291f4ca1add24937fd107403vboxsync elements between first and last inclusive are members of the new set.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync If a RecordSetInterval's first field is greater than its last field, the
f78b12e570284aa8291f4ca1add24937fd107403vboxsync results are undefined. It is valid to create an empty set (nintervals ==
f78b12e570284aa8291f4ca1add24937fd107403vboxsync 0). If RecordCreateSet returns NULL, the set could not be created due
f78b12e570284aa8291f4ca1add24937fd107403vboxsync to resource constraints.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncint RecordSetMemoryRequirements(
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordSetInterval * /*pIntervals*/,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int /*nintervals*/,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int * /*alignment*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define RecordDestroySet(_pSet) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* void */ (*_pSet->ops->DestroySet)(/* RecordSetPtr */ _pSet)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordDestroySet frees all resources used by _pSet. _pSet should not be
f78b12e570284aa8291f4ca1add24937fd107403vboxsync used after it is destroyed.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define RecordIsMemberOfSet(_pSet, _m) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* unsigned long */ (*_pSet->ops->IsMemberOfSet)(/* RecordSetPtr */ _pSet, \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* int */ _m)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordIsMemberOfSet returns a non-zero value if _m is a member of
f78b12e570284aa8291f4ca1add24937fd107403vboxsync _pSet, else it returns zero.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define RecordIterateSet(_pSet, _pIter, _interval) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* RecordSetIteratePtr */ (*_pSet->ops->IterateSet)(/* RecordSetPtr */ _pSet,\
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* RecordSetIteratePtr */ _pIter, /* RecordSetInterval */ _interval)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordIterateSet returns successive intervals of members of _pSet. If
f78b12e570284aa8291f4ca1add24937fd107403vboxsync _pIter is NULL, the first interval of set members is copied into _interval.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync The return value should be passed as _pIter in the next call to
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RecordIterateSet to obtain the next interval. When the return value is
f78b12e570284aa8291f4ca1add24937fd107403vboxsync NULL, there were no more intervals in the set, and nothing is copied into
f78b12e570284aa8291f4ca1add24937fd107403vboxsync the _interval parameter. Intervals appear in increasing numerical order
f78b12e570284aa8291f4ca1add24937fd107403vboxsync with no overlap between intervals. As such, the list of intervals produced
f78b12e570284aa8291f4ca1add24937fd107403vboxsync by RecordIterateSet may not match the list of intervals that were passed
f78b12e570284aa8291f4ca1add24937fd107403vboxsync in RecordCreateSet. Typical usage:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync pIter = NULL;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync while (pIter = RecordIterateSet(pSet, pIter, &interval))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync process interval;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*/