From bdb3f0597f6ac1eac050a68053d2c4acebdf644d Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Tue, 12 Apr 2016 13:17:28 +0000 Subject: m_gui: CMOption for strings git-svn-id: http://svn.miranda-ng.org/main/trunk@16632 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/m_gui.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'include') diff --git a/include/m_gui.h b/include/m_gui.h index b919207189..c78ebfe7e7 100644 --- a/include/m_gui.h +++ b/include/m_gui.h @@ -133,6 +133,72 @@ private: void operator= (const CMOption &) {} }; +#ifdef M_SYSTEM_CPP_H__ + +template<> +class CMOption : public CMOptionBase +{ +public: + + typedef char Type; + + __forceinline CMOption(PROTO_INTERFACE *proto, char *szSetting, const Type *defValue = nullptr) : + CMOptionBase(proto, szSetting), m_default(defValue) + {} + + __forceinline operator Type*() + { + m_value = m_proto->getStringA(m_szSetting); + if (!m_value) m_value = mir_strdup(m_default); + return m_value; + } + __forceinline Type* operator= (Type *value) + { + m_proto->setString(m_szSetting, value); + return value; + } + +private: + const Type *m_default; + mir_ptr m_value; + + CMOption(const CMOption &) : CMOptionBase(NULL, NULL) {} + void operator= (const CMOption &) {} +}; + +template<> +class CMOption : public CMOptionBase +{ +public: + + typedef wchar_t Type; + + __forceinline CMOption(PROTO_INTERFACE *proto, char *szSetting, const Type *defValue = nullptr) : + CMOptionBase(proto, szSetting), m_default(defValue) + {} + + __forceinline operator Type*() + { + m_value = m_proto->getWStringA(m_szSetting); + if (!m_value) m_value = mir_wstrdup(m_default); + return m_value; + } + + __forceinline const Type* operator= (const Type *value) + { + m_proto->setWString(m_szSetting, value); + return value; + } + +private: + const Type *m_default; + mir_ptr m_value; + + CMOption(const CMOption &) : CMOptionBase(NULL, NULL) {} + void operator= (const CMOption &) {} +}; + +#endif ///////////////////////////////////////////////////////////////////////////////////////// // Callbacks -- cgit v1.2.3