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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006-2007, 2009-2012 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/list.h>
using namespace mailutils;
std::list<void*>
mailutils :: mulist_to_stl (mu_list_t mu_list)
{
size_t list_count;
std::list<void *> list;
if (!mu_list)
return list;
int status = mu_list_count (mu_list, &list_count);
if (status)
return list;
for (int i = 0; i < list_count; i++)
{
void *item = NULL;
status = mu_list_get (mu_list, i, &item);
if (!status && item)
list.push_back (item);
}
return list;
}
//
// 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_foreach (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);
}
mu_list_destroy_item_t
List :: set_destroy_item (mu_list_destroy_item_t mu_destroy_item)
{
return mu_list_set_destroy_item (mu_list, mu_destroy_item);
}
std::list<void*>
List :: to_stl ()
{
return mulist_to_stl (mu_list);
}
|