From 8c4603c73675958efc960fbd4bb599a2909d106a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 16 Jan 2023 14:52:43 +0100 Subject: Source codes --- ComLightLib/server/ObjectRoot.hpp | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ComLightLib/server/ObjectRoot.hpp (limited to 'ComLightLib/server/ObjectRoot.hpp') diff --git a/ComLightLib/server/ObjectRoot.hpp b/ComLightLib/server/ObjectRoot.hpp new file mode 100644 index 0000000..1cc8f4d --- /dev/null +++ b/ComLightLib/server/ObjectRoot.hpp @@ -0,0 +1,51 @@ +#pragma once +#include "RefCounter.hpp" +#include "../comLightCommon.h" +#include "../utils/typeTraits.hpp" + +namespace ComLight +{ + // Base class of objects, implements reference counting, also a few lifetime methods. + // The template argument is the interface you want clients to get when they ask for IID_IUnknown. By convention, that pointer defines object's identity. + template + class ObjectRoot : public RefCounter, public I + { + protected: + + inline HRESULT internalFinalConstruct() + { + return S_FALSE; + } + + inline HRESULT FinalConstruct() + { + return S_FALSE; + } + + inline void FinalRelease() { } + + IUnknown* getUnknown() + { + static_assert( details::pointersAssignable(), "The interface doesn't derive from IUnknown" ); + return static_cast( this ); + } + + bool queryExtraInterfaces( REFIID riid, void **ppvObject ) const + { + return false; + } + + // Implement query interface with 2 entries, IUnknown and I. + bool implQueryInterface( REFIID riid, void** ppvObject ) + { + if( riid == I::iid() || riid == IUnknown::iid() ) + { + I* const result = this; + result->AddRef(); + *ppvObject = result; + return true; + } + return false; + } + }; +} \ No newline at end of file -- cgit v1.2.3