baseobject is now stl-free
[fegdk.git] / core / code / system / f_baseobject.h
blobab9f926ac0e68c939390a1531123089f39c26c8e
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 #ifndef __F_BASEOBJECT_H
24 #define __F_BASEOBJECT_H
26 #include "f_string.h"
27 #include "f_helpers.h"
28 #include <map>
30 namespace fe {
32 const int OBJ_HASH_SIZE = 256;
34 /** Base class for most of the system classes. */
35 /**
36 * The class is used for almost all classes in FEGDK.
37 * It provides basic functionality, such as refcounting, naming and checking for memory leaks.
39 class FE_API baseObject
41 friend class leakManager;
42 friend class resourceMgr;
44 protected:
45 /**
46 * internal counter used to assign IDs to newly created objects
48 static int mLastId;
49 static baseObject *mpObjList;
50 /**
51 * name of the object
53 cStr mName;
54 /**
55 * object's reference counter.
56 * can be accessed by derived classes for debug purposes.
58 int mRefc;
59 /**
60 * identifier of the object. assigned automatically. should not be changed during session.
62 int mId;
64 /**
65 * value of refcounter for the moment when object was marked as used
67 int mUsedRefc;
69 bool mbValid;
71 /** virtual dtor */
72 /**
73 * 'release' method calls 'delete this', so virtual is required
75 virtual ~baseObject (void);
77 /** main ctor */
78 /**
79 * this ctor is most used in derived classes.
81 baseObject (void);
83 public:
85 // don't use those addref/release to refcount object
86 // smartptr should take care of that
88 /**
89 * increases reference counter by 1
91 void addRef(void);
92 /**
93 * decreases reference counter by 1.
94 * calls 'delete this' when counter reaches zero.
96 void release(void);
97 /**
98 * returns name of an object.
99 * in case the name is NULL returns empty string ("")
101 const char* name( void ) const;
103 * sets the name for an object.
104 * @param nm new name
106 void setName (const char *nm);
109 * tells object that it is used from now and can proceed with loading it's data using prefetch
111 void use (void);
114 * returns 'true' if object refcount is more then 1, 'false' otherwise.
116 bool isUsed (void) const;
119 * object data loading method
120 * should be called by feScript::prefetch or by the object itself when used
122 virtual void loadData (void);
125 * returns 'true' if object creation was successful
127 bool isValid (void) const;
130 * implements base for Run-Time Type Information.
131 * returns true if an object belongs to a specified type-id.
132 * returns false otherwise.
133 * @param type type-id of an object we're testing against
135 virtual bool isTypeOf (int type) const;
136 protected:
138 * next hash value for resourceMgr
140 baseObject *mpResHashNext;
143 * next object in global obj list
145 baseObject *mpNextObj;
147 * prev object in global obj list
149 baseObject *mpPrevObj;
153 typedef smartPtr<baseObject> baseObjectPtr;
157 #endif // __F_BASEOBJECT_H