diff --git a/autowiring/CoreContext.h b/autowiring/CoreContext.h index 48564b466..112da6e51 100644 --- a/autowiring/CoreContext.h +++ b/autowiring/CoreContext.h @@ -147,7 +147,7 @@ class CoreContext: { protected: typedef std::list> t_childList; - CoreContext(const std::shared_ptr& pParent, t_childList::iterator backReference); + CoreContext(const std::shared_ptr& pParent, t_childList::iterator backReference, const std::type_info& sigilType); public: // Asserted when the context is initiated @@ -178,6 +178,9 @@ class CoreContext: // Back-referencing iterator which refers to ourselves in our parent's child list: const t_childList::iterator m_backReference; + // Sigil type, used during bolting + const std::type_info& m_sigilType; + // State block for this context: std::shared_ptr m_stateBlock; @@ -528,7 +531,7 @@ class CoreContext: /// The number of child contexts of this context. size_t GetChildCount(void) const; /// The type used as a sigil when creating this class, if any. - virtual const std::type_info& GetSigilType(void) const = 0; + const std::type_info& GetSigilType(void) const { return m_sigilType; } /// The Context iterator for the parent context's children, pointing to this context. t_childList::iterator GetBackReference(void) const { return m_backReference; } /// A shared reference to the parent context of this context. @@ -545,7 +548,7 @@ class CoreContext: /// True if the sigil type of this CoreContext matches the specified sigil type. template - bool Is(void) const { return GetSigilType() == typeid(Sigil); } + bool Is(void) const { return m_sigilType == typeid(Sigil); } /// /// The first child in the set of this context's children. @@ -1327,18 +1330,11 @@ class CoreContextT: public CoreContext { public: - static const std::type_info& sc_type; - CoreContextT(const std::shared_ptr& pParent, t_childList::iterator backReference) : - CoreContext(pParent, backReference) + CoreContext(pParent, backReference, typeid(T)) {} - - const std::type_info& GetSigilType(void) const override { return sc_type; } }; -template -const std::type_info& CoreContextT::sc_type = typeid(T); - std::ostream& operator<<(std::ostream& os, const CoreContext& context); #include "MicroBolt.h" diff --git a/src/autowiring/CoreContext.cpp b/src/autowiring/CoreContext.cpp index 2e033a3c8..77e8cbf73 100644 --- a/src/autowiring/CoreContext.cpp +++ b/src/autowiring/CoreContext.cpp @@ -52,9 +52,10 @@ class DelayedContextHold: static thread_specific_ptr> autoCurrentContext; // Peer Context Constructor. Called interally by CreatePeer -CoreContext::CoreContext(const std::shared_ptr& pParent, t_childList::iterator backReference) : +CoreContext::CoreContext(const std::shared_ptr& pParent, t_childList::iterator backReference, const std::type_info& sigilType) : m_pParent(pParent), m_backReference(backReference), + m_sigilType(sigilType), m_stateBlock(std::make_shared(pParent ? pParent->m_stateBlock : nullptr)), m_junctionBoxManager(new JunctionBoxManager), m_threadPool(std::make_shared()) diff --git a/src/autowiring/test/CoreContextTest.cpp b/src/autowiring/test/CoreContextTest.cpp index ce021518b..add04acb4 100644 --- a/src/autowiring/test/CoreContextTest.cpp +++ b/src/autowiring/test/CoreContextTest.cpp @@ -8,6 +8,12 @@ #include THREAD_HEADER #include FUTURE_HEADER +// A lot of clients invoke arbitrary CoreContext members during teardown of this type. If any of those members are +// potentially abstract, the result could be a disastrous pure virtual function call. Broadly speaking, while there +// are not guarantees that calls to the base versions of CoreContext virtual functions will perform the desired +// operation, there should never be a circumstance where such calls trigger a crash. +static_assert(!std::is_abstract::value, "CoreContext cannot be abstract"); + class CoreContextTest: public testing::Test {};