Laxkit  0.0.7.1
lists.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2004-2007 by Tom Lechner
22 //
23 #ifndef _LAX_LISTS_H
24 #define _LAX_LISTS_H
25 
26 namespace Laxkit {
27 
28 #ifndef NULL
29 #define NULL 0
30 #endif
31 
32 template <class T>
33 class NumStack
34 {
35  protected:
36  int delta,max; // delta is size of chunk to add or remove, max is how many spaces allocated
37  public:
38  int n;
39  T *e;
40  NumStack() : delta(10), max(0), n(0),e(NULL) {}
41  NumStack(const NumStack &numstack); // copy constructor
42  NumStack &operator=(NumStack &numstack); // equals operator
43  const NumStack &operator=(const NumStack &numstack); // equals operator
44  virtual ~NumStack() { if (e) delete[] e; }
45  virtual T &operator[](int i);
46  virtual void flush();
47  virtual int howmany() { return n; }
48  virtual int findindex(T t);
49  virtual void swap(int i1,int i2);
50  virtual int push(T nd,int where=-1);
51  virtual int pushnodup(T nd);
52  virtual T pop(int which=-1);
53  virtual int remove(int which=-1);
54  virtual void Delta(int ndelta) { if (ndelta>=0) delta=ndelta; }
55  virtual int Delta() { return delta; }
56  virtual T *extractArray(int *nn=NULL);
57  virtual int insertArray(T *a,int nn);
58 };
59 
60 
61 enum ListsDeleteType {
62  LISTS_DELETE_None,
63  LISTS_DELETE_Array,
64  LISTS_DELETE_Refcount,
65  LISTS_DELETE_MAX
66 };
67 
68 
69 template <class T>
70 class PtrStack
71 {
72  protected:
73  int max,delta;
74  char arrays;
75  public:
76  char *islocal;
77  int n;
78  T **e;
79  PtrStack(char nar=1);
80  virtual ~PtrStack();
81  virtual T *operator[](int i) { if (i>=0 && i<n) return e[i]; else return NULL; }
82  virtual void flush();
83  virtual int howmany() { return n; }
84  virtual void swap(int i1,int i2);
85  virtual int push(T *nd,char local=-1,int where=-1);
86  virtual int popp(T *topop,int *local=NULL);
87  virtual int pop(T *&popped,int which=-1,int *local=NULL);
88  virtual T *pop(int which=-1,int *local=NULL); // -1 means from the end, <-1 means return NULL
89  virtual int findindex(T *t);
90  virtual int remove(int which=-1); // which is index
91  virtual int pushnodup(T *nd,char local,int where=-1);
92  virtual void Delta(int ndelta) { if (ndelta>=0) delta=ndelta; }
93  virtual int Delta() { return delta; }
94  virtual T **extractArrays(char **local=NULL,int *nn=NULL);
95  virtual int insertArrays(T **a,char *nl,int nn);
96 };
97 
98 } // namespace Laxkit;
99 
100 #ifdef LAX_LISTS_SOURCE_TOO
101 #include <lax/lists.cc>
102 #endif
103 
104 
105 #endif
106 

Mon Feb 17 2014 11:52:57, Laxkit