summaryrefslogtreecommitdiff
path: root/libmu_cpp/iterator.cc
blob: 6cb355610dcb2cd6f08cfb035881a2d6266fb5c0 (plain)
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
/*
   GNU Mailutils -- a suite of utilities for electronic mail
   Copyright (C) 2004 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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

#include <mailutils/cpp/iterator.h>
#include <mailutils/cpp/error.h>
#include <errno.h>

using namespace mailutils;

//
// Iterator
//

Iterator :: Iterator (const List& lst)
{
  int status = list_get_iterator (lst.mu_list, &mu_iter);
  if (status)
    throw Exception ("Iterator::Iterator", status);

  this->pList = (List*) &lst;
}

Iterator :: Iterator (const iterator_t iter)
{
  if (iter == 0)
    throw Exception ("Iterator::Iterator", EINVAL);

  this->mu_iter = iter;
  this->pList = 0;
}

Iterator :: ~Iterator ()
{
  iterator_destroy (&mu_iter);
}

void
Iterator :: First ()
{
  iterator_first (mu_iter);
}

void
Iterator :: Next ()
{
  iterator_next (mu_iter);
}

Iterator&
Iterator :: operator ++ (int)
{
  iterator_next (mu_iter);
  return *this;
}

void
Iterator :: Current (void** pitem)
{
  int status = iterator_current (mu_iter, pitem);
  if (status)
    throw Exception ("Iterator::Current", status);
}

void*
Iterator :: Current ()
{
  void* pitem;

  int status = iterator_current (mu_iter, &pitem);
  if (status)
    throw Exception ("Iterator::Current", status);

  return pitem;
}

bool
Iterator :: IsDone ()
{
  return (bool) iterator_is_done (mu_iter);
}

List&
Iterator :: GetList ()
{
  if (!pList)
    throw Exception ("Iterator::GetList", ENOTSUP);
  return *pList;
}

void
Iterator :: Dup (Iterator*& piter, const Iterator& orig)
{
  iterator_t iter;

  int status = iterator_dup (&iter, orig.mu_iter);
  if (status)
    throw Exception ("Iterator::Dup", status);

  piter->mu_iter = iter;
}

Return to:

Send suggestions and report system problems to the System administrator.