/src/aspell/common/string_list.hpp
Line | Count | Source |
1 | | // This file is part of The New Aspell |
2 | | // Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license |
3 | | // version 2.0 or 2.1. You should have received a copy of the LGPL |
4 | | // license along with this library if you did not you can find |
5 | | // it at http://www.gnu.org/. |
6 | | #ifndef STRING_LIST_HP_HEADER |
7 | | #define STRING_LIST_HP_HEADER |
8 | | |
9 | | #include "string.hpp" |
10 | | #include "string_enumeration.hpp" |
11 | | #include "mutable_container.hpp" |
12 | | #include "posib_err.hpp" |
13 | | #include <stdio.h> |
14 | | #include <cstdio> |
15 | | |
16 | | namespace acommon { |
17 | | |
18 | | struct StringListNode { |
19 | | // private data structure |
20 | | // default copy & destructor unsafe |
21 | | String data; |
22 | | StringListNode * next; |
23 | | StringListNode(ParmStr str, StringListNode * n = 0) |
24 | 2.31M | : data(str), next(n) { |
25 | 2.31M | } |
26 | | }; |
27 | | |
28 | | class StringListEnumeration : public StringEnumeration { |
29 | | // default copy and destructor safe |
30 | | private: |
31 | | StringListNode * n_; |
32 | | public: |
33 | | StringEnumeration * clone() const; |
34 | | void assign(const StringEnumeration *); |
35 | | |
36 | 92.3k | StringListEnumeration(StringListNode * n) : n_(n) {} |
37 | 246k | const char * next() { |
38 | 246k | const char * temp; |
39 | 246k | if (n_ == 0) { |
40 | 58.8k | temp = 0; |
41 | 187k | } else { |
42 | 187k | temp = n_->data.c_str(); |
43 | 187k | n_ = n_->next; |
44 | 187k | } |
45 | 246k | return temp; |
46 | 246k | } |
47 | 0 | bool at_end() const { |
48 | 0 | return n_ == 0; |
49 | 0 | } |
50 | | }; |
51 | | |
52 | | |
53 | | class StringList : public MutableContainer { |
54 | | // copy and destructor provided |
55 | | private: |
56 | | StringListNode * first; |
57 | | |
58 | | StringListNode * * find (ParmStr str); |
59 | | void copy(const StringList &); |
60 | | void destroy(); |
61 | | public: |
62 | | friend bool operator==(const StringList &, const StringList &); |
63 | 95.7k | StringList() : first(0) {} |
64 | | StringList(const StringList & other) |
65 | 0 | { |
66 | 0 | copy(other); |
67 | 0 | } |
68 | | StringList & operator= (const StringList & other) |
69 | 70.0k | { |
70 | 70.0k | destroy(); |
71 | 70.0k | copy(other); |
72 | 70.0k | return *this; |
73 | 70.0k | } |
74 | | virtual ~StringList() |
75 | 94.6k | { |
76 | 94.6k | destroy(); |
77 | 94.6k | } |
78 | | |
79 | | StringList * clone() const; |
80 | | void assign(const StringList *); |
81 | | |
82 | | PosibErr<bool> add(ParmStr); |
83 | | PosibErr<bool> remove(ParmStr); |
84 | | PosibErr<void> clear(); |
85 | | |
86 | | StringEnumeration * elements() const; |
87 | | StringListEnumeration elements_obj() const |
88 | 89.8k | { |
89 | 89.8k | return StringListEnumeration(first); |
90 | 89.8k | } |
91 | | |
92 | 1.94k | bool empty() const { return first == 0; } |
93 | 0 | unsigned int size() const { abort(); return 0; } |
94 | | |
95 | | }; |
96 | | |
97 | | StringList * new_string_list(); |
98 | | |
99 | | } |
100 | | #endif |