Single RUNTIME_CLASS() macro for classes and templates

The main purpose of this is to fix compilation errors with GCC/Clang
src/dobject.h:87:48: error: expected primary-expression before ‘)’ token
This commit is contained in:
alexey.lysiuk 2017-04-14 17:54:01 +03:00
parent cde450dd8a
commit 2add60a4c4
3 changed files with 7 additions and 8 deletions

View File

@ -739,7 +739,7 @@ public:
AInventory *FindInventory (FName type, bool subclass = false); AInventory *FindInventory (FName type, bool subclass = false);
template<class T> T *FindInventory () template<class T> T *FindInventory ()
{ {
return static_cast<T *> (FindInventory (RUNTIME_TEMPLATE_CLASS(T))); return static_cast<T *> (FindInventory (RUNTIME_CLASS(T)));
} }
// Adds one item of a particular type. Returns NULL if it could not be added. // Adds one item of a particular type. Returns NULL if it could not be added.
@ -1512,7 +1512,7 @@ public:
do do
{ {
actor = FActorIterator::Next (); actor = FActorIterator::Next ();
} while (actor && !actor->IsKindOf (RUNTIME_TEMPLATE_CLASS(T))); } while (actor && !actor->IsKindOf (RUNTIME_CLASS(T)));
return static_cast<T *>(actor); return static_cast<T *>(actor);
} }
}; };
@ -1563,12 +1563,12 @@ inline AActor *Spawn(FName type, const DVector3 &pos, replace_t allowreplacement
template<class T> inline T *Spawn(const DVector3 &pos, replace_t allowreplacement) template<class T> inline T *Spawn(const DVector3 &pos, replace_t allowreplacement)
{ {
return static_cast<T *>(AActor::StaticSpawn(RUNTIME_TEMPLATE_CLASS(T), pos, allowreplacement)); return static_cast<T *>(AActor::StaticSpawn(RUNTIME_CLASS(T), pos, allowreplacement));
} }
template<class T> inline T *Spawn() // for inventory items we do not need coordinates and replacement info. template<class T> inline T *Spawn() // for inventory items we do not need coordinates and replacement info.
{ {
return static_cast<T *>(AActor::StaticSpawn(RUNTIME_TEMPLATE_CLASS(T), DVector3(0, 0, 0), NO_REPLACE)); return static_cast<T *>(AActor::StaticSpawn(RUNTIME_CLASS(T), DVector3(0, 0, 0), NO_REPLACE));
} }
inline PClassActor *PClass::FindActor(FName name) inline PClassActor *PClass::FindActor(FName name)

View File

@ -84,8 +84,7 @@ class DPillar;
class PClassActor; class PClassActor;
#define RUNTIME_CLASS_CASTLESS(cls) (cls::RegistrationInfo.MyClass) // Passed a native class name, returns a PClass representing that class #define RUNTIME_CLASS_CASTLESS(cls) (cls::RegistrationInfo.MyClass) // Passed a native class name, returns a PClass representing that class
#define RUNTIME_CLASS(cls) ((cls::MetaClass *)RUNTIME_CLASS_CASTLESS(cls)) // Like above, but returns the true type of the meta object #define RUNTIME_CLASS(cls) ((typename cls::MetaClass *)RUNTIME_CLASS_CASTLESS(cls)) // Like above, but returns the true type of the meta object
#define RUNTIME_TEMPLATE_CLASS(cls) ((typename cls::MetaClass *)RUNTIME_CLASS_CASTLESS(cls)) // RUNTIME_CLASS, but works with templated parameters on GCC
#define NATIVE_TYPE(object) (object->StaticType()) // Passed an object, returns the type of the C++ class representing the object #define NATIVE_TYPE(object) (object->StaticType()) // Passed an object, returns the type of the C++ class representing the object
// Enumerations for the meta classes created by ClassReg::RegisterClass() // Enumerations for the meta classes created by ClassReg::RegisterClass()

View File

@ -134,10 +134,10 @@ protected:
template <class T> class TThinkerIterator : public FThinkerIterator template <class T> class TThinkerIterator : public FThinkerIterator
{ {
public: public:
TThinkerIterator (int statnum=MAX_STATNUM+1) : FThinkerIterator (RUNTIME_TEMPLATE_CLASS(T), statnum) TThinkerIterator (int statnum=MAX_STATNUM+1) : FThinkerIterator (RUNTIME_CLASS(T), statnum)
{ {
} }
TThinkerIterator (int statnum, DThinker *prev) : FThinkerIterator (RUNTIME_TEMPLATE_CLASS(T), statnum, prev) TThinkerIterator (int statnum, DThinker *prev) : FThinkerIterator (RUNTIME_CLASS(T), statnum, prev)
{ {
} }
TThinkerIterator (const PClass *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(subclass, statnum) TThinkerIterator (const PClass *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(subclass, statnum)