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