From 0b033fdcac3c923ed5fecdd37e6367d4aef77cee Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 1 Apr 2014 11:28:51 +0200 Subject: [PATCH] refs #199 , context base class to simplify handling * usingLocalObjects() now derived from runtime config, no need to override it in contexts * getRuntime in base class, no longer to implement it in each context class --- src/blackcore/context.h | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/blackcore/context.h diff --git a/src/blackcore/context.h b/src/blackcore/context.h new file mode 100644 index 000000000..c94e68a3e --- /dev/null +++ b/src/blackcore/context.h @@ -0,0 +1,49 @@ +#ifndef BLACKCORE_CONTEXT_H +#define BLACKCORE_CONTEXT_H + +#include +#include "blackcore/context_runtime_config.h" +#include "blackcore/context_runtime.h" + +namespace BlackCore +{ + /*! + * \brief Base for all context classes + */ + class CContext : public QObject + { + private: + CRuntimeConfig::ContextMode m_mode; + + public: + //! Destructor + ~CContext() {} + + //! Using local objects? + bool usingLocalObjects() const + { + return m_mode == CRuntimeConfig::Local || m_mode == CRuntimeConfig::LocalInDbusServer; + } + + //! Runtime + CRuntime *getRuntime() + { + Q_ASSERT(this->parent()); + return static_cast(this->parent()); + } + + //! Const runtime + const CRuntime *getRuntime() const + { + Q_ASSERT(this->parent()); + return static_cast(this->parent()); + } + + protected: + //! Constructor + CContext(CRuntimeConfig::ContextMode mode, QObject *parent) : QObject(parent), m_mode(mode) + {} + + }; +} +#endif // guard