iterator.cc
2.45 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
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006-2007, 2009-2012, 2014 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, see
<http://www.gnu.org/licenses/>. */
#include <mailutils/cpp/iterator.h>
using namespace mailutils;
//
// Iterator
//
Iterator :: Iterator (const List& lst)
{
int status = mu_list_get_iterator (lst.mu_list, &mu_iter);
if (status)
throw Exception ("Iterator::Iterator", status);
this->pList = (List*) &lst;
}
Iterator :: Iterator (const mu_iterator_t iter)
{
if (iter == 0)
throw Exception ("Iterator::Iterator", EINVAL);
this->mu_iter = iter;
this->pList = 0;
}
Iterator :: ~Iterator ()
{
mu_iterator_destroy (&mu_iter);
}
bool
Iterator :: operator == (const Iterator& iter)
{
return mu_iter == iter.mu_iter;
}
bool
Iterator :: operator != (const Iterator& iter)
{
return mu_iter != iter.mu_iter;
}
void
Iterator :: first ()
{
mu_iterator_first (mu_iter);
}
void
Iterator :: next ()
{
mu_iterator_next (mu_iter);
}
Iterator&
Iterator :: operator ++ (int)
{
mu_iterator_next (mu_iter);
return *this;
}
void
Iterator :: current (void** pitem)
{
int status = mu_iterator_current (mu_iter, pitem);
if (status)
throw Exception ("Iterator::current", status);
}
void*
Iterator :: current ()
{
void* pitem;
int status = mu_iterator_current (mu_iter, &pitem);
if (status)
throw Exception ("Iterator::current", status);
return pitem;
}
bool
Iterator :: is_done ()
{
return (bool) mu_iterator_is_done (mu_iter);
}
List&
Iterator :: get_list ()
{
if (!pList)
throw Exception ("Iterator::get_list", ENOTSUP);
return *pList;
}
void
Iterator :: dup (Iterator*& piter, const Iterator& orig)
{
mu_iterator_t iter;
int status = mu_iterator_dup (&iter, orig.mu_iter);
if (status)
throw Exception ("Iterator::dup", status);
piter->mu_iter = iter;
}