Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / reg4msdoc / registryvalueimpl.cxx
blob36af0511b006bb15707eddce0f2e89e9dcbaa68e
1 // RegistryValueImpl.cpp: Implementierung der Klasse RegistryValueImpl.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #include "registryvalueimpl.hxx"
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
15 #include <malloc.h>
16 #include <assert.h>
18 #include "stringconverter.hxx"
20 //#################################
21 // Creation/Destruction
22 //#################################
24 //--------------------------------------------
25 /**
27 RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, int Value) :
28 m_Name(Name),
29 m_Type(REG_DWORD),
30 m_IntData(Value)
34 //--------------------------------------------
35 /**
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)
45 //--------------------------------------------
46 /**
48 RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, const std::string& Value) :
49 m_Name(Name),
50 m_Type(REG_SZ),
51 m_IntData(0)
53 m_StringData = AnsiToUnicodeString(Value);
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)
64 #endif
65 //--------------------------------------------
66 /**
68 RegistryValueImpl::~RegistryValueImpl()
72 //#################################
73 // Query
74 //#################################
76 //--------------------------------------------
77 /** Returns the name of the value
79 std::wstring RegistryValueImpl::GetName() const
81 return m_Name;
84 //--------------------------------------------
85 /** Return the size of data held
87 size_t RegistryValueImpl::GetDataSize() const
89 size_t size = 0;
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;
96 return size;
99 //--------------------------------------------
100 /** Get a pointer to the data buffer
101 in order to copy the data
103 const void* RegistryValueImpl::GetDataBuffer() const
105 const void* pData = 0;
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());
112 return pData;
115 //--------------------------------------------
116 /** Returns the data as string
118 std::wstring RegistryValueImpl::GetDataAsUniString() const
120 assert(REG_SZ == m_Type);
121 return m_StringData;
124 //--------------------------------------------
125 /** Returns the data as string
127 std::string RegistryValueImpl::GetDataAsAnsiString() const
129 assert(REG_SZ == m_Type);
130 return UnicodeToAnsiString(m_StringData);
133 //--------------------------------------------
134 /** Returns the data as number
136 int RegistryValueImpl::GetDataAsInt() const
138 assert(REG_DWORD == m_Type);
139 return m_IntData;
142 //--------------------------------------------
143 /** Returns the type of the data
145 int RegistryValueImpl::GetType() const
147 return m_Type;
151 //#################################
152 // Command
153 //#################################
156 //--------------------------------------------
157 /** Set a new name
159 void RegistryValueImpl::SetName(const std::wstring& NewName)
161 m_Name = NewName;
164 //--------------------------------------------
165 /**
167 void RegistryValueImpl::SetValue(const std::wstring& NewValue)
169 m_Type = REG_SZ;
170 m_StringData = NewValue;
173 //--------------------------------------------
174 /**
176 void RegistryValueImpl::SetValue(const std::string& NewValue)
178 m_Type = REG_SZ;
179 m_StringData = AnsiToUnicodeString(NewValue);
182 //--------------------------------------------
185 void RegistryValueImpl::SetValue(int NewValue)
187 m_Type = REG_DWORD;
188 m_IntData = NewValue;