OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Basic / List.hh
1 /*
2  * $XConsortium: List.hh /main/7 1996/08/10 11:31:57 cde-hal $
3  *
4  * Copyright (c) 1992 HaL Computer Systems, Inc.  All rights reserved.
5  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
6  * States.  Use of a copyright notice is precautionary only and does not
7  * imply publication or disclosure.
8  * 
9  * This software contains confidential information and trade secrets of HaL
10  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
11  * without the prior express written permission of HaL Computer Systems, Inc.
12  * 
13  *                         RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the Government is subject to
15  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
16  * Technical Data and Computer Software clause at DFARS 252.227-7013.
17  *                        HaL Computer Systems, Inc.
18  *                  1315 Dell Avenue, Campbell, CA  95008
19  * 
20  */
21
22
23
24 class List : public FolioObject
25 {
26 public: // variables
27   enum grow_method_t { GROW_ADD, GROW_MULTIPLY };
28   // notifications 
29   enum notifications { APPENDED = FolioObject::_LAST, INSERTED, REMOVED };
30
31 public: // functions
32   // increment really defaults to initial_size 
33   List (int initial_size, int increment = 0, grow_method_t method = GROW_ADD,
34         bool delete_elements = FALSE);
35   virtual ~List();
36   u_int length () const
37     { return (f_length); }
38   // NOTE: clean up and use either reference or ptr.  figure this out - DJB 
39   virtual void append (FolioObject &);
40   virtual void append (FolioObject *object)
41     { append (*object); }
42   virtual void remove (FolioObject &);
43   virtual void remove (FolioObject *object)
44     { remove (*object); }
45   virtual void remove (unsigned int);
46   // Change find to return FolioObect * 
47   virtual int  find   (FolioObject &);           // returns -1 on failure 
48   virtual void replace (int, FolioObject &);
49   virtual void replace (int i, FolioObject *obj);
50   virtual void insert (unsigned int, FolioObject *);
51   virtual void remove_all()
52     { f_length = 0; }
53   virtual void remove_all (bool delete_elements);
54
55   virtual FolioObject *operator[](int) const ;
56
57   virtual List *copy() const;   // NOTE: just copies the pointers, not the
58                                 // pointed at objects - jbm 
59
60   void dtor_delete_elements (bool delete_elements)
61     { f_dtor_delete_elements = delete_elements; }
62
63 protected: // functions
64   void check_space (int num_additions = 1);
65
66 protected: // variables
67   FolioObject    **f_list_element;        // array of list elements
68   unsigned short   f_length;
69   unsigned short   f_internal_length;
70   unsigned short   f_increment;
71   grow_method_t    f_grow_method;
72   bool             f_dtor_delete_elements : 1;
73 };
74
75 inline FolioObject *
76 List::operator[] (int position) const
77 {
78   // NOTE: need to be able to "throw" an exception here!!
79   if (position >= f_length)
80     abort ();
81
82   return (f_list_element[position]);
83 }
84
85 inline void
86 List::replace (int /* position */, FolioObject& /* element */)
87
88   // This function is obsolete, do not try to use
89   // someone needs to clean it up.
90   abort();
91 }
92
93 inline void
94 List::replace (int position, FolioObject *element)
95 {
96   replace (position, *element);
97 }
98