00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #ifndef WINSTL_INCL_H_WINSTL
00060 # include "winstl.h"
00061 #endif
00062 #ifndef WINSTL_INCL_H_WINSTL_FUNCTIONS
00063 # include "winstl_functions.h"
00064 #endif
00065 #ifndef WINSTL_INCL_H_WINSTL_FILESYSTEM_TRAITS
00066 # include "winstl_filesystem_traits.h"
00067 #endif
00068 #ifndef WINSTL_INCL_H_WINSTL_STRING_ACCESS
00069 # include "winstl_string_access.h"
00070 #endif
00071
00072
00073
00074
00075
00076 #ifndef _WINSTL_NO_NAMESPACE
00077 # if defined(_STLSOFT_NO_NAMESPACE) || \
00078 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00079
00080 namespace winstl
00081 {
00082 # else
00083
00084
00085 namespace stlsoft
00086 {
00087
00088 namespace winstl_project
00089 {
00090
00091 # endif
00092 #endif
00093
00094
00095
00098
00099
00100
00101
00102
00106 template< ss_typename_param_k C
00107 , ss_typename_param_k T = filesystem_traits<C>
00108 >
00109 class basic_error_desc
00110 {
00111 public:
00113 typedef C char_type;
00115 typedef T traits_type;
00117 typedef basic_error_desc<C, T> class_type;
00118
00119
00120 public:
00125 ss_explicit_k basic_error_desc(ws_dword_t error = GetLastError(), char_type const *paths = NULL);
00126 public:
00128 ~basic_error_desc() winstl_throw_0();
00129
00130
00131 public:
00133 char_type const *get_description() const;
00134
00135
00136 public:
00138 operator char_type const *() const;
00139
00140
00141 private:
00142 char_type *m_message;
00143
00144
00145 public:
00146 basic_error_desc(class_type const &);
00147 basic_error_desc &operator =(class_type const &);
00148 };
00149
00150
00152 typedef basic_error_desc<ws_char_a_t> error_desc_a;
00154 typedef basic_error_desc<ws_char_w_t> error_desc_w;
00156 typedef basic_error_desc<TCHAR> error_desc;
00157
00158
00159
00160
00161
00162 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00163
00164 template< ss_typename_param_k C
00165 , ss_typename_param_k T
00166 >
00167 inline basic_error_desc<C, T>::basic_error_desc(ws_dword_t error , char_type const *paths )
00168 : m_message(NULL)
00169 {
00170 ws_dword_t cch = 0;
00171
00172 if(NULL != paths)
00173 {
00174 HINSTANCE hinstSource = traits_type::load_library(paths);
00175
00176 if(NULL != hinstSource)
00177 {
00178 cch = FormatMessage(error, hinstSource, &m_message);
00179
00180 traits_type::free_library(hinstSource);
00181 }
00182 }
00183
00184 if(NULL == m_message)
00185 {
00186 cch = FormatMessage(error, NULL, &m_message);
00187 }
00188
00189 if(0 == cch)
00190 {
00191 m_message = NULL;
00192 }
00193 }
00194
00195 template< ss_typename_param_k C
00196 , ss_typename_param_k T
00197 >
00198 inline basic_error_desc<C, T>::~basic_error_desc() winstl_throw_0()
00199 {
00200 if(m_message != NULL)
00201 {
00202 ::LocalFree(m_message);
00203 }
00204 }
00205
00206 template< ss_typename_param_k C
00207 , ss_typename_param_k T
00208 >
00209 inline ss_typename_type_k basic_error_desc<C, T>::char_type const *basic_error_desc<C, T>::get_description() const
00210 {
00211 return (NULL != m_message) ? m_message : "";
00212 }
00213
00214 template< ss_typename_param_k C
00215 , ss_typename_param_k T
00216 >
00217 #if defined(__STLSOFT_COMPILER_IS_GCC)
00218 inline basic_error_desc<C, T>::operator C const *() const
00219 #else
00220 inline basic_error_desc<C, T>::operator ss_typename_type_k basic_error_desc<C, T>::char_type const *() const
00221 #endif
00222 {
00223 return get_description();
00224 }
00225
00226 #endif
00227
00228
00229
00230
00231
00232 #ifndef __STLSOFT_CF_TEMPLATE_SHIMS_NOT_SUPPORTED
00233
00235 template< ss_typename_param_k C
00236 , ss_typename_param_k T
00237 >
00238 inline C const *c_str_ptr_null(basic_error_desc<C, T> const &e)
00239 {
00240 C const *p = e;
00241
00242 return ('\0' != *e) ? p : NULL;
00243 }
00244
00246 template< ss_typename_param_k C
00247 , ss_typename_param_k T
00248 >
00249 inline C const *c_str_ptr(basic_error_desc<C, T> const &e)
00250 {
00251 return e;
00252 }
00253
00255 template< ss_typename_param_k C
00256 , ss_typename_param_k T
00257 >
00258 inline C const *get_ptr(basic_error_desc<C, T> const &e)
00259 {
00260 return e;
00261 }
00262
00263 #endif
00264
00266
00267
00268 #ifdef STLSOFT_UNITTEST
00269
00270 namespace unittest
00271 {
00272 ss_bool_t test_winstl_error_desc(unittest_reporter *r)
00273 {
00274 using stlsoft::unittest::unittest_initialiser;
00275
00276 ss_bool_t bSuccess = true;
00277
00278 unittest_initialiser init(r, "WinSTL", "error_desc", __FILE__);
00279
00280 #if 0
00281 if(<<TODO>>)
00282 {
00283 r->report("<<TODO>> failed ", __LINE__);
00284 bSuccess = false;
00285 }
00286 #endif
00287
00288 return bSuccess;
00289 }
00290
00291 unittest_registrar unittest_winstl_error_desc(test_winstl_error_desc);
00292
00293 }
00294
00295 #endif
00296
00297
00298
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 #endif
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 #ifndef _WINSTL_NO_NAMESPACE
00322 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00323 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00324 namespace stlsoft
00325 {
00326 # else
00327
00328 # endif
00329
00330 using ::winstl::c_str_ptr_null;
00331
00332 using ::winstl::c_str_ptr;
00333
00334 using ::winstl::get_ptr;
00335
00336 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00337 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00338 }
00339 # else
00340
00341 # endif
00342 #endif
00343
00344
00345
00346
00347
00348