Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /** | 1 /** |
2 * \file COM_Value.cpp Support for the values used in COM and Automation. | 2 * \file COM_Value.cpp Support for the values used in COM and Automation. |
3 */ | 3 */ |
4 #include "COM_Value.h" | 4 #include "COM_Value.h" |
5 #include <stdexcept> | 5 #include <stdexcept> |
6 | 6 |
7 using namespace AdblockPlus::COM; | 7 using namespace AdblockPlus::COM; |
8 | 8 |
9 /* | 9 /* |
10 * MSDN SysAllocStringLen function http://msdn.microsoft.com/en-us/library/windo ws/desktop/ms221639%28v=vs.85%29.aspx | 10 * MSDN SysAllocStringLen function http://msdn.microsoft.com/en-us/library/windo ws/desktop/ms221639%28v=vs.85%29.aspx |
11 */ | 11 */ |
12 BSTR_Argument::BSTR_Argument( const std::wstring& s ) | 12 BSTR_Argument::BSTR_Argument(const std::wstring& s) |
Eric
2014/07/30 14:14:42
If you initialize something in the constructor ini
| |
13 { | 13 { |
14 auto length = s.length(); | 14 auto length = s.length(); |
15 if ( length == 0 ) | 15 if (length == 0) |
16 { | 16 { |
17 /* | 17 /* |
18 * BSTR makes no distinction between null pointers and non-null pointers to the empty string. | 18 * BSTR makes no distinction between null pointers and non-null pointers to the empty string. |
19 * In order to detect allocation failure reliably, we simply don't allocate empty strings. | 19 * In order to detect allocation failure reliably, we simply don't allocate empty strings. |
20 * Compare with the default constructor. | 20 * Compare with the default constructor. |
21 */ | 21 */ |
22 bstr = nullptr; | 22 bstr = nullptr; |
sergei
2014/07/28 09:18:26
The comment should be in the header near the ctr,
Eric
2014/07/29 16:59:27
This is an implementation detail, not some basic p
| |
23 return; | 23 return; |
24 } | 24 } |
25 // Assert length >= 1 | 25 // Assert length >= 1 |
26 bstr = SysAllocStringLen( s.c_str(), length ); | 26 bstr = SysAllocStringLen(s.c_str(), length); |
27 /* | 27 /* |
28 * Since the string is non-empty, | 28 * Since the string is non-empty, |
29 * if the return value of SysAllocStringLen is null it means that it had an allocation failure. | 29 * if the return value of SysAllocStringLen is null it means that it had an allocation failure. |
30 */ | 30 */ |
31 if ( !bstr ) | 31 if (!bstr) |
32 { | 32 { |
33 throw std::bad_alloc(); | 33 throw std::bad_alloc(); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 /* | 37 /* |
38 * MSDN SysFreeString function http://msdn.microsoft.com/en-us/library/windows/d esktop/ms221481%28v=vs.85%29.aspx | 38 * MSDN SysFreeString function http://msdn.microsoft.com/en-us/library/windows/d esktop/ms221481%28v=vs.85%29.aspx |
39 */ | 39 */ |
40 BSTR_Argument::~BSTR_Argument() | 40 BSTR_Argument::~BSTR_Argument() |
41 { | 41 { |
42 // There's no need to check for null; SysFreeString already handles that case. | 42 // There's no need to check for null; SysFreeString already handles that case. |
43 SysFreeString( bstr ); | 43 SysFreeString(bstr); |
44 } | 44 } |
45 | 45 |
46 BSTR* BSTR_Argument::operator&() | 46 BSTR* BSTR_Argument::operator&() |
47 { | 47 { |
48 // Assign the empty string, if not already empty. | 48 // Assign the empty string, if not already empty. |
sergei
2014/07/28 09:18:26
I don't like the changing of the value when the ad
Eric
2014/07/29 16:59:27
Directly assigning to internal members of smart po
| |
49 if ( bstr ) | 49 if (bstr) |
50 { | 50 { |
51 SysFreeString( bstr ); | 51 SysFreeString(bstr); |
52 bstr = nullptr; | 52 bstr = nullptr; |
53 } | 53 } |
54 return &bstr; | 54 return &bstr; |
55 } | 55 } |
56 | 56 |
57 BSTR_Argument::operator std::wstring() const | 57 BSTR_Argument::operator std::wstring() const |
58 { | 58 { |
59 if ( !bstr ) | 59 if (!bstr) |
60 { | 60 { |
61 return std::wstring(); | 61 return std::wstring(); |
62 } | 62 } |
63 return std::wstring( bstr, SysStringLen( bstr ) ); | 63 return std::wstring(bstr, SysStringLen(bstr)); |
64 } | 64 } |
LEFT | RIGHT |