From cfdb17be06c8897cd48765ec7f019878b233d39b Mon Sep 17 00:00:00 2001 From: kingscallop <54776947+kingscallop@users.noreply.github.com> Date: Sat, 30 Apr 2022 16:40:00 +0100 Subject: [PATCH] Fix the compile time counter The compile time counter now compiles with the latest versions of gcc, clang and msvc. --- include/Core/SPK_Attributes.h | 2 +- include/Core/SPK_DescriptionDefines.h | 137 +++++++++++++------------- include/Core/SPK_Meta.h | 13 ++- include/Core/SPK_StaticDescription.h | 4 +- 4 files changed, 82 insertions(+), 74 deletions(-) diff --git a/include/Core/SPK_Attributes.h b/include/Core/SPK_Attributes.h index eb673c4c..81fc1711 100644 --- a/include/Core/SPK_Attributes.h +++ b/include/Core/SPK_Attributes.h @@ -295,7 +295,7 @@ namespace SPK public: template - struct Fields : public sAttr::template spkField + struct Fields : public sAttr::template spkField> { }; diff --git a/include/Core/SPK_DescriptionDefines.h b/include/Core/SPK_DescriptionDefines.h index 17c59b83..4289081d 100644 --- a/include/Core/SPK_DescriptionDefines.h +++ b/include/Core/SPK_DescriptionDefines.h @@ -93,82 +93,83 @@ namespace meta _spk_check ## _t_::value>::value #define SPK_REGISTER_DESC_TYPE( _tag_ , _type_ ) \ + static const unsigned int spk_meta_count_ ## _type_ = GET_COUNT(_tag_); \ template \ - struct spk ## _tag_ \ + struct spk ## _tag_, b> \ { \ static const bool isVoid = false; \ typedef _type_ type; \ }; \ - INC_COUNT(_tag_) + INC_COUNT(_tag_, _type_) /** * @internal */ -#define _spk_description_body( ... ) \ - { \ - private: \ - static description_base* _spk_getDescription(_spk_obj* obj) \ - { \ - return &obj->_spk_description_obj; \ - } \ - template friend class SPK::DescriptionBase; \ - template \ - struct spkAttr \ - { \ - static const bool isVoid = true; \ - typedef SPK::DefaultAttribute<_spk_obj> type; \ - }; \ - MAKE_COUNTER(Attr); \ - \ - template \ - struct spkCtrl \ - { \ - static const bool isVoid = true; \ - typedef SPK::DefaultControl<_spk_obj> type; \ - }; \ - MAKE_COUNTER(Ctrl); \ - \ - /* Workaround for VS2003-2012 : the following structure (Instantiate) */\ - /* triggers infinite inheritance if used in class template and defined */\ - /* outside it. See the following page: */\ - /*http://stackoverflow.com/questions/15620686/templated-recurrent-type-error */\ - template class A, int n = 0, bool = A::isVoid> \ - struct Instantiate : public Instantiate \ - { \ - typedef typename A::type type; \ - type object; \ - using Instantiate::getObject; \ - Instantiate() : object() {} \ - type* getObject(SPK::meta::NumOverload) \ - { \ - return &object; \ - } \ - }; \ - template class A, int n> \ - struct Instantiate \ - { \ - void getObject(); \ - }; \ - public: \ - __VA_ARGS__ \ - private: \ - Instantiate _spk_attributes; \ - template \ - typename spkAttr::type* getAttributePtr() \ - { \ - return _spk_attributes.getObject(SPK::meta::NumOverload()); \ - } \ - }; \ - public: \ - class description : public description_base \ - { \ - public: \ - static const char* getClassName() \ - { \ - return _spk_inner_name::get(); \ - } \ - }; \ - private: \ +#define _spk_description_body( ... ) \ + { \ + private: \ + static description_base* _spk_getDescription(_spk_obj* obj) \ + { \ + return &obj->_spk_description_obj; \ + } \ + template friend class SPK::DescriptionBase; \ + template \ + struct spkAttr \ + { \ + static const bool isVoid = true; \ + typedef SPK::DefaultAttribute<_spk_obj> type; \ + }; \ + MAKE_COUNTER(Attr); \ + \ + template \ + struct spkCtrl \ + { \ + static const bool isVoid = true; \ + typedef SPK::DefaultControl<_spk_obj> type; \ + }; \ + MAKE_COUNTER(Ctrl); \ + \ + /* Workaround for VS2003-2012 : the following structure (Instantiate) */ \ + /* triggers infinite inheritance if used in class template and defined */ \ + /* outside it. See the following page: */ \ + /*http://stackoverflow.com/questions/15620686/templated-recurrent-type-error */ \ + template class A, int n = 0, bool = A>::isVoid> \ + struct Instantiate : public Instantiate \ + { \ + typedef typename A>::type type; \ + type object; \ + using Instantiate::getObject; \ + Instantiate() : object() {} \ + type* getObject(SPK::meta::NumOverload) \ + { \ + return &object; \ + } \ + }; \ + template class A, int n> \ + struct Instantiate \ + { \ + void getObject(); \ + }; \ + public: \ + __VA_ARGS__ \ + private: \ + Instantiate _spk_attributes; \ + template \ + typename spkAttr>::type* getAttributePtr() \ + { \ + return _spk_attributes.getObject(SPK::meta::NumOverload()); \ + } \ + }; \ + public: \ + class description : public description_base \ + { \ + public: \ + static const char* getClassName() \ + { \ + return _spk_inner_name::get(); \ + } \ + }; \ + private: \ description_base _spk_description_obj /** @@ -306,7 +307,7 @@ namespace meta unsigned int> \ friend class SPK::StructuredAttributeBase; \ \ - template \ + template \ struct spkField \ { \ static const bool isVoid = true; \ diff --git a/include/Core/SPK_Meta.h b/include/Core/SPK_Meta.h index b5fb86e2..641f11be 100644 --- a/include/Core/SPK_Meta.h +++ b/include/Core/SPK_Meta.h @@ -417,6 +417,12 @@ namespace meta template struct Counter : public Counter {}; template<> struct Counter<0> {}; + template + struct CountWrapper + { + static const unsigned int value = n; + }; + // Create a counter #define MAKE_COUNTER( _tag_ ) \ static SPK::meta::Count<1> _spk_count_ ## _tag_ (SPK::meta::Counter<1>) @@ -424,8 +430,9 @@ namespace meta // Use counter #define GET_COUNT( _tag_ ) \ ((sizeof(_spk_count_ ## _tag_ (SPK::meta::Counter())) / sizeof(bool)) - 1) -#define INC_COUNT( _tag_ ) \ - static SPK::meta::Count _spk_count_ ## _tag_ (SPK::meta::Counter) +#define INC_COUNT( _tag_, _uniqueid_ ) \ + static const unsigned int spk_meta_inc_count_ ## _uniqueid_ = GET_COUNT(_tag_); \ + static SPK::meta::Count _spk_count_ ## _tag_ (SPK::meta::Counter) } } @@ -475,6 +482,6 @@ namespace meta static const bool isVoid = false; \ typedef BaseTypeRelation<_cpp_, _base_, cpp_name, spk_name, _passtype_> type; \ }; \ - INC_COUNT(type_relation) + INC_COUNT(type_relation, _base_) #endif diff --git a/include/Core/SPK_StaticDescription.h b/include/Core/SPK_StaticDescription.h index c3359831..9dcbf0bf 100644 --- a/include/Core/SPK_StaticDescription.h +++ b/include/Core/SPK_StaticDescription.h @@ -219,11 +219,11 @@ namespace SPK private: // Array of controls template - struct Controls : public T::template spkCtrl {}; + struct Controls : public T::template spkCtrl,true> {}; // Array of attributes template - struct Attributes : public T::template spkAttr {}; + struct Attributes : public T::template spkAttr,true> {}; /** * @brief Holds the 'queries' allowing to get / alter information on controls and attributes