GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/resource.h Lines: 2 4 50.0 %
Date: 2021-03-17 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-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#ifndef RESOURCES_RESOURCE_H
25
#define RESOURCES_RESOURCE_H
26
27
#include "resources/memorycounter.h"
28
29
#include "localconsts.h"
30
31
/**
32
 * A generic reference counted resource object.
33
 */
34
class Resource notfinal : public MemoryCounter
35
{
36
    public:
37
        /**
38
         * Constructor
39
         */
40
36677
        Resource() :
41
            MemoryCounter(),
42
            mTimeStamp(0),
43
            mIdPath(),
44
            mSource(),
45
            mRefCount(0),
46
            mProtected(false),
47
#ifdef DEBUG_DUMP_LEAKS
48
            mNotCount(false),
49
            mDumped(false)
50
#else  // DEBUG_DUMP_LEAKS
51

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