Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/plugin/COM_Value.cpp

Issue 6650591174459392: Issues #276, #1163 - introduce class IncomingParam (Closed)
Left Patch Set: Created July 25, 2014, 11:27 p.m.
Right Patch Set: rewrite incomparable with patch set 1 Created July 29, 2014, 7:52 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/COM_Value.h ('k') | src/plugin/PluginClass.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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)
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;
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.
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 }
65 65
66 66
67 namespace 67 bool IncomingParam::wstringConvertible() const
68 { 68 {
69 /** 69 /*
70 * Pre-construction assistant for wstring_Incoming_Param. 70 * Initial support is for BSTR only.
71 * 71 * We've got one case later where we'll need to support VT_I4.
72 * Because wstring_Incoming_Param is a derived class,
73 * we need to have a wstring value to initialize the base class.
74 */ 72 */
75 std::wstring construct_Incoming_Param( BSTR b ) 73 return var.vt == VT_BSTR;
76 {
77 if ( !b )
78 {
79 return std::wstring();
80 }
81 return std::wstring( b, SysStringLen( b ) );
82 }
83 } 74 }
84 75
85 Incoming_Param::Incoming_Param( BSTR b ) 76 std::wstring IncomingParam::wstringValueNoexcept() const
86 : std::wstring( construct_Incoming_Param( b ) )
87 { 77 {
78 return L"";
88 } 79 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld