My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
valuelist.h
Go to the documentation of this file.
1 /*
2  * valuelist.h - value list template class definitions
3  *
4  * Copyright (C) 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: valuelist.h 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #ifndef __VALUELIST_H__
26 #define __VALUELIST_H__
27 
28 template <class type_t> class valentry;
29 template <class type_t> class valuelist;
30 template <class type_t> class valuelistiterator;
31 
32 /* Value list entry. */
33 template <class type_t>
34 class valentry
35 {
36  friend class valuelistiterator<type_t>;
37  friend class valuelist<type_t>;
38 
39  public:
40  ~valentry () { free (key); delete value; }
41  char * key;
42  type_t * value;
45 };
46 
47 /* The value list class. */
48 template <class type_t>
49 class valuelist
50 {
51  friend class valuelistiterator<type_t>;
52 
53  public:
54  valuelist ();
55  ~valuelist ();
56  valuelist (const valuelist &);
57  void add (const char *, type_t *);
58  void append (char *, type_t *);
59  void append (valuelist *);
60  void del (char *);
61  int length (void);
62  int contains (char *);
63  type_t * get (const char *);
64  void clear (void);
65 
66  private:
67  int size;
68  valentry<type_t> * root;
70 };
71 
72 /* Value list iterator. */
73 template <class type_t>
75 {
76  public:
79 
80  int count (void);
81  char * toFirst (void);
82  char * toLast (void);
83  char * operator++ (void);
84  char * operator-- (void);
85  char * operator * (void) { return current (); }
86  char * current (void);
87  char * currentKey (void);
88  type_t * currentVal (void);
89  char * first (void);
90  char * last (void);
91 
92  private:
93  valuelist<type_t> * _valuelist;
94  valentry<type_t> * _first;
95  valentry<type_t> * _last;
96  valentry<type_t> * _current;
97 };
98 
99 #include "valuelist.cpp"
100 
101 #endif /* __VALUELIST_H__ */