list.cc
3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include <mailutils/cpp/list.h>
using namespace mailutils;
//
// List
//
List :: List ()
{
int status = mu_list_create (&mu_list);
if (status)
throw Exception ("List::List", status);
}
List :: List (const mu_list_t lst)
{
if (lst == 0)
throw Exception ("List::List", EINVAL);
this->mu_list = lst;
}
List :: ~List ()
{
mu_list_destroy (&mu_list);
}
void
List :: append (void* item)
{
int status = mu_list_append (mu_list, item);
if (status)
throw Exception ("List::append", status);
}
void
List :: prepend (void* item)
{
int status = mu_list_prepend (mu_list, item);
if (status)
throw Exception ("List::prepend", status);
}
void
List :: insert (void* item, void* new_item, int insert_before)
{
int status = mu_list_insert (mu_list, item, new_item, insert_before);
if (status)
throw Exception ("List::insert", status);
}
void
List :: remove (void* item)
{
int status = mu_list_remove (mu_list, item);
if (status)
throw Exception ("List::remove", status);
}
void
List :: replace (void* old_item, void* new_item)
{
int status = mu_list_replace (mu_list, old_item, new_item);
if (status)
throw Exception ("List::replace", status);
}
void
List :: get (size_t index, void** pitem)
{
int status = mu_list_get (mu_list, index, pitem);
if (status)
throw Exception ("List::get", status);
}
void*
List :: get (size_t index)
{
void* pitem;
int status = mu_list_get (mu_list, index, &pitem);
if (status)
throw Exception ("List::get", status);
return pitem;
}
inline void*
List :: front ()
{
return this->get (0);
}
void*
List :: back ()
{
size_t count = this->count ();
if (count)
return this->get (count - 1);
else
return NULL;
}
Iterator
List :: begin ()
{
mu_iterator_t mu_iter;
int status = mu_list_get_iterator (this->mu_list, &mu_iter);
if (status)
throw Exception ("Iterator::begin", status);
Iterator itr = Iterator (mu_iter);
this->iter = &itr;
this->iter->first ();
return itr;
}
void
List :: to_array (void** array, size_t count, size_t* pcount)
{
int status = mu_list_to_array (mu_list, array, count, pcount);
if (status)
throw Exception ("List::to_array", status);
}
void
List :: locate (void* item, void** ret_item)
{
int status = mu_list_locate (mu_list, item, ret_item);
if (status)
throw Exception ("List::locate", status);
}
bool
List :: is_empty ()
{
return (bool) mu_list_is_empty (mu_list);
}
size_t
List :: count ()
{
size_t count = 0;
int status = mu_list_count (mu_list, &count);
if (status)
throw Exception ("List::count", status);
return count;
}
inline size_t
List :: size ()
{
return this->count ();
}
void
List :: apply (mu_list_action_t* action, void* cbdata)
{
int status = mu_list_do (mu_list, action, cbdata);
if (status)
throw Exception ("List::apply", status);
}
mu_list_comparator_t
List :: set_comparator (mu_list_comparator_t comp)
{
return mu_list_set_comparator (mu_list, comp);
}
void
List :: set_destroy_item (void (*mu_destroy_item) (void *item))
{
int status = mu_list_set_destroy_item (mu_list, mu_destroy_item);
if (status)
throw Exception ("List::set_destroy_item", status);
}