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
00041
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifndef WINSTL_INCL_H_WINSTL
00061 # include "winstl.h"
00062 #endif
00063 #ifndef WINSTL_INCL_H_WINSTL_FILESYSTEM_TRAITS
00064 # include "winstl_filesystem_traits.h"
00065 #endif
00066 #ifndef WINSTL_INCL_H_WINSTL_STRING_ACCESS
00067 # include "winstl_string_access.h"
00068 #endif
00069
00070
00071
00072
00073
00074 #ifndef _WINSTL_NO_NAMESPACE
00075 # if defined(_STLSOFT_NO_NAMESPACE) || \
00076 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00077
00078 namespace winstl
00079 {
00080 # else
00081
00082
00083 namespace stlsoft
00084 {
00085
00086 namespace winstl_project
00087 {
00088
00089 # endif
00090 #endif
00091
00092
00093
00096
00100
00105
00106
00107
00108
00109
00110
00111
00112
00117 template< ss_typename_param_k C
00118 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00119 , ss_typename_param_k T = filesystem_traits<C>
00120 #else
00121 , ss_typename_param_k T
00122 #endif
00123 >
00124 class basic_windows_directory
00125 {
00126 public:
00128 typedef C char_type;
00130 typedef T traits_type;
00132 typedef basic_windows_directory<C, T> class_type;
00134 typedef ws_size_t size_type;
00135
00136
00137 public:
00139 static size_type get_path(ws_char_a_t *buffer, size_type cchBuffer);
00141 static size_type get_path(ws_char_w_t *buffer, size_type cchBuffer);
00142
00143
00144 public:
00146 char_type const *get_path() const;
00148 char_type const *c_str() const;
00150 size_type length() const;
00151
00152
00153 public:
00155 operator char_type const *() const
00156 {
00157 return get_path();
00158 }
00159
00161 #ifdef STLSOFT_UNITTEST
00162 public:
00163 #else
00164 private:
00165 #endif
00166 ws_bool_t is_valid_() const;
00167
00168
00169 private:
00170 struct Information
00171 {
00172 char_type m_dir[_MAX_PATH];
00173 size_type m_len;
00174
00175 Information()
00176 : m_len(get_path(m_dir, winstl_num_elements(m_dir)))
00177 {}
00178 };
00179
00180 #if !defined(__STLSOFT_COMPILER_IS_DMC)
00181 static Information const &get_information_()
00182 {
00183 static Information s_info;
00184
00185 return s_info;
00186 }
00187 #else
00188
00189
00190
00191 Information m_information;
00192 Information const &get_information_() const
00193 {
00194 return m_information;
00195 }
00196 #endif
00197 };
00198
00199
00200
00201
00202
00204 typedef basic_windows_directory<ws_char_a_t, filesystem_traits<ws_char_a_t> > windows_directory_a;
00206 typedef basic_windows_directory<ws_char_w_t, filesystem_traits<ws_char_w_t> > windows_directory_w;
00208 typedef basic_windows_directory<TCHAR, filesystem_traits<TCHAR> > windows_directory;
00209
00210
00211
00212
00213
00214 #ifdef STLSOFT_UNITTEST
00215
00216 namespace unittest
00217 {
00218 ss_bool_t test_winstl_windows_directory(unittest_reporter *r)
00219 {
00220 using stlsoft::unittest::unittest_initialiser;
00221
00222 ss_bool_t bSuccess = true;
00223
00224 unittest_initialiser init(r, "WinSTL", "windows_directory", __FILE__);
00225
00226 windows_directory_a win_dir_a_1;
00227 windows_directory_a win_dir_a_2;
00228 windows_directory_w win_dir_w_1;
00229 windows_directory_w win_dir_w_2;
00230 WCHAR wszBuffer[_MAX_PATH];
00231
00232 if( !win_dir_a_1.is_valid_() ||
00233 !win_dir_a_2.is_valid_() ||
00234 !win_dir_w_1.is_valid_() ||
00235 !win_dir_w_2.is_valid_())
00236 {
00237 r->report("Class invariant fails for one or more instances", __LINE__);
00238 bSuccess = false;
00239 }
00240
00241 if(0 != lstrcmpiA(win_dir_a_1, win_dir_a_2))
00242 {
00243 r->report("Two (ANSI) instances do not report same Windows directory", __LINE__);
00244 bSuccess = false;
00245 }
00246
00247 if(0 != lstrcmpiW(win_dir_w_1, win_dir_w_2))
00248 {
00249 r->report("Two (Unicode) instances do not report same Windows directory", __LINE__);
00250 bSuccess = false;
00251 }
00252
00253 if( 0 == ::MultiByteToWideChar(0, 0, win_dir_a_1, -1, wszBuffer, stlsoft_num_elements(wszBuffer)) ||
00254 0 != lstrcmpiW(wszBuffer, win_dir_w_1))
00255 {
00256 r->report("ANSI and Unicode instances do not report same Windows directory", __LINE__);
00257 bSuccess = false;
00258 }
00259
00260 return bSuccess;
00261 }
00262
00263 unittest_registrar unittest_winstl_windows_directory(test_winstl_windows_directory);
00264
00265 }
00266
00267 #endif
00268
00269
00270
00271
00272
00273 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00274
00275 template< ss_typename_param_k C
00276 , ss_typename_param_k T
00277 >
00278 inline ss_typename_type_k basic_windows_directory<C, T>::size_type basic_windows_directory<C, T>::get_path(ws_char_a_t *buffer, ss_typename_type_k basic_windows_directory<C, T>::size_type cchBuffer)
00279 {
00280 return static_cast<size_type>(::GetWindowsDirectoryA(buffer, cchBuffer));
00281 }
00282
00283 template< ss_typename_param_k C
00284 , ss_typename_param_k T
00285 >
00286 inline ss_typename_type_k basic_windows_directory<C, T>::size_type basic_windows_directory<C, T>::get_path(ws_char_w_t *buffer, ss_typename_type_k basic_windows_directory<C, T>::size_type cchBuffer)
00287 {
00288 return static_cast<size_type>(::GetWindowsDirectoryW(buffer, cchBuffer));
00289 }
00290
00291 template< ss_typename_param_k C
00292 , ss_typename_param_k T
00293 >
00294 inline ss_typename_type_k basic_windows_directory<C, T>::char_type const *basic_windows_directory<C, T>::get_path() const
00295 {
00296 #if defined(__STLSOFT_COMPILER_IS_DMC)
00297 return get_information_().m_dir;
00298 #else
00299 static char_type const *s_sz = get_information_().m_dir;
00300
00301 return s_sz;
00302 #endif
00303 }
00304
00305 template< ss_typename_param_k C
00306 , ss_typename_param_k T
00307 >
00308 inline ss_typename_type_k basic_windows_directory<C, T>::char_type const *basic_windows_directory<C, T>::c_str() const
00309 {
00310 return get_path();
00311 }
00312
00313 template< ss_typename_param_k C
00314 , ss_typename_param_k T
00315 >
00316 inline ss_typename_type_k basic_windows_directory<C, T>::size_type basic_windows_directory<C, T>::length() const
00317 {
00318 return get_information_().m_len;
00319 }
00320
00321 template< ss_typename_param_k C
00322 , ss_typename_param_k T
00323 >
00324 inline ws_bool_t basic_windows_directory<C, T>::is_valid_() const
00325 {
00326 ws_bool_t bValid = true;
00327
00328 if(traits_type::str_len(*this) != length())
00329 {
00330 return false;
00331 }
00332
00333 if(0 == length())
00334 {
00335 return false;
00336 }
00337
00338 return bValid;
00339 }
00340
00341 #endif
00342
00343
00344
00346
00347
00348
00349
00350
00352
00355
00359
00364
00366 template< ss_typename_param_k C
00367 , ss_typename_param_k T
00368 >
00369 inline C const *c_str_ptr_null(basic_windows_directory<C, T> const &sd)
00370 {
00371 return sd;
00372 }
00373
00375 template< ss_typename_param_k C
00376 , ss_typename_param_k T
00377 >
00378 inline C const *c_str_ptr(basic_windows_directory<C, T> const &sd)
00379 {
00380 return sd;
00381 }
00382
00384 template< ss_typename_param_k C
00385 , ss_typename_param_k T
00386 >
00387 inline ws_size_t c_str_len(basic_windows_directory<C, T> const &sd)
00388 {
00389 return sd.length();
00390 }
00391
00393 template< ss_typename_param_k C
00394 , ss_typename_param_k T
00395 >
00396 inline ws_size_t c_str_size(basic_windows_directory<C, T> const &sd)
00397 {
00398 return sd.length() * sizeof(C);
00399 }
00400
00401
00402
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 #endif
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 #ifndef _WINSTL_NO_NAMESPACE
00426 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00427 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00428 namespace stlsoft
00429 {
00430 # else
00431
00432 # endif
00433
00434 using ::winstl::c_str_ptr_null;
00435
00436 using ::winstl::c_str_ptr;
00437
00438 using ::winstl::c_str_len;
00439
00440 using ::winstl::c_str_size;
00441
00442 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00443 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00444 }
00445 # else
00446
00447 # endif
00448 #endif
00449
00450
00451
00452
00453
00454