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

Side by Side Diff: installer/src/installer-lib/handle.h

Issue 5665210325008384: Combine snapshot classes into a template class (Closed)
Patch Set: Created April 3, 2014, 4:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * \file handle.h The "install session" is the context for all custom installati on behavior. 2 * \file handle.h The "install session" is the context for all custom installati on behavior.
3 */ 3 */
4 4
5 #ifndef HANDLE_H 5 #ifndef HANDLE_H
6 #define HANDLE_H 6 #define HANDLE_H
7 7
8 #include "windows.h" 8 #include "windows.h"
9 #include "msi.h" 9 #include "msi.h"
10 10
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 public: 135 public:
136 /** 136 /**
137 * Conversion operator to underlying handle type. 137 * Conversion operator to underlying handle type.
138 */ 138 */
139 operator T() 139 operator T()
140 { 140 {
141 return _handle ; 141 return _handle ;
142 } 142 }
143 143
144 /**
145 * Error thrown when initialize or assigning a null handle against policy.
146 *
147 * Note that this error is a logic_error, not a runtime error.
148 * If it's against policy for a handle to be null, it's an error for the calle r to try to make it null.
149 * Policy enforcment here is not a substitute for good error handling by the c aller.
150 * In many cases, the caller ought to be throwing windows_api_error.
151 */
144 struct null_handle_error 152 struct null_handle_error
145 : public std::runtime_error 153 : public std::logic_error
146 { 154 {
147 null_handle_error() 155 null_handle_error()
148 : std::runtime_error( "May not initialize with null handle" ) 156 : std::logic_error( "May not initialize with null handle" )
149 {} 157 {}
150 } ; 158 } ;
151 } ; 159 } ;
152 160
153 /* 161 /*
154 * Handle class 162 * Handle class
155 */ 163 */
156 template< 164 template<
157 class T, 165 class T,
158 template <class> class Null_Policy, 166 template <class> class Null_Policy,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 * The check for a non-zero handle compiles out conditionally based on Null_Po licy. 255 * The check for a non-zero handle compiles out conditionally based on Null_Po licy.
248 * The specific function used to close the handle is given by the Destruction_ Policy. 256 * The specific function used to close the handle is given by the Destruction_ Policy.
249 */ 257 */
250 ~handle() 258 ~handle()
251 { 259 {
252 if ( Null_Policy< T >::prohibited_always() || ( _handle != 0 ) ) { 260 if ( Null_Policy< T >::prohibited_always() || ( _handle != 0 ) ) {
253 Destruction_Policy< T >::close( _handle ) ; 261 Destruction_Policy< T >::close( _handle ) ;
254 } 262 }
255 } 263 }
256 264
265 /**
266 * Expose the underlying handle type.
267 */
268 typedef T handle_type ;
257 } ; 269 } ;
258 270
259 //------------------------------------------------------- 271 //-------------------------------------------------------
260 // Common instantiations of handle 272 // Common instantiations of handle
261 //------------------------------------------------------- 273 //-------------------------------------------------------
262 typedef handle< HANDLE, Disallow_Null, Windows_Generic_Destruction > Windows_Han dle ; 274 typedef handle< HANDLE, Disallow_Null, Windows_Generic_Destruction > Windows_Han dle ;
263 275
264 #endif 276 #endif
OLDNEW
« no previous file with comments | « installer/src/custom-action/close_application.cpp ('k') | installer/src/installer-lib/process.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld