GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/resource.h Lines: 2 4 50.0 %
Date: 2017-11-29 Branches: 0 6 0.0 %

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 RESOURCES_RESOURCE_H
24
#define RESOURCES_RESOURCE_H
25
26
#include "resources/memorycounter.h"
27
28
#include "localconsts.h"
29
30
/**
31
 * A generic reference counted resource object.
32
 */
33
class Resource notfinal : public MemoryCounter
34
{
35
    public:
36
        /**
37
         * Constructor
38
         */
39
67052
        Resource() :
40
            MemoryCounter(),
41
            mTimeStamp(0),
42
            mIdPath(),
43
            mSource(),
44
            mRefCount(0),
45
            mProtected(false),
46
#ifdef DEBUG_DUMP_LEAKS
47
            mNotCount(false),
48
            mDumped(false)
49
#else  // DEBUG_DUMP_LEAKS
50

201156
            mNotCount(false)
51
#endif  // DEBUG_DUMP_LEAKS
52
        {
53
        }
54
55
        A_DELETE_COPY(Resource)
56
57
        /**
58
         * Destructor.
59
         */
60
        virtual ~Resource();
61
62
        /**
63
         * Increments the internal reference count.
64
         */
65
        virtual void incRef();
66
67
        /**
68
         * Decrements the reference count and deletes the object
69
         * if no references are left.
70
         *
71
         * @return <code>true</code> if the object was deleted
72
         *         <code>false</code> otherwise.
73
         */
74
        virtual void decRef();
75
76
        int calcMemoryLocal() const override;
77
78
        std::string getCounterName() const override
79
        { return mIdPath + "-" + mSource; }
80
81
        time_t mTimeStamp;   /**< Time at which the resource was orphaned. */
82
83
        std::string mIdPath; /**< Path identifying this resource. */
84
        std::string mSource;
85
86
        unsigned int mRefCount;  /**< Reference count. */
87
        bool mProtected;
88
        bool mNotCount;
89
90
#ifdef DEBUG_DUMP_LEAKS
91
        bool mDumped;
92
#endif  // DEBUG_DUMP_LEAKS
93
};
94
95
#endif  // RESOURCES_RESOURCE_H