GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/dtor.h Lines: 5 5 100.0 %
Date: 2017-11-29 Branches: 3 16 18.8 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef UTILS_DTOR_H
24
#define UTILS_DTOR_H
25
26
#include <algorithm>
27
#include <functional>
28
29
#include "localconsts.h"
30
31
template<typename T>
32
struct dtor final : public std::unary_function <T, void>
33
{
34
    A_DEFAULT_COPY(dtor)
35
36
6648
    void operator()(T &ptr)
37



57524
    { delete ptr; }
38
};
39
40
template<typename T1, typename T2>
41
struct dtor<std::pair<T1, T2> > :
42
public std::unary_function <std::pair<T1, T2>, void>
43
{
44
2578
    void operator()(std::pair<T1, T2> &pair)
45

4896
    { delete pair.second; }
46
};
47
48
template<class Cont>
49
inline dtor<typename Cont::value_type> make_dtor(Cont const &d A_UNUSED)
50
{
51
    return dtor<typename Cont::value_type>();
52
}
53
54
template<typename Container>
55
inline void delete_all(Container &c)
56
{
57
52696
    std::for_each(c.begin(), c.end(), make_dtor(c));
58
}
59
60
#endif  // UTILS_DTOR_H