list.h
2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//====================================================================
// list.h
//
// Copyright 1994, Silicon Graphics, Inc.
// All Rights Reserved.
//
// Author(s)
// Kevin Smith
//
// This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
// the contents of this file may not be disclosed to third parties, copied or
// duplicated in any form, in whole or in part, without the prior written
// permission of Silicon Graphics, Inc.
//
// RESTRICTED RIGHTS LEGEND:
// Use, duplication or disclosure by the Government is subject to restrictions
// as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
// and Computer Software clause at DFARS 252.227-7013, and/or in similar or
// successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
// rights reserved under the Copyright Laws of the United States.
//====================================================================
#pragma once
//
// A real simple list class. It does next to nothing, but does
// encapsulate a linked list well.
//
//
// A list iterator. Used to iterate over any list that inherits from
// List. The actual methods for iterating are in the List class.
//
class ListNode {
private:
ListNode *next;
void *thing;
friend List;
};
typedef ListNode **ListIter;
class List {
private:
ListNode *first;
ListNode *last;
int count;
public:
List (void) { first = last = 0; count = 0; }
virtual ~List ();
// Get the length of the list
int GetCount (void) const
{ return count; }
// List iteration support routines.
void PointToFirst (ListIter &iter) const
{ iter = (ListNode **) &first; }
void PointToLast (ListIter &iter) const
{ iter = (ListNode **) &last; }
void PointToNext (ListIter &iter) const
{ if ((*iter) != 0) iter = &((*iter)->next); }
// This routine should be heavily overloaded by routines that
// inherit from this class
void *GetIteratorValue (ListIter iter) const
{ return ((*iter) != 0) ? (*iter)->thing : 0; }
// Append a new entry to the list at specified location
// If "where" is 0, the new entry will go at the beginning
// of the list. This function needs to be overloaded for lists
// of a specific type (instead of "void *").
void AppendData (ListIter where, void *data);
// Remove a list entry from the list. The list iterator is invalid
// after this operation.
void RemoveData (ListIter where);
// Basic list searching
// Find a key. If found, return value is 1, otherwise 0.
int FindByKey (ListIter &iter, void *key);
// Key comparison. Return one if key matches, zero otherwise.
virtual int KeyCompare (void *key, void *element);
};