|
#include "Registry.h"
#include <vector>
class RegDDX
{
public:
RegDDX(CDataExchange* pDX, RegKey& key)
{ m_stack.push_back(key); m_save = (pDX->m_bSaveAndValidate != 0); }
~RegDDX()
{ m_stack.clear(); }
public:
RegDDX(const RegDDX& other);
RegDDX& operator=(const RegDDX& rhs);
public:
void PushKey(LPCTSTR name)
{ m_stack.push_back(m_stack.back().Key(name)); }
void PopKey()
{ m_stack.pop_back(); }
public:
bool SetBool(bool& val, LPCTSTR name)
{
RegValue rv = m_stack.back().Value(name);
return (m_save ? rv.Set(val) : rv.Get(val));
}
bool SetInt(int& val, LPCTSTR name)
{
RegValue rv = m_stack.back().Value(name);
return (m_save ? rv.Set(val) : rv.Get(val));
}
bool SetDouble(double& val, LPCTSTR name)
{
RegValue rv = m_stack.back().Value(name);
return (m_save ? rv.Set(val) : rv.Get(val));
}
bool SetString(CString& val, LPCTSTR name)
{
bool result = false;
RegValue rv = m_stack.back().Value(name);
if (m_save) {
result = rv.Set(val);
} else {
result = rv.Get(val.GetBuffer(MAX_PATH), MAX_PATH);
val.ReleaseBuffer(MAX_PATH);
}
return result;
}
protected:
typedef std::vector<RegKey> KeyStack;
KeyStack m_stack;
bool m_save;
};
template <class O>
class RegDDXMethodCall
{
public:
typedef O ObjectType;
typedef void (O::*PMethod)(CDataExchange*);
RegDDXMethodCall()
: ctx(NULL), object(NULL), method(NULL)
{}
RegDDXMethodCall(CDataExchange* c, ObjectType* o, PMethod m)
: ctx(c), object(o), method(m)
{ if (!ctx->m_bSaveAndValidate && object && method) Call(); }
~RegDDXMethodCall()
{ if (ctx->m_bSaveAndValidate && object && method) Call(); }
void Call()
{ (object->*method)(ctx); }
ObjectType* object;
PMethod method;
CDataExchange* ctx;
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
A compiler warns of bogasity, ignore it at your peril. Unless you've done the compiler's job yourself, don't criticize it.