OLD | NEW |
1 /** | 1 /** |
2 * \file record.h Definition of Record class. | 2 * \file record.h Definition of Record class. |
3 */ | 3 */ |
4 | 4 |
5 #ifndef RECORD_H | 5 #ifndef RECORD_H |
6 #define RECORD_H | 6 #define RECORD_H |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include <Windows.h> | 10 #include <Windows.h> |
11 #include <Msi.h> | 11 #include <Msi.h> |
12 | 12 |
13 #include "handle.h" | 13 #include "handle.h" |
14 | 14 |
15 // Forward | 15 // Forward |
16 class View ; | 16 class View ; |
17 | 17 |
18 /** | 18 /** |
19 * An abstract record entity. | 19 * An abstract record entity. |
20 * It represents both records in the installation database and as argument vector
s for API functions. | 20 * It represents both records in the installation database and as argument vector
s for API functions. |
21 * | 21 * |
22 * The ordinary constructor creates a free-standing record. | 22 * The ordinary constructor creates a free-standing record. |
23 * It takes only the number of fields in the created record. | 23 * It takes only the number of fields in the created record. |
24 * The fields of the record are dynamically typed according to how they're assign
ed. | 24 * The fields of the record are dynamically typed according to how they're assign
ed. |
25 * Other constructors will be required to encapsulate records that are bound to d
atabases. | 25 * Other constructors will be required to encapsulate records that are bound to d
atabases. |
26 * | 26 * |
27 * This class has exclusive-ownership semantics for the API handle to the record. | 27 * This class has exclusive-ownership semantics for the API handle to the record. |
28 * Every constructor has a postcondition that the _handle member points to an ope
n record. | 28 * Every constructor has a postcondition that the handle member points to an open
record. |
29 * The destructor closes the record. | 29 * The destructor closes the record. |
30 * The copy constructor syntax is used as a move constructor (since no C++11 yet)
. | 30 * The copy constructor syntax is used as a move constructor (since no C++11 yet)
. |
31 * Analogously, copy assignment has move semantics. | 31 * Analogously, copy assignment has move semantics. |
32 * | 32 * |
33 * \par Invariant | 33 * \par Invariant |
34 * - _handle is not null implies _handle points to a record open in the Windows
Installer subsystem | 34 * - handle is not null implies handle points to a record open in the Windows I
nstaller subsystem |
35 * | 35 * |
36 * \sa http://msdn.microsoft.com/en-us/library/windows/desktop/aa372881%28v=vs.85
%29.aspx | 36 * \sa http://msdn.microsoft.com/en-us/library/windows/desktop/aa372881%28v=vs.85
%29.aspx |
37 * Windows Installer on MSDN: "Working with Records" | 37 * Windows Installer on MSDN: "Working with Records" |
38 */ | 38 */ |
39 class Record { | 39 class Record { |
40 /** | 40 /** |
41 * | 41 * |
42 */ | 42 */ |
43 typedef handle< MSIHANDLE, Special_Null, MSI_Generic_Destruction > record_hand
le_type ; | 43 typedef Handle< MSIHANDLE, SpecialNull, GenericMsiDestruction > RecordHandleTy
pe ; |
44 | 44 |
45 /** | 45 /** |
46 * The handle for the record as a Windows Installer resource. | 46 * The handle for the record as a Windows Installer resource. |
47 */ | 47 */ |
48 MSIHANDLE _handle ; | 48 MSIHANDLE handle ; |
49 | 49 |
50 /** | 50 /** |
51 * Construct a record from its handle as returned by some MSI call. | 51 * Construct a record from its handle as returned by some MSI call. |
52 */ | 52 */ |
53 Record( msi_handle handle ) | 53 Record( MsiHandle handle ) |
54 : _handle( handle ) | 54 : handle( handle ) |
55 {} | 55 {} |
56 | 56 |
57 /** | 57 /** |
58 * Internal validation guard for operations that require a non-null handle. | 58 * Internal validation guard for operations that require a non-null handle. |
59 * | 59 * |
60 * \post | 60 * \post |
61 * - if _handle is zero, throw an exception | 61 * - if handle is zero, throw an exception |
62 * - if _handle is non-zero, nothing | 62 * - if handle is non-zero, nothing |
63 */ | 63 */ |
64 void only_non_null() ; | 64 void OnlyNonNull() ; |
65 | 65 |
66 /** | 66 /** |
67 * Proxy class used to implement move semantics, prior to use of C++11. | 67 * Proxy class used to implement move semantics, prior to use of C++11. |
68 * | 68 * |
69 * /sa | 69 * /sa |
70 * - Wikibooks [More C++ Idioms/Move Constructor](http://en.wikibooks.org/wik
i/More_C%2B%2B_Idioms/Move_Constructor) | 70 * - Wikibooks [More C++ Idioms/Move Constructor](http://en.wikibooks.org/wik
i/More_C%2B%2B_Idioms/Move_Constructor) |
71 */ | 71 */ |
72 struct Proxy_Record | 72 struct ProxyRecord |
73 { | 73 { |
74 MSIHANDLE _handle ; | 74 MSIHANDLE handle ; |
75 | 75 |
76 Proxy_Record( MSIHANDLE handle ) | 76 ProxyRecord( MSIHANDLE handle ) |
77 : _handle( handle ) | 77 : handle( handle ) |
78 {} | 78 {} |
79 } ; | 79 } ; |
80 | 80 |
81 /** | 81 /** |
82 * Tag class for null record constructor | 82 * Tag class for null record constructor |
83 */ | 83 */ |
84 class null_t {} ; | 84 class NullType {} ; |
85 | 85 |
86 /** | 86 /** |
87 * Null record constructor. | 87 * Null record constructor. |
88 * | 88 * |
89 * The null record constructor avoids the ordinary check that an external handl
e not be zero. | 89 * The null record constructor avoids the ordinary check that an external handl
e not be zero. |
90 * It's declared private so that only friends can instantiate them. | 90 * It's declared private so that only friends can instantiate them. |
91 */ | 91 */ |
92 Record( null_t ) | 92 Record( NullType ) |
93 : _handle( 0 ) | 93 : handle( 0 ) |
94 {} | 94 {} |
95 | 95 |
96 /** | 96 /** |
97 * View class needs access to constructor-from-handle. | 97 * View class needs access to constructor-from-handle. |
98 */ | 98 */ |
99 friend class View ; | 99 friend class View ; |
100 | 100 |
101 public: | 101 public: |
102 /** | 102 /** |
103 * Ordinary constructor creates a free-standing record. | 103 * Ordinary constructor creates a free-standing record. |
104 * Use this for creating argument vectors. | 104 * Use this for creating argument vectors. |
105 * | 105 * |
106 * \post _handle points to a record obtained from MsiCreateRecord | 106 * \post handle points to a record obtained from MsiCreateRecord |
107 * | 107 * |
108 * \param[in] n_fields | 108 * \param[in] nFields |
109 * Number of fields in the created record. | 109 * Number of fields in the created record. |
110 */ | 110 */ |
111 Record( unsigned int n_fields ) ; | 111 Record( unsigned int nFields ) ; |
112 | 112 |
113 /** | 113 /** |
114 * Destructor | 114 * Destructor |
115 */ | 115 */ |
116 ~Record() ; | 116 ~Record() ; |
117 | 117 |
118 /** | 118 /** |
119 * Copy constructor syntax used as a move constructor. | 119 * Copy constructor syntax used as a move constructor. |
120 */ | 120 */ |
121 Record( Record & r ) | 121 Record( Record & r ) |
122 : _handle( r._handle ) | 122 : handle( r.handle ) |
123 { | 123 { |
124 r._handle = 0 ; | 124 r.handle = 0 ; |
125 } | 125 } |
126 | 126 |
127 /** | 127 /** |
128 * Proxy move constructor. | 128 * Proxy move constructor. |
129 */ | 129 */ |
130 Record( Proxy_Record r ) | 130 Record( ProxyRecord r ) |
131 : _handle( r._handle ) | 131 : handle( r.handle ) |
132 { | 132 { |
133 r._handle = 0 ; | 133 r.handle = 0 ; |
134 } | 134 } |
135 | 135 |
136 /** | 136 /** |
137 * Copy assignment syntax has move assignment semantics. | 137 * Copy assignment syntax has move assignment semantics. |
138 */ | 138 */ |
139 Record & operator=( Record & r ) | 139 Record & operator=( Record & r ) |
140 { | 140 { |
141 this -> ~Record() ; | 141 this -> ~Record() ; |
142 _handle = r._handle ; | 142 handle = r.handle ; |
143 r._handle = 0 ; | 143 r.handle = 0 ; |
144 return * this ; | 144 return * this ; |
145 } | 145 } |
146 | 146 |
147 /** | 147 /** |
148 * Proxy move assignment. | 148 * Proxy move assignment. |
149 */ | 149 */ |
150 Record & operator=( Proxy_Record pr ) | 150 Record & operator=( ProxyRecord pr ) |
151 { | 151 { |
152 this -> ~Record() ; | 152 this -> ~Record() ; |
153 _handle = pr._handle ; | 153 handle = pr.handle ; |
154 pr._handle = 0 ; | 154 pr.handle = 0 ; |
155 return * this ; | 155 return * this ; |
156 } | 156 } |
157 | 157 |
158 /** | 158 /** |
159 * Proxy conversion operator | 159 * Proxy conversion operator |
160 */ | 160 */ |
161 operator Proxy_Record() | 161 operator ProxyRecord() |
162 { | 162 { |
163 Proxy_Record pr( _handle ) ; | 163 ProxyRecord pr( handle ) ; |
164 _handle = 0 ; | 164 handle = 0 ; |
165 return pr ; | 165 return pr ; |
166 } | 166 } |
167 | 167 |
168 /** | 168 /** |
169 * Two records are equal exactly when their handles are equal. | 169 * Two records are equal exactly when their handles are equal. |
170 */ | 170 */ |
171 inline bool operator==( const Record & x ) const | 171 inline bool operator==( const Record & x ) const |
172 { | 172 { |
173 return _handle == x._handle ; | 173 return handle == x.handle ; |
174 } | 174 } |
175 | 175 |
176 /** | 176 /** |
177 * Standard inequality operator defined by negating the equality operator. | 177 * Standard inequality operator defined by negating the equality operator. |
178 */ | 178 */ |
179 inline bool operator!=( const Record & x ) const | 179 inline bool operator!=( const Record & x ) const |
180 { | 180 { |
181 return ! operator==( x ) ; | 181 return ! operator==( x ) ; |
182 } | 182 } |
183 | 183 |
184 /** | 184 /** |
185 * Assign a string to a record, (regular) character pointer. | 185 * Assign a string to a record, (regular) character pointer. |
186 * | 186 * |
187 * \param[in] field_index | 187 * \param[in] fieldIndex |
188 * Index into the record as a vector of fields | 188 * Index into the record as a vector of fields |
189 * \param[in] value | 189 * \param[in] value |
190 * String to write into the field | 190 * String to write into the field |
191 */ | 191 */ |
192 void assign_string( unsigned int field_index, const char *value ) ; | 192 void AssignString( unsigned int fieldIndex, const char *value ) ; |
193 | 193 |
194 /** | 194 /** |
195 * Assign a string to a record, regular string version. | 195 * Assign a string to a record, regular string version. |
196 * | 196 * |
197 * \param[in] field_index | 197 * \param[in] fieldIndex |
198 * Index into the record as a vector of fields | 198 * Index into the record as a vector of fields |
199 * \param[in] value | 199 * \param[in] value |
200 * String to write into the field | 200 * String to write into the field |
201 */ | 201 */ |
202 void assign_string( unsigned int field_index, const std::string value ) | 202 void AssignString(unsigned int fieldIndex, const std::string value) |
203 { | 203 { |
204 assign_string( field_index, value.c_str() ); | 204 AssignString(fieldIndex, value.c_str()); |
205 } | 205 } |
206 | 206 |
207 /** | 207 /** |
208 * Assign a string to a record, wide character pointer version. | 208 * Assign a string to a record, wide character pointer version. |
209 * | 209 * |
210 * \param[in] field_index | 210 * \param[in] fieldIndex |
211 * Index into the record as a vector of fields | 211 * Index into the record as a vector of fields |
212 * \param[in] value | 212 * \param[in] value |
213 * String to write into the field | 213 * String to write into the field |
214 */ | 214 */ |
215 void assign_string( unsigned int field_index, const wchar_t *value ) ; | 215 void AssignString(unsigned int fieldIndex, const wchar_t *value) ; |
216 | 216 |
217 /** | 217 /** |
218 * Assign a string to a record, wide string version. | 218 * Assign a string to a record, wide string version. |
219 * | 219 * |
220 * \param[in] field_index | 220 * \param[in] fieldIndex |
221 * Index into the record as a vector of fields | 221 * Index into the record as a vector of fields |
222 * \param[in] value | 222 * \param[in] value |
223 * String to write into the field | 223 * String to write into the field |
224 */ | 224 */ |
225 void assign_string( unsigned int field_index, const std::wstring value ) | 225 void AssignString( unsigned int fieldIndex, const std::wstring value) |
226 { | 226 { |
227 assign_string( field_index, value.c_str() ); | 227 AssignString(fieldIndex, value.c_str()); |
228 } | 228 } |
229 | 229 |
230 /** | 230 /** |
231 * Retrieve a wide string value from a record | 231 * Retrieve a wide string value from a record |
232 */ | 232 */ |
233 std::wstring value_string( unsigned int field_index ) ; | 233 std::wstring ValueString( unsigned int fieldIndex) ; |
234 | 234 |
235 /** | 235 /** |
236 * The number of fields in the record. | 236 * The number of fields in the record. |
237 */ | 237 */ |
238 size_t n_fields() const ; | 238 size_t NumberOfFields() const ; |
239 | 239 |
240 /** | 240 /** |
241 * Handle accessor. | 241 * Handle accessor. |
242 */ | 242 */ |
243 MSIHANDLE handle() { return _handle ; } | 243 MSIHANDLE Handle() { return handle ; } |
244 }; | 244 }; |
245 | 245 |
246 #endif | 246 #endif |
OLD | NEW |