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
00048 #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE
00049 #define WINSTL_INCL_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE_MAJOR 5
00053 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE_MINOR 2
00054 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE_REVISION 4
00055 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE_EDIT 122
00056 #endif
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00073 # include <winstl/winstl.h>
00074 #endif
00075
00076 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00077 _MSC_VER < 1200
00078 # error winstl/filesystem/current_directory_scope.hpp is not compatible with Visual C++ 5.0 or earlier
00079 #endif
00080
00081 #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
00082 # include <winstl/filesystem/filesystem_traits.hpp>
00083 #endif
00084 #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER
00085 # include <winstl/filesystem/file_path_buffer.hpp>
00086 #endif
00087 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00088 # include <stlsoft/shims/access/string.hpp>
00089 #endif
00090 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00091 # ifndef WINSTL_INCL_WINSTL_ERROR_HPP_WINDOWS_EXCEPTIONS
00092 # include <winstl/error/exceptions.hpp>
00093 # endif
00094 #endif
00095 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_OPERATOR_BOOL
00096 # include <stlsoft/util/operator_bool.hpp>
00097 #endif
00098
00099
00100
00101
00102
00103 #ifndef _WINSTL_NO_NAMESPACE
00104 # if defined(_STLSOFT_NO_NAMESPACE) || \
00105 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00106
00107 namespace winstl
00108 {
00109 # else
00110
00111
00112 namespace stlsoft
00113 {
00114
00115 namespace winstl_project
00116 {
00117
00118 # endif
00119 #endif
00120
00121
00122
00123
00124
00125
00126
00127
00140 template< ss_typename_param_k C
00141 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00142 , ss_typename_param_k T = filesystem_traits<C>
00143 #else
00144 , ss_typename_param_k T
00145 #endif
00146 >
00147 class basic_current_directory_scope
00148 {
00149 public:
00150 typedef C char_type;
00151 typedef T traits_type;
00153 typedef basic_current_directory_scope<C, T> class_type;
00154 typedef ws_size_t size_type;
00155
00156
00157 public:
00161 ss_explicit_k basic_current_directory_scope(char_type const* dir);
00162 #if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
00166 template <ss_typename_param_k S>
00167 ss_explicit_k basic_current_directory_scope(S const& dir)
00168 {
00169 init_(stlsoft_ns_qual(c_str_ptr)(dir));
00170 }
00171 #endif
00173 ~basic_current_directory_scope() stlsoft_throw_0();
00174
00175
00176 public:
00178 char_type const* get_previous() const;
00179
00180
00181 public:
00183 operator char_type const* () const;
00184
00187 private:
00188 STLSOFT_DEFINE_OPERATOR_BOOL_TYPES_T(class_type, operator_bool_generator_type, operator_bool_type);
00189 public:
00194 operator operator_bool_type() const
00195 {
00196 return operator_bool_generator_type::translate('\0' != m_previous[0]);
00197 }
00198
00200
00201
00202 private:
00203 void init_(char_type const* dir);
00204
00205
00206 private:
00207 basic_file_path_buffer<char_type> m_previous;
00208
00209
00210 private:
00211 basic_current_directory_scope();
00212 basic_current_directory_scope(class_type const&);
00213 class_type const& operator =(class_type const&);
00214 };
00215
00216
00217
00218
00219
00224 typedef basic_current_directory_scope<ws_char_a_t, filesystem_traits<ws_char_a_t> > current_directory_scope_a;
00229 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.get_previous());
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 b.get_previous();
00254 }
00255
00256 template< ss_typename_param_k C
00257 , ss_typename_param_k T
00258 >
00259 inline C const* c_str_data(basic_current_directory_scope<C, T> const& b)
00260 {
00261 return b.get_previous();
00262 }
00263
00264 template< ss_typename_param_k C
00265 , ss_typename_param_k T
00266 >
00267 inline ws_size_t c_str_len(basic_current_directory_scope<C, T> const& b)
00268 {
00269 return stlsoft_ns_qual(c_str_len)(b.get_previous());
00270 }
00271
00272
00273
00274 template< ss_typename_param_k S
00275 , ss_typename_param_k C
00276 , ss_typename_param_k T
00277 >
00278 inline S& operator <<(S& s, basic_current_directory_scope<C, T> const& b)
00279 {
00280 s << b.get_previous();
00281
00282 return s;
00283 }
00284
00286
00287
00288 #ifdef STLSOFT_UNITTEST
00289 # include "./unittest/current_directory_scope_unittest_.h"
00290 #endif
00291
00292
00293
00294
00295
00296 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00297
00298 template< ss_typename_param_k C
00299 , ss_typename_param_k T
00300 >
00301 inline void basic_current_directory_scope<C, T>::init_(ss_typename_type_k basic_current_directory_scope<C, T>::char_type const* dir)
00302 {
00303 if(0 == traits_type::get_current_directory(m_previous.size(), &m_previous[0]))
00304 {
00305 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00306 STLSOFT_THROW_X(windows_exception("could not determine current directory", ::GetLastError()));
00307 #else
00308 m_previous[0] = '\0';
00309 #endif
00310 }
00311 else if(!traits_type::set_current_directory(dir))
00312 {
00313 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00314 STLSOFT_THROW_X(windows_exception("could not change current directory", ::GetLastError()));
00315 #else
00316 m_previous[0] = '\0';
00317 #endif
00318 }
00319 }
00320
00321 template< ss_typename_param_k C
00322 , ss_typename_param_k T
00323 >
00324 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)
00325 {
00326 init_(dir);
00327 }
00328
00329 template< ss_typename_param_k C
00330 , ss_typename_param_k T
00331 >
00332 inline basic_current_directory_scope<C, T>::~basic_current_directory_scope() stlsoft_throw_0()
00333 {
00334 if('\0' != m_previous[0])
00335 {
00336 traits_type::set_current_directory(&m_previous[0]);
00337 }
00338 }
00339
00340 template< ss_typename_param_k C
00341 , ss_typename_param_k T
00342 >
00343 inline ss_typename_type_ret_k basic_current_directory_scope<C, T>::char_type const* basic_current_directory_scope<C, T>::get_previous() const
00344 {
00345 return stlsoft_ns_qual(c_str_ptr)(m_previous);
00346 }
00347
00348 template< ss_typename_param_k C
00349 , ss_typename_param_k T
00350 >
00351 #if defined(STLSOFT_COMPILER_IS_GCC)
00352 inline basic_current_directory_scope<C, T>::operator C const* () const
00353 #else
00354 inline basic_current_directory_scope<C, T>::operator ss_typename_type_k basic_current_directory_scope<C, T>::char_type const* () const
00355 #endif
00356 {
00357 return get_previous();
00358 }
00359
00360 #endif
00361
00362
00363
00364 #ifndef _WINSTL_NO_NAMESPACE
00365 # if defined(_STLSOFT_NO_NAMESPACE) || \
00366 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00367 }
00368 # else
00369 }
00370 }
00371 # endif
00372 #endif
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382 #ifndef _WINSTL_NO_NAMESPACE
00383 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00384 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00385 namespace stlsoft
00386 {
00387 # else
00388
00389 # endif
00390
00391 using ::winstl::c_str_ptr_null;
00392
00393 using ::winstl::c_str_ptr;
00394
00395 using ::winstl::c_str_data;
00396
00397 using ::winstl::c_str_len;
00398
00399 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00400 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00401 }
00402 # else
00403
00404 # endif
00405 #endif
00406
00407
00408
00409 #endif
00410
00411