My Project: dynamics.mod/NewtonDynamics/source/core/dgRtti.h Source File

My Project

dgRtti.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #ifndef __dgRtti__
23 #define __dgRtti__
24
25 #include "dgStdafx.h"
26 #include "dgCRC.h"
27
28 class dgRtti
29 {
30 public:
31 dgRtti(const char* typeName);
32 dgUnsigned32 GetTypeId() const;
33 bool IsTypeID(dgUnsigned32 id) const;
34
35 private:
36 dgUnsigned32 m_TypeId;
37 };
38
39 inline dgRtti::dgRtti(const char* typeName)
40 {
41 m_TypeId = dgCRC (typeName, (dgInt32) strlen (typeName));
42 }
43
44 inline dgUnsigned32 dgRtti::GetTypeId() const
45 {
46 return m_TypeId;
47 }
48
49 inline bool dgRtti::IsTypeID (dgUnsigned32 id) const
50 {
51 return m_TypeId == id;
52 }
53
54
55
56 #define dgAddRtti(baseClass) \
57 private: \
58 static dgRtti rtti; \
59 public: \
60 virtual bool IsType (dgUnsigned32 typeId) const \
61 { \
62 if (rtti.IsTypeID (typeId)) { \
63 return true; \
64 } \
65 return baseClass::IsType (typeId); \
66 } \
67 virtual dgUnsigned32 GetTypeId () const \
68 { \
69 return rtti.GetTypeId (); \
70 } \
71 static dgUnsigned32 GetRttiType() \
72 { \
73 return rtti.GetTypeId(); \
74 }
75
76
77 #define dgInitRtti(className) \
78 dgRtti className::rtti (#className)
79
80 #endif
81
dgCRC
dgUnsigned32 dgApi dgCRC(const char *const name)
Definition: dgCRC.cpp:340
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgRtti::GetTypeId
dgUnsigned32 GetTypeId() const
Definition: dgRtti.h:44
dgRtti::dgRtti
dgRtti(const char *typeName)
Definition: dgRtti.h:39
dgCRC.h
dgStdafx.h
dgUnsigned32
unsigned dgUnsigned32
Definition: dgTypes.h:219
dgRtti
Definition: dgRtti.h:28
dgRtti::IsTypeID
bool IsTypeID(dgUnsigned32 id) const
Definition: dgRtti.h:49