My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ptrlist.h
Go to the documentation of this file.
1 /*
2  * ptrlist.h - pointer list template class definitions
3  *
4  * Copyright (C) 2005, 2006 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id: ptrlist.h 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #ifndef __PTRLIST_H__
26 #define __PTRLIST_H__
27 
28 template <class type_t> class ptrentry;
29 template <class type_t> class ptrlist;
30 template <class type_t> class ptrlistiterator;
31 
32 /* Pointer entry class. */
33 template <class type_t>
34 class ptrentry
35 {
36  friend class ptrlist<type_t>;
37  friend class ptrlistiterator<type_t>;
38 
39  public:
40  type_t * data;
41 
42  private:
43  ptrentry * next;
44  ptrentry * prev;
45 };
46 
47 /* Pointer list class. */
48 template <class type_t>
49 class ptrlist
50 {
51  friend class ptrlistiterator<type_t>;
52 
53  public:
54  ptrlist ();
55  ~ptrlist ();
56  ptrlist (const ptrlist &);
57  void add (type_t *);
58  void append (type_t *);
59  void del (type_t *);
60  int length (void);
61  int contains (type_t *);
62  int index (type_t *);
63  type_t * get (int);
64 
65  private:
66  int size;
67  ptrentry<type_t> * root;
68 };
69 
70 /* Pointer list iterator. */
71 template <class type_t>
72 class ptrlistiterator
73 {
74  public:
75  ptrlistiterator ();
78 
79  int count (void);
80  type_t * toFirst (void);
81  type_t * toLast (void);
82  type_t * operator++ (void);
83  type_t * operator-- (void);
84  type_t * operator * (void) { return current (); }
85  type_t * current (void);
86  type_t * first (void);
87  type_t * last (void);
88 
89  private:
90  ptrlist<type_t> * _ptrlist;
91  ptrentry<type_t> * _first;
92  ptrentry<type_t> * _last;
93  ptrentry<type_t> * _current;
94 };
95 
96 #include "ptrlist.cpp"
97 
98 #endif /* __PTRLIST_H__ */