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