changed copyright years in source files
[fegdk.git] / core / code / system / f_baseobject.cpp
blob4d3fc4e452818722065538d94f3393505b2319ef
1 /*
2 fegdk: FE Game Development Kit
3 Copyright (C) 2001-2008 Alexey "waker" Yakovenko
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 Alexey Yakovenko
20 waker@users.sourceforge.net
23 #include "pch.h"
24 #include "f_baseobject.h"
25 #include "f_helpers.h"
26 #include <map>
28 namespace fe
31 int baseObject::mLastId = 0;
32 std::map< int, baseObject* > *baseObject::mpObjects = NULL;
34 class leakManager
36 public:
37 leakManager ();
38 ~leakManager ();
41 leakManager lm;
43 leakManager::leakManager ()
47 leakManager::~leakManager ()
49 if (NULL == baseObject::mpObjects)
50 return;
52 std::map< int, baseObject* >::iterator it;
53 for (it = baseObject::mpObjects->begin (); it != baseObject::mpObjects->end (); it++)
55 fprintf (stderr, "memory leak: id=%Xh, refc=%d ptr=%Xh, name='%s', data='", (*it).first, (*it).second->mRefc, (*it).second, (*it).second->name ());
56 for (int i = 0; i < 20; i++)
58 try {
59 uchar c = ( (char*) ((*it).second))[i];
60 if (c >= 32)
61 fprintf (stderr, "%c", ( (char*) ((*it).second))[i]);
62 else
63 fprintf (stderr, ".");
65 catch (...) {
66 fprintf (stderr, ".");
69 fprintf (stderr, "'\n");
73 baseObject::~baseObject (void)
75 std::map< int, baseObject* >::iterator it;
76 it = mpObjects->find (mId);
77 assert (it != mpObjects->end ());
78 mpObjects->erase (it);
79 if (mpObjects->empty ())
81 delete mpObjects;
82 mpObjects = NULL;
86 baseObject::baseObject (void)
88 if (!mpObjects)
89 mpObjects = new std::map< int, baseObject* >;
90 mRefc = 0;
91 mId = ++mLastId;
92 (*mpObjects)[ mId ] = this;
93 mbValid = true;
94 mUsedRefc = -1;
97 void baseObject::addRef (void)
99 // fprintf (stderr, "object %s addreffed to %d\n", mName.c_str (), mRefc);
100 mRefc++;
103 void baseObject::release (void)
105 // <= is intentional -- client may prefer to not using smartpointers and refcounting
106 if (--mRefc <= 0)
108 // fprintf (stderr, "object %s released to %d\n", mName.c_str (), mRefc);
109 delete this;
113 const char* baseObject::name (void) const
115 return mName;
118 void baseObject::setName (const char *nm)
120 mName = nm;
123 bool baseObject::isUsed (void) const
125 // mbUsed flag must be set by resource mgr when non-parser creation method is used
126 // reference counter is remembered at the moment
127 // when refc reaches the same value "used" flag is being reset to 0
128 return mRefc > 1 ? true : false;
131 void baseObject::loadData (void)
135 bool baseObject::isValid (void) const
137 return mbValid;
141 bool baseObject::isTypeOf (int type) const
143 return false;