1*cdf0e10cSrcweir // RegistryValueImpl.cpp: Implementierung der Klasse RegistryValueImpl.
2*cdf0e10cSrcweir //
3*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
4*cdf0e10cSrcweir 
5*cdf0e10cSrcweir #include "registryvalueimpl.hxx"
6*cdf0e10cSrcweir 
7*cdf0e10cSrcweir #ifdef _MSC_VER
8*cdf0e10cSrcweir #pragma warning(push, 1) /* disable warnings within system headers */
9*cdf0e10cSrcweir #endif
10*cdf0e10cSrcweir #include <windows.h>
11*cdf0e10cSrcweir #ifdef _MSC_VER
12*cdf0e10cSrcweir #pragma warning(pop)
13*cdf0e10cSrcweir #endif
14*cdf0e10cSrcweir 
15*cdf0e10cSrcweir #include <malloc.h>
16*cdf0e10cSrcweir #include <assert.h>
17*cdf0e10cSrcweir 
18*cdf0e10cSrcweir #include "stringconverter.hxx"
19*cdf0e10cSrcweir 
20*cdf0e10cSrcweir //#################################
21*cdf0e10cSrcweir // Creation/Destruction
22*cdf0e10cSrcweir //#################################
23*cdf0e10cSrcweir 
24*cdf0e10cSrcweir //--------------------------------------------
25*cdf0e10cSrcweir /**
26*cdf0e10cSrcweir */
27*cdf0e10cSrcweir RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, int Value) :
28*cdf0e10cSrcweir 	m_Name(Name),
29*cdf0e10cSrcweir 	m_Type(REG_DWORD),
30*cdf0e10cSrcweir 	m_IntData(Value)
31*cdf0e10cSrcweir {
32*cdf0e10cSrcweir }
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir //--------------------------------------------
35*cdf0e10cSrcweir /**
36*cdf0e10cSrcweir */
37*cdf0e10cSrcweir RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, const std::wstring& Value) :
38*cdf0e10cSrcweir 	m_Name(Name),
39*cdf0e10cSrcweir 	m_Type(REG_SZ),
40*cdf0e10cSrcweir 	m_StringData(Value),
41*cdf0e10cSrcweir 	m_IntData(0)
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir }
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //--------------------------------------------
46*cdf0e10cSrcweir /**
47*cdf0e10cSrcweir */
48*cdf0e10cSrcweir RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, const std::string& Value) :
49*cdf0e10cSrcweir 	m_Name(Name),
50*cdf0e10cSrcweir 	m_Type(REG_SZ),
51*cdf0e10cSrcweir 	m_IntData(0)
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir 	m_StringData = AnsiToUnicodeString(Value);
54*cdf0e10cSrcweir }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #if (_MSC_VER >= 1300)
57*cdf0e10cSrcweir RegistryValueImpl::RegistryValueImpl(const RegistryValueImpl& s) :
58*cdf0e10cSrcweir 	m_Name(s.m_Name),
59*cdf0e10cSrcweir 	m_Type(s.m_Type),
60*cdf0e10cSrcweir 	m_StringData(s.m_StringData),
61*cdf0e10cSrcweir 	m_IntData(s.m_IntData)
62*cdf0e10cSrcweir 	{
63*cdf0e10cSrcweir }
64*cdf0e10cSrcweir #endif
65*cdf0e10cSrcweir //--------------------------------------------
66*cdf0e10cSrcweir /**
67*cdf0e10cSrcweir */
68*cdf0e10cSrcweir RegistryValueImpl::~RegistryValueImpl()
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir //#################################
73*cdf0e10cSrcweir // Query
74*cdf0e10cSrcweir //#################################
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //--------------------------------------------
77*cdf0e10cSrcweir /** Returns the name of the value
78*cdf0e10cSrcweir */
79*cdf0e10cSrcweir std::wstring RegistryValueImpl::GetName() const
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 	return m_Name;
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir //--------------------------------------------
85*cdf0e10cSrcweir /** Return the size of data held
86*cdf0e10cSrcweir */
87*cdf0e10cSrcweir size_t RegistryValueImpl::GetDataSize() const
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	size_t size = 0;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	if (REG_DWORD == m_Type)
92*cdf0e10cSrcweir 		size = sizeof(m_IntData);
93*cdf0e10cSrcweir 	else if (REG_SZ == m_Type)
94*cdf0e10cSrcweir 		size = m_StringData.length() ? ((m_StringData.length() + 1) * sizeof(wchar_t)) : 0;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	return size;
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir //--------------------------------------------
100*cdf0e10cSrcweir /** Get a pointer to the data buffer
101*cdf0e10cSrcweir 	in order to copy the data
102*cdf0e10cSrcweir */
103*cdf0e10cSrcweir const void* RegistryValueImpl::GetDataBuffer() const
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir 	const void* pData = 0;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	if (REG_DWORD == m_Type)
108*cdf0e10cSrcweir 		pData = reinterpret_cast<const void*>(&m_IntData);
109*cdf0e10cSrcweir 	else if (REG_SZ == m_Type)
110*cdf0e10cSrcweir 		pData = reinterpret_cast<const void*>(m_StringData.c_str());
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	return pData;
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir //--------------------------------------------
116*cdf0e10cSrcweir /** Returns the data as string
117*cdf0e10cSrcweir */
118*cdf0e10cSrcweir std::wstring RegistryValueImpl::GetDataAsUniString() const
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir 	assert(REG_SZ == m_Type);
121*cdf0e10cSrcweir 	return m_StringData;
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir //--------------------------------------------
125*cdf0e10cSrcweir /** Returns the data as string
126*cdf0e10cSrcweir */
127*cdf0e10cSrcweir std::string RegistryValueImpl::GetDataAsAnsiString() const
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir 	assert(REG_SZ == m_Type);
130*cdf0e10cSrcweir 	return UnicodeToAnsiString(m_StringData);
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //--------------------------------------------
134*cdf0e10cSrcweir /** Returns the data as number
135*cdf0e10cSrcweir */
136*cdf0e10cSrcweir int RegistryValueImpl::GetDataAsInt() const
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	assert(REG_DWORD == m_Type);
139*cdf0e10cSrcweir 	return m_IntData;
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir //--------------------------------------------
143*cdf0e10cSrcweir /** Returns the type of the data
144*cdf0e10cSrcweir */
145*cdf0e10cSrcweir int RegistryValueImpl::GetType() const
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir 	return m_Type;
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir //#################################
152*cdf0e10cSrcweir // Command
153*cdf0e10cSrcweir //#################################
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir //--------------------------------------------
157*cdf0e10cSrcweir /** Set a new name
158*cdf0e10cSrcweir */
159*cdf0e10cSrcweir void RegistryValueImpl::SetName(const std::wstring& NewName)
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir 	m_Name = NewName;
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir //--------------------------------------------
165*cdf0e10cSrcweir /**
166*cdf0e10cSrcweir */
167*cdf0e10cSrcweir void RegistryValueImpl::SetValue(const std::wstring& NewValue)
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir 	m_Type = REG_SZ;
170*cdf0e10cSrcweir 	m_StringData = NewValue;
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir //--------------------------------------------
174*cdf0e10cSrcweir /**
175*cdf0e10cSrcweir */
176*cdf0e10cSrcweir void RegistryValueImpl::SetValue(const std::string& NewValue)
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir 	m_Type = REG_SZ;
179*cdf0e10cSrcweir 	m_StringData = AnsiToUnicodeString(NewValue);
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir //--------------------------------------------
183*cdf0e10cSrcweir /**
184*cdf0e10cSrcweir */
185*cdf0e10cSrcweir void RegistryValueImpl::SetValue(int NewValue)
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir 	m_Type = REG_DWORD;
188*cdf0e10cSrcweir 	m_IntData = NewValue;
189*cdf0e10cSrcweir }
190