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
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef WINSTL_INCL_H_WINSTL
00070 # include "winstl.h"
00071 #endif
00072
00073 #if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00074 _MSC_VER < 1200
00075 # error winstl_file_path_buffer.h is not compatible with Visual C++ 5.0 or earlier
00076 #endif
00077
00078 #ifndef WINSTL_INCL_H_WINSTL_FILESYSTEM_TRAITS
00079 # include "winstl_filesystem_traits.h"
00080 #endif
00081 #ifndef STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00082 # include "stlsoft_string_access.h"
00083 #endif
00084 #ifndef WINSTL_INCL_H_WINSTL_STRING_ACCESS
00085 # include "winstl_string_access.h"
00086 #endif
00087 #ifndef WINSTL_INCL_H_WINSTL_FILE_PATH_BUFFER
00088 # include "winstl_file_path_buffer.h"
00089 #endif
00090 #ifndef STLSOFT_INCL_H_STLSOFT_OPERATOR_BOOL
00091 # include "stlsoft_operator_bool.h"
00092 #endif
00093
00094
00095
00096
00097
00098 #ifndef _WINSTL_NO_NAMESPACE
00099 # if defined(_STLSOFT_NO_NAMESPACE) || \
00100 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00101
00102 namespace winstl
00103 {
00104 # else
00105
00106
00107 namespace stlsoft
00108 {
00109
00110 namespace winstl_project
00111 {
00112
00113 # endif
00114 #endif
00115
00116 #if !defined(__STLSOFT_COMPILER_IS_MWERKS)
00117 stlsoft_ns_using(c_str_ptr)
00118 #endif
00119
00120
00121
00124
00128
00133
00134
00135
00136
00137
00138
00139
00140
00149
00150 template< ss_typename_param_k C
00151 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00152 , ss_typename_param_k T = filesystem_traits<C>
00153 #else
00154 , ss_typename_param_k T
00155 #endif
00156 >
00157 class basic_current_directory_scope
00158 {
00159 public:
00160 typedef C char_type;
00161 typedef T traits_type;
00162 typedef basic_current_directory_scope<C, T> class_type;
00163 typedef ws_size_t size_type;
00164
00165
00166 public:
00170 ss_explicit_k basic_current_directory_scope(char_type const *dir);
00171 #if defined(__STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
00175 template <ss_typename_param_k S>
00176 ss_explicit_k basic_current_directory_scope(S const &dir)
00177 {
00178 init_(stlsoft_ns_qual(c_str_ptr)(dir));
00179 }
00180 #endif
00181
00182 ~basic_current_directory_scope() winstl_throw_0();
00183
00184
00185 public:
00187 char_type const *get_previous() const;
00188
00189
00190 public:
00192 operator char_type const *() const;
00193
00196 private:
00197 STLSOFT_DEFINE_OPERATOR_BOOL_TYPES_T(class_type, operator_bool_generator_type, operator_bool_type);
00198 public:
00203 operator operator_bool_type() const
00204 {
00205 return operator_bool_generator_type::translate('\0' != m_previous[0]);
00206 }
00207
00209
00210
00211 private:
00212 void init_(char_type const *dir);
00213
00214
00215 private:
00216 basic_file_path_buffer<char_type> m_previous;
00217
00218
00219 private:
00220 basic_current_directory_scope();
00221 basic_current_directory_scope(class_type const &);
00222 class_type const &operator =(class_type const &);
00223 };
00224
00225
00226
00227
00228
00230 typedef basic_current_directory_scope<ws_char_a_t, filesystem_traits<ws_char_a_t> > current_directory_scope_a;
00232 typedef basic_current_directory_scope<ws_char_w_t, filesystem_traits<ws_char_w_t> > current_directory_scope_w;
00234 typedef basic_current_directory_scope<TCHAR, filesystem_traits<TCHAR> > current_directory_scope;
00235
00236
00237
00238
00239
00240 template< ss_typename_param_k C
00241 , ss_typename_param_k T
00242 >
00243 inline C const *c_str_ptr_null(basic_current_directory_scope<C, T> const &b)
00244 {
00245 return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
00246 }
00247
00248 template< ss_typename_param_k C
00249 , ss_typename_param_k T
00250 >
00251 inline C const *c_str_ptr(basic_current_directory_scope<C, T> const &b)
00252 {
00253 return stlsoft_ns_qual(c_str_ptr)(b.c_str());
00254 }
00255
00256 template< ss_typename_param_k C
00257 , ss_typename_param_k T
00258 >
00259 inline ws_size_t c_str_len(basic_current_directory_scope<C, T> const &b)
00260 {
00261 return stlsoft_ns_qual(c_str_len)(b.c_str());
00262 }
00263
00264 template< ss_typename_param_k C
00265 , ss_typename_param_k T
00266 >
00267 inline ws_size_t c_str_size(basic_current_directory_scope<C, T> const &b)
00268 {
00269 return stlsoft_ns_qual(c_str_size)(b.c_str());
00270 }
00271
00272 template< ss_typename_param_k S
00273 , ss_typename_param_k C
00274 , ss_typename_param_k T
00275 >
00276 inline S &operator <<(S & s, basic_current_directory_scope<C, T> const &b)
00277 {
00278 s << b.c_str();
00279
00280 return s;
00281 }
00282
00284
00285
00286 #ifdef STLSOFT_UNITTEST
00287
00288 namespace unittest
00289 {
00290 ss_bool_t test_winstl_current_directory_scope(unittest_reporter *r)
00291 {
00292 using stlsoft::unittest::unittest_initialiser;
00293
00294 ss_bool_t bSuccess = true;
00295
00296 unittest_initialiser init(r, "WinSTL", "current_directory_scope", __FILE__);
00297
00298 typedef basic_current_directory_scope<char> current_directory_scope;
00299
00300 {
00301 char szCwd[1 + _MAX_PATH];
00302 char szRoot[1 + _MAX_PATH];
00303 char *lpFilePart;
00304
00305 ::GetCurrentDirectoryA(stlsoft_num_elements(szCwd), szCwd);
00306 ::GetFullPathNameA("\\", stlsoft_num_elements(szRoot), szRoot, &lpFilePart);
00307
00308 current_directory_scope cds(szRoot);
00309
00310 if(0 != strcmp(szCwd, cds.get_previous()))
00311 {
00312 r->report("current_directory_scope failed ", __LINE__);
00313 bSuccess = false;
00314 }
00315
00316 {
00317 current_directory_scope cds2(szCwd);
00318
00319 if(0 != strcmp(szRoot, cds2.get_previous()))
00320 {
00321 r->report("current_directory_scope failed ", __LINE__);
00322 bSuccess = false;
00323 }
00324 }
00325 }
00326
00327 return bSuccess;
00328 }
00329
00330 unittest_registrar unittest_winstl_current_directory_scope(test_winstl_current_directory_scope);
00331
00332 }
00333
00334 #endif
00335
00336
00337
00338
00339
00340 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00341
00342 template< ss_typename_param_k C
00343 , ss_typename_param_k T
00344 >
00345 inline void basic_current_directory_scope<C, T>::init_(ss_typename_type_k basic_current_directory_scope<C, T>::char_type const *dir)
00346 {
00347 if( 0 == traits_type::get_current_directory(m_previous.size(), &m_previous[0]) ||
00348 !traits_type::set_current_directory(dir))
00349 {
00350 m_previous[0] = '\0';
00351 }
00352 }
00353
00354 template< ss_typename_param_k C
00355 , ss_typename_param_k T
00356 >
00357 inline basic_current_directory_scope<C, T>::basic_current_directory_scope(ss_typename_type_k basic_current_directory_scope<C, T>::char_type const *dir)
00358 {
00359 init_(stlsoft_ns_qual(c_str_ptr)(dir));
00360 }
00361
00362 template< ss_typename_param_k C
00363 , ss_typename_param_k T
00364 >
00365 inline basic_current_directory_scope<C, T>::~basic_current_directory_scope() winstl_throw_0()
00366 {
00367 if('\0' != m_previous[0])
00368 {
00369 traits_type::set_current_directory(&m_previous[0]);
00370 }
00371 }
00372
00373 template< ss_typename_param_k C
00374 , ss_typename_param_k T
00375 >
00376 inline ss_typename_type_k basic_current_directory_scope<C, T>::char_type const *basic_current_directory_scope<C, T>::get_previous() const
00377 {
00378 return stlsoft_ns_qual(c_str_ptr)(m_previous);
00379 }
00380
00381 template< ss_typename_param_k C
00382 , ss_typename_param_k T
00383 >
00384 #if defined(__STLSOFT_COMPILER_IS_GCC)
00385 inline basic_current_directory_scope<C, T>::operator C const *() const
00386 #else
00387 inline basic_current_directory_scope<C, T>::operator ss_typename_type_k basic_current_directory_scope<C, T>::char_type const *() const
00388 #endif
00389 {
00390 return get_previous();
00391 }
00392
00393 #endif
00394
00395
00396
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 #endif
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 #ifndef _WINSTL_NO_NAMESPACE
00420 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00421 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00422 namespace stlsoft
00423 {
00424 # else
00425
00426 # endif
00427
00428 using ::winstl::c_str_ptr_null;
00429
00430 using ::winstl::c_str_ptr;
00431
00432 using ::winstl::c_str_len;
00433
00434 using ::winstl::c_str_size;
00435
00436 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00437 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00438 }
00439 # else
00440
00441 # endif
00442 #endif
00443
00444
00445
00446
00447
00448