Ardour  9.0-pre0-350-gf17a656217
stl_delete.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2015 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include "pbd/libpbd_visibility.h"
22 
23 /* To actually use any of these deletion functions, you need to
24  first include the revelant container type header.
25 */
26 #if defined(_CPP_VECTOR) || defined(_GLIBCXX_VECTOR) || defined(__SGI_STL_VECTOR) || defined(_LIBCPP_VECTOR)
27 template<class T> /*LIBPBD_API*/ void vector_delete (std::vector<T *> *vec)
28 {
29  typename std::vector<T *>::iterator i;
30 
31  for (i = vec->begin(); i != vec->end(); i++) {
32  delete *i;
33  }
34  vec->clear ();
35 }
36 #endif // _CPP_VECTOR || _GLIBCXX_VECTOR || __SGI_STL_VECTOR || _LIBCPP_VECTOR
37 
38 #if defined(_CPP_MAP) || defined(_GLIBCXX_MAP) || defined(__SGI_STL_MAP)
39 template<class K, class T> /*LIBPBD_API*/ void map_delete (std::map<K, T *> *m)
40 {
41  typename std::map<K, T *>::iterator i;
42 
43  for (i = m->begin(); i != m->end(); i++) {
44  delete (*i).second;
45  }
46  m->clear ();
47 }
48 #endif // _CPP_MAP || _GLIBCXX_MAP || __SGI_STL_MAP
49 
50 #if defined(_CPP_LIST) || defined(_GLIBCXX_LIST) || defined(__SGI_STL_LIST)
51 template<class T> /*LIBPBD_API*/ void list_delete (std::list<T *> *l)
52 {
53  typename std::list<T *>::iterator i;
54 
55  for (i = l->begin(); i != l->end(); i++) {
56  delete (*i);
57  }
58 
59  l->clear ();
60 }
61 #endif // _CPP_LIST || _GLIBCXX_LIST || __SGI_STL_LIST
62 
63 #if defined(_CPP_SLIST) || defined(_GLIBCXX_SLIST) || defined(__SGI_STL_SLIST)
64 template<class T> /*LIBPBD_API*/ void slist_delete (std::slist<T *> *l)
65 {
66  typename std::slist<T *>::iterator i;
67 
68  for (i = l->begin(); i != l->end(); i++) {
69  delete (*i);
70  }
71 
72  l->clear ();
73 }
74 #endif // _CPP_SLIST || _GLIBCXX_SLIST || __SGI_STL_SLIST
75 
76 #if defined(_CPP_SET) || defined(_GLIBCXX_SET) || defined(__SGI_STL_SET)
77 template<class T> void /*LIBPBD_API*/ set_delete (std::set<T *> *sset)
78 {
79  typename std::set<T *>::iterator i;
80 
81  for (i = sset->begin(); i != sset->end(); i++) {
82  delete *i;
83  }
84  sset->erase (sset->begin(), sset->end());
85 }
86 #endif // _CPP_SET || _GLIBCXX_SET || __SGI_STL_SET
87