1*32b1fd08SAndrew Rist /**************************************************************
2*32b1fd08SAndrew Rist  *
3*32b1fd08SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*32b1fd08SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*32b1fd08SAndrew Rist  * distributed with this work for additional information
6*32b1fd08SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*32b1fd08SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*32b1fd08SAndrew Rist  * "License"); you may not use this file except in compliance
9*32b1fd08SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*32b1fd08SAndrew Rist  *
11*32b1fd08SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*32b1fd08SAndrew Rist  *
13*32b1fd08SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*32b1fd08SAndrew Rist  * software distributed under the License is distributed on an
15*32b1fd08SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*32b1fd08SAndrew Rist  * KIND, either express or implied.  See the License for the
17*32b1fd08SAndrew Rist  * specific language governing permissions and limitations
18*32b1fd08SAndrew Rist  * under the License.
19*32b1fd08SAndrew Rist  *
20*32b1fd08SAndrew Rist  *************************************************************/
21*32b1fd08SAndrew Rist 
22cdf0e10cSrcweir // RegistryValueImpl.cpp: Implementierung der Klasse RegistryValueImpl.
23cdf0e10cSrcweir //
24cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "registryvalueimpl.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #ifdef _MSC_VER
29cdf0e10cSrcweir #pragma warning(push, 1) /* disable warnings within system headers */
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include <windows.h>
32cdf0e10cSrcweir #ifdef _MSC_VER
33cdf0e10cSrcweir #pragma warning(pop)
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <malloc.h>
37cdf0e10cSrcweir #include <assert.h>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "stringconverter.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //#################################
42cdf0e10cSrcweir // Creation/Destruction
43cdf0e10cSrcweir //#################################
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //--------------------------------------------
46cdf0e10cSrcweir /**
47cdf0e10cSrcweir */
RegistryValueImpl(const std::wstring & Name,int Value)48cdf0e10cSrcweir RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, int Value) :
49cdf0e10cSrcweir 	m_Name(Name),
50cdf0e10cSrcweir 	m_Type(REG_DWORD),
51cdf0e10cSrcweir 	m_IntData(Value)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //--------------------------------------------
56cdf0e10cSrcweir /**
57cdf0e10cSrcweir */
RegistryValueImpl(const std::wstring & Name,const std::wstring & Value)58cdf0e10cSrcweir RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, const std::wstring& Value) :
59cdf0e10cSrcweir 	m_Name(Name),
60cdf0e10cSrcweir 	m_Type(REG_SZ),
61cdf0e10cSrcweir 	m_StringData(Value),
62cdf0e10cSrcweir 	m_IntData(0)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //--------------------------------------------
67cdf0e10cSrcweir /**
68cdf0e10cSrcweir */
RegistryValueImpl(const std::wstring & Name,const std::string & Value)69cdf0e10cSrcweir RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, const std::string& Value) :
70cdf0e10cSrcweir 	m_Name(Name),
71cdf0e10cSrcweir 	m_Type(REG_SZ),
72cdf0e10cSrcweir 	m_IntData(0)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	m_StringData = AnsiToUnicodeString(Value);
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir #if (_MSC_VER >= 1300)
RegistryValueImpl(const RegistryValueImpl & s)78cdf0e10cSrcweir RegistryValueImpl::RegistryValueImpl(const RegistryValueImpl& s) :
79cdf0e10cSrcweir 	m_Name(s.m_Name),
80cdf0e10cSrcweir 	m_Type(s.m_Type),
81cdf0e10cSrcweir 	m_StringData(s.m_StringData),
82cdf0e10cSrcweir 	m_IntData(s.m_IntData)
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir }
85cdf0e10cSrcweir #endif
86cdf0e10cSrcweir //--------------------------------------------
87cdf0e10cSrcweir /**
88cdf0e10cSrcweir */
~RegistryValueImpl()89cdf0e10cSrcweir RegistryValueImpl::~RegistryValueImpl()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir //#################################
94cdf0e10cSrcweir // Query
95cdf0e10cSrcweir //#################################
96cdf0e10cSrcweir 
97cdf0e10cSrcweir //--------------------------------------------
98cdf0e10cSrcweir /** Returns the name of the value
99cdf0e10cSrcweir */
GetName() const100cdf0e10cSrcweir std::wstring RegistryValueImpl::GetName() const
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	return m_Name;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir //--------------------------------------------
106cdf0e10cSrcweir /** Return the size of data held
107cdf0e10cSrcweir */
GetDataSize() const108cdf0e10cSrcweir size_t RegistryValueImpl::GetDataSize() const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	size_t size = 0;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	if (REG_DWORD == m_Type)
113cdf0e10cSrcweir 		size = sizeof(m_IntData);
114cdf0e10cSrcweir 	else if (REG_SZ == m_Type)
115cdf0e10cSrcweir 		size = m_StringData.length() ? ((m_StringData.length() + 1) * sizeof(wchar_t)) : 0;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	return size;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir //--------------------------------------------
121cdf0e10cSrcweir /** Get a pointer to the data buffer
122cdf0e10cSrcweir 	in order to copy the data
123cdf0e10cSrcweir */
GetDataBuffer() const124cdf0e10cSrcweir const void* RegistryValueImpl::GetDataBuffer() const
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	const void* pData = 0;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	if (REG_DWORD == m_Type)
129cdf0e10cSrcweir 		pData = reinterpret_cast<const void*>(&m_IntData);
130cdf0e10cSrcweir 	else if (REG_SZ == m_Type)
131cdf0e10cSrcweir 		pData = reinterpret_cast<const void*>(m_StringData.c_str());
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	return pData;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //--------------------------------------------
137cdf0e10cSrcweir /** Returns the data as string
138cdf0e10cSrcweir */
GetDataAsUniString() const139cdf0e10cSrcweir std::wstring RegistryValueImpl::GetDataAsUniString() const
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	assert(REG_SZ == m_Type);
142cdf0e10cSrcweir 	return m_StringData;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir //--------------------------------------------
146cdf0e10cSrcweir /** Returns the data as string
147cdf0e10cSrcweir */
GetDataAsAnsiString() const148cdf0e10cSrcweir std::string RegistryValueImpl::GetDataAsAnsiString() const
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	assert(REG_SZ == m_Type);
151cdf0e10cSrcweir 	return UnicodeToAnsiString(m_StringData);
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir //--------------------------------------------
155cdf0e10cSrcweir /** Returns the data as number
156cdf0e10cSrcweir */
GetDataAsInt() const157cdf0e10cSrcweir int RegistryValueImpl::GetDataAsInt() const
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	assert(REG_DWORD == m_Type);
160cdf0e10cSrcweir 	return m_IntData;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //--------------------------------------------
164cdf0e10cSrcweir /** Returns the type of the data
165cdf0e10cSrcweir */
GetType() const166cdf0e10cSrcweir int RegistryValueImpl::GetType() const
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	return m_Type;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
172cdf0e10cSrcweir //#################################
173cdf0e10cSrcweir // Command
174cdf0e10cSrcweir //#################################
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
177cdf0e10cSrcweir //--------------------------------------------
178cdf0e10cSrcweir /** Set a new name
179cdf0e10cSrcweir */
SetName(const std::wstring & NewName)180cdf0e10cSrcweir void RegistryValueImpl::SetName(const std::wstring& NewName)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 	m_Name = NewName;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir //--------------------------------------------
186cdf0e10cSrcweir /**
187cdf0e10cSrcweir */
SetValue(const std::wstring & NewValue)188cdf0e10cSrcweir void RegistryValueImpl::SetValue(const std::wstring& NewValue)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	m_Type = REG_SZ;
191cdf0e10cSrcweir 	m_StringData = NewValue;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir //--------------------------------------------
195cdf0e10cSrcweir /**
196cdf0e10cSrcweir */
SetValue(const std::string & NewValue)197cdf0e10cSrcweir void RegistryValueImpl::SetValue(const std::string& NewValue)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir 	m_Type = REG_SZ;
200cdf0e10cSrcweir 	m_StringData = AnsiToUnicodeString(NewValue);
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir //--------------------------------------------
204cdf0e10cSrcweir /**
205cdf0e10cSrcweir */
SetValue(int NewValue)206cdf0e10cSrcweir void RegistryValueImpl::SetValue(int NewValue)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir 	m_Type = REG_DWORD;
209cdf0e10cSrcweir 	m_IntData = NewValue;
210cdf0e10cSrcweir }
211