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

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

Issue 5070706781978624: Issue #276 - introduce class BSTR_Argument (Closed)
Left Patch Set: Created July 25, 2014, 9:32 p.m.
Right Patch Set: clarified documentation for operator&, updated to_wstring(CString) Created July 30, 2014, 2:13 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/AdblockPlusDomTraverser.cpp ('k') | src/plugin/COM_Value.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.h Support for the values used in COM and Automation. 2 * \file COM_Value.h Support for the values used in COM and Automation.
sergei 2014/07/28 09:18:26 All current comments in this file look redundant.
3 */ 3 */
4 #ifndef COM_VALUE_H 4 #ifndef COM_VALUE_H
5 #define COM_VALUE_H 5 #define COM_VALUE_H
6 6
7 #include <wtypes.h> 7 #include <wtypes.h>
8 #include <string> 8 #include <string>
9 9
10 namespace AdblockPlus 10 namespace AdblockPlus
11 { 11 {
12 namespace COM 12 namespace COM
13 { 13 {
14 /** 14 /**
15 * BSTR life cycle manager. Used by a caller to pass BSTR as an argument to a COM call. 15 * BSTR life cycle manager. Used by a caller to pass BSTR as an argument to a COM call.
16 * 16 *
17 * This class manages the life cycle of a BSTR passed as an argument to a CO M call. 17 * This class manages the life cycle of a BSTR passed as an argument to a CO M call.
18 * There are two different life cycles relevant here. 18 * There are two different life cycles relevant here.
19 * In the first, the BSTR acts as an ordinary argument; in the second, the B STR is a return value. 19 * In the first, the BSTR acts as an ordinary argument; in the second, the B STR is a return value.
20 * Both these are implemented as arguments to a COM function; 20 * Both these are implemented as arguments to a COM function;
21 * the difference is that one is an [in] param and the other is an [out]. 21 * the difference is that one is an [in] param and the other is an [out].
22 * In both cases, we must release an allocated string, whether or not we all ocated it. 22 * In both cases, we must release an allocated string, whether or not we all ocated it.
23 * Because of this commonality, it's possible to combine these two uses into a single class. 23 * Because of this commonality, it's possible to combine these two uses into a single class.
24 * 24 *
25 * The two life cycles differ in how the allocation is done. 25 * The two life cycles differ in how the allocation is done.
26 * When used as an argument, the caller must allocate. 26 * When used as an argument, the caller must allocate.
27 * In this case the caller uses the non-trivial constructor, which allocates a copy of its argument. 27 * In this case the caller uses the non-trivial constructor, which allocates a copy of its argument.
28 * When used for a result, the called function allocates. 28 * When used for a result, the called function allocates.
29 * In this case the caller uses the default constructor and the address-of o perator; 29 * In this case the caller uses the default constructor and the address-of o perator;
30 * the address-of operator does not allocate and its pointer must be assig ned an allocated value. 30 * the address-of operator does not allocate and its pointer must be assig ned an allocated value.
31 * 31 *
32 * Copy/move constructor/assignment are all deleted, not because they couldn 't be implemented, 32 * Copy/move constructor/assignment are all deleted, not because they couldn 't be implemented,
33 * but because these class are meant to be used in tight conjunction with API calls. 33 * but because these class are meant to be used in tight conjunction with API calls.
34 * Thus their design use requires that they not leave this proximity. 34 * Thus their design use requires that they not leave this proximity.
35 * 35 *
36 * \par Reference 36 * \par Reference
37 * MSDN "Allocating and Releasing Memory for a BSTR" http://msdn.microsoft .com/en-us/library/vstudio/xda6xzx7%28v=vs.120%29.aspx 37 * MSDN "Allocating and Releasing Memory for a BSTR" http://msdn.microsoft .com/en-us/library/vstudio/xda6xzx7%28v=vs.120%29.aspx
38 * "When you call into a function that expects a BSTR argument, you must a llocate the memory for the BSTR before the call and release it afterwards." 38 * "When you call into a function that expects a BSTR argument, you must a llocate the memory for the BSTR before the call and release it afterwards."
39 * "When you call into a function that returns a BSTR, you must free the s tring yourself." 39 * "When you call into a function that returns a BSTR, you must free the s tring yourself."
40 * 40 *
41 * \invariant Either bstr == nullptr or bstr is a non-null system-allocated BSTR. 41 * \invariant Either bstr == nullptr or bstr is a non-null system-allocated BSTR.
42 */ 42 */
43 class BSTR_Argument 43 class BSTR_Argument
44 { 44 {
45 /** 45 /**
46 * The underlying BSTR pointer. 46 * The underlying BSTR pointer.
47 */ 47 */
48 BSTR bstr; 48 BSTR bstr;
49 49
50 public: 50 public:
51 /** 51 /**
52 * Default constructor has the value of the empty string. 52 * Default constructor has the value of the empty string.
53 */ 53 */
54 BSTR_Argument() 54 BSTR_Argument()
55 : bstr( nullptr ) 55 : bstr(nullptr)
56 { 56 {
57 } 57 }
58 58
59 /** 59 /**
60 * Constructor from std::wstring. 60 * Constructor from std::wstring.
61 */ 61 */
62 BSTR_Argument( const std::wstring& s ); 62 BSTR_Argument(const std::wstring& s);
sergei 2014/07/28 09:18:26 explicit
Eric 2014/07/29 16:59:27 Why? There's no need for it. There's no context wh
sergei 2014/07/30 10:10:54 No assumptions.
63 63
64 /** 64 /**
65 * Destructor 65 * Destructor
66 * 66 *
67 * The destructor frees the BSTR. 67 * The destructor frees the BSTR.
68 * Do not use this class when freeing the BSTR is not our responsibility. 68 * Do not use this class when freeing the BSTR is not our responsibility.
69 */ 69 */
70 ~BSTR_Argument(); 70 ~BSTR_Argument();
71 71
72 /** 72 /**
73 * Conversion operator to BSTR. 73 * Conversion operator to BSTR.
74 */ 74 */
75 operator BSTR() const 75 operator BSTR() const
sergei 2014/07/28 09:18:26 operator const BSTR() const
Eric 2014/07/29 16:59:27 There's no such thing as a 'const BSTR'. Tried it
sergei 2014/07/30 10:10:54 I've tried it also and it works. struct X { oper
Eric 2014/07/30 14:14:42 I did not say you couldn't declare it. What I said
76 { 76 {
77 return bstr; 77 return bstr;
78 } 78 }
79 79
80 /** 80 /**
81 * Conversion operator to std::wstring 81 * Conversion operator to std::wstring
82 */ 82 */
83 operator std::wstring() const; 83 operator std::wstring() const;
84 84
85 /** 85 /**
86 * Address-of operator. 86 * Address-of operator.
87 * 87 *
88 * This operator is used for assignment directly into our underlying point er. 88 * This operator is used for assignment directly into our underlying point er.
89 * In order to avoid leaking memory, this operator also implicitly assigns the null string. 89 * In order to avoid leaking memory, this operator also implicitly assigns the null string.
90 * Specifically, this operator is not 'const'. 90 * Specifically, this operator is not 'const'.
91 * 91 *
92 * \postcondition 92 * \par postcondition
93 * bstr == nullptr 93 * - bstr == nullptr
94 * - return value is not null
95 * - does not throw
94 */ 96 */
95 BSTR* operator&(); 97 BSTR* operator&(); // noexcept
96 98
97 private: 99 private:
98 /** 100 /**
99 * Copy constructor is deleted 101 * Copy constructor is deleted
100 */ 102 */
101 BSTR_Argument( const BSTR_Argument& ); // = delete 103 BSTR_Argument(const BSTR_Argument&); // = delete
102 104
103 /** 105 /**
104 * Move constructor is deleted 106 * Move constructor is deleted
105 */ 107 */
106 BSTR_Argument( BSTR_Argument&& ); // = delete 108 BSTR_Argument(BSTR_Argument&&); // = delete
107 109
108 /** 110 /**
109 * Copy assignment is deleted 111 * Copy assignment is deleted
110 */ 112 */
111 BSTR_Argument& operator=( const BSTR_Argument& ); // = delete 113 BSTR_Argument& operator=(const BSTR_Argument&); // = delete
112 114
113 /** 115 /**
114 * Move assignment is deleted 116 * Move assignment is deleted
115 */ 117 */
116 BSTR_Argument& operator=( BSTR_Argument&& ); // = delete 118 BSTR_Argument& operator=(BSTR_Argument&&); // = delete
117 }; 119 };
118 } 120 }
119 } 121 }
120 122
121 #endif 123 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld