diff --git a/benchmark/rtti_benchmark.cc b/benchmark/rtti_benchmark.cc index 62baa17..e3bd884 100644 --- a/benchmark/rtti_benchmark.cc +++ b/benchmark/rtti_benchmark.cc @@ -14,7 +14,9 @@ struct ParentB : virtual GrandParent { RTTI_DECLARE_TYPEINFO(ParentB, GrandParent); }; -struct Child : ParentA, ParentB { +struct Child + : ParentA + , ParentB { RTTI_DECLARE_TYPEINFO(Child, ParentA, ParentB); }; @@ -28,10 +30,10 @@ NativeDynamicCast(benchmark::State& state) { GrandParent* g; benchmark::DoNotOptimize(g = dynamic_cast(&c)); - ParentA *pa; + ParentA* pa; benchmark::DoNotOptimize(pa = dynamic_cast(g)); - ParentB *pb; + ParentB* pb; benchmark::DoNotOptimize(pb = dynamic_cast(g)); InvalidCast* invalid; @@ -48,10 +50,10 @@ RttiDynamicCast(benchmark::State& state) { GrandParent* g; benchmark::DoNotOptimize(g = c.cast()); - ParentA *pa; + ParentA* pa; benchmark::DoNotOptimize(pa = g->cast()); - ParentB *pb; + ParentB* pb; benchmark::DoNotOptimize(pb = g->cast()); InvalidCast* invalid; diff --git a/include/rtti.hh b/include/rtti.hh index d8f446f..6e2d1db 100644 --- a/include/rtti.hh +++ b/include/rtti.hh @@ -24,10 +24,10 @@ #pragma once -#include -#include #include #include +#include +#include namespace RTTI { /// Forward declaration of the Enable base. @@ -37,9 +37,11 @@ namespace RTTI { using TypeId = uintptr_t; namespace Detail { - template - struct Type { static constexpr int Id = 0; }; - } + template + struct Type { + static constexpr int Id = 0; + }; + } // namespace Detail /** * Static typeinfo structure for registering types and accessing their information. @@ -48,11 +50,11 @@ namespace RTTI { struct TypeInfo { /// Ensure all passed parents are basses of this type. static_assert((... && std::is_base_of::value), - "One or more parents are not a base of this type."); + "One or more parents are not a base of this type."); /// Ensure all passed parent hierarchies have RTTI enabled. static_assert((... && std::is_base_of::value), - "One or more parent hierarchies is not based on top of RTTI::Enable."); + "One or more parent hierarchies is not based on top of RTTI::Enable."); /** * Returns the type identifier of the type T. @@ -115,7 +117,7 @@ namespace RTTI { * Returns the type identifier of the object. * @returns Type identifier */ - [[nodiscard]] virtual TypeId typeId() const noexcept =0; + [[nodiscard]] virtual TypeId typeId() const noexcept = 0; /** * Checks whether the object is a direct or derived instance of @@ -123,7 +125,7 @@ namespace RTTI { * @tparam The identifier to compare with. * @returns True in case a match was found. */ - [[nodiscard]] virtual bool isById(TypeId typeId) const noexcept =0; + [[nodiscard]] virtual bool isById(TypeId typeId) const noexcept = 0; /** * Checks whether the object is an instance of child instance of @@ -180,18 +182,17 @@ namespace RTTI { * @param T The type it self. * @param Parents Variadic number of direct parrent types of the type */ -#define RTTI_DECLARE_TYPEINFO(T, ...) \ - public: \ - using TypeInfo = RTTI::TypeInfo; \ - [[nodiscard]] virtual RTTI::TypeId typeId() const noexcept override { \ - return TypeInfo::Id(); \ - } \ - [[nodiscard]] virtual bool isById(RTTI::TypeId typeId) const noexcept override { \ - return TypeInfo::Is(typeId); \ - } \ - protected: \ - [[nodiscard]] virtual void const* _cast(RTTI::TypeId typeId) const noexcept override { \ - return TypeInfo::DynamicCast(typeId, this); \ - } - - \ No newline at end of file +#define RTTI_DECLARE_TYPEINFO(T, ...) \ +public: \ + using TypeInfo = RTTI::TypeInfo; \ + [[nodiscard]] virtual RTTI::TypeId typeId() const noexcept override { \ + return TypeInfo::Id(); \ + } \ + [[nodiscard]] virtual bool isById(RTTI::TypeId typeId) const noexcept override { \ + return TypeInfo::Is(typeId); \ + } \ + \ +protected: \ + [[nodiscard]] virtual void const* _cast(RTTI::TypeId typeId) const noexcept override { \ + return TypeInfo::DynamicCast(typeId, this); \ + } diff --git a/tests/hierarchy_test.cc b/tests/hierarchy_test.cc index 8573cd3..c45c919 100644 --- a/tests/hierarchy_test.cc +++ b/tests/hierarchy_test.cc @@ -14,11 +14,15 @@ struct ParentB : virtual GrandParent { RTTI_DECLARE_TYPEINFO(ParentB, GrandParent); }; -struct ChildA : ParentA, ParentB { +struct ChildA + : ParentA + , ParentB { RTTI_DECLARE_TYPEINFO(ChildA, ParentA, ParentB); }; -struct ChildB : ParentA, ParentB { +struct ChildB + : ParentA + , ParentB { RTTI_DECLARE_TYPEINFO(ChildB, ParentA, ParentB); };