Mana
Loading...
Searching...
No Matches
resource.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "resources/resource.h"
23
24#include "log.h"
25
27
28#include <cassert>
29
31{
32 // Reference may not already have reached zero
33 if (mRefCount == 0) {
34 Log::warn("mRefCount already zero for %s", mIdPath.c_str());
35 assert(false);
36 }
37
38 --mRefCount;
39
40 if (mRefCount == 0)
41 {
43
44 switch (orphanPolicy)
45 {
46 case DeleteLater:
47 default:
48 resman->release(this);
49 break;
51 resman->remove(this);
52 delete this;
53 break;
54 }
55 }
56}
A class for loading and managing resources.
void remove(Resource *)
Removes a resource from the list of resources managed by the resource manager.
static ResourceManager * getInstance()
Returns an instance of the class, creating one if it does not already exist.
void release(Resource *)
Releases a resource, placing it in the set of orphaned resources.
std::string mIdPath
Path identifying this resource.
Definition resource.h:64
void decRef(OrphanPolicy orphanPolicy=DeleteLater)
Decrements the reference count.
Definition resource.cpp:30
unsigned mRefCount
Reference count.
Definition resource.h:66
@ DeleteImmediately
Definition resource.h:37
@ DeleteLater
Definition resource.h:36
void warn(const char *log_text,...) LOG_PRINTF_ATTR