diff options
author | fluxgen <fluxgen> | 2006-05-13 15:36:10 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2006-05-13 15:36:10 (GMT) |
commit | 8267672d73d498224bda0fd6680fd2db6aac49db (patch) | |
tree | 859b9823f83d5cf5ebbe527bb7e5ed3f6eb8c59e /src | |
parent | 806addad8e1220cbf9ab5228e662f24e4f3dcd52 (diff) | |
download | fluxbox-8267672d73d498224bda0fd6680fd2db6aac49db.zip fluxbox-8267672d73d498224bda0fd6680fd2db6aac49db.tar.bz2 |
STL utilities
Diffstat (limited to 'src')
-rw-r--r-- | src/STLUtil.hh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/STLUtil.hh b/src/STLUtil.hh new file mode 100644 index 0000000..a9b08e0 --- /dev/null +++ b/src/STLUtil.hh | |||
@@ -0,0 +1,56 @@ | |||
1 | // STLUtil.cc for fluxbox | ||
2 | // Copyright (c) 2006 Fluxbox Team (fluxgen at fluxbox dot org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id$ | ||
23 | |||
24 | |||
25 | #ifndef STLUTIL_HH | ||
26 | #define STLUTIL_HH | ||
27 | |||
28 | /// contains useful utilities for STL | ||
29 | namespace STLUtil { | ||
30 | |||
31 | /// calls delete on each item in the container and then clears the container | ||
32 | template <typename A> | ||
33 | void destroyAndClear(A &a) { | ||
34 | typedef typename A::iterator iterator; | ||
35 | iterator it = a.begin(); | ||
36 | iterator it_end = a.end(); | ||
37 | for (; it != it_end; ++it) | ||
38 | delete (*it); | ||
39 | |||
40 | a.clear(); | ||
41 | } | ||
42 | |||
43 | /// calls delete on each item value in the map and then clears the map | ||
44 | template <typename A> | ||
45 | void destroyAndClearSecond(A &a) { | ||
46 | typedef typename A::iterator iterator; | ||
47 | iterator it = a.begin(); | ||
48 | iterator it_end = a.end(); | ||
49 | for (; it != it_end; ++it) | ||
50 | delete it->second; | ||
51 | a.clear(); | ||
52 | } | ||
53 | |||
54 | }; | ||
55 | |||
56 | #endif // STLUTIL_Hh | ||