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 UNIXSTL_INCL_H_WINSTL
00060 # include "unixstl.h"
00061 #endif
00062 #ifndef UNIXSTL_INCL_H_UNIXSTL_FILESYSTEM_TRAITS
00063 # include "unixstl_filesystem_traits.h"
00064 #endif
00065 #ifndef UNIXSTL_INCL_H_UNIXSTL_FILE_PATH_BUFFER
00066 # include "unixstl_file_path_buffer.h"
00067 #endif
00068 #ifndef STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00069 # include "stlsoft_string_access.h"
00070 #endif
00071 #ifndef UNIXSTL_INCL_H_UNIXSTL_STRING_ACCESS
00072 # include "unixstl_string_access.h"
00073 #endif
00074 #ifndef STLSOFT_INCL_H_STLSOFT_OPERATOR_BOOL
00075 # include "stlsoft_operator_bool.h"
00076 #endif
00077
00078
00079
00080
00081
00082 #ifndef _UNIXSTL_NO_NAMESPACE
00083 # if defined(_STLSOFT_NO_NAMESPACE) || \
00084 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00085
00086 namespace unixstl
00087 {
00088 # else
00089
00090
00091 namespace stlsoft
00092 {
00093
00094 namespace unixstl_project
00095 {
00096
00097 # endif
00098 #endif
00099
00100 #if !defined(__STLSOFT_COMPILER_IS_GCC) && \
00101 __GNUC__ < 3
00102 stlsoft_ns_using(c_str_ptr)
00103 #endif
00104
00105
00106
00109
00113
00118
00119
00120
00121
00122
00123
00124
00125
00134
00135 template< ss_typename_param_k C
00136 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00137 , ss_typename_param_k T = filesystem_traits<C>
00138 #else
00139 , ss_typename_param_k T
00140 #endif
00141 >
00142 class basic_current_directory_scope
00143 {
00144 public:
00145 typedef C char_type;
00146 private:
00147 typedef T traits_type;
00148 typedef basic_current_directory_scope<C, T> class_type;
00149
00150
00151 public:
00155 ss_explicit_k basic_current_directory_scope(char_type const *dir);
00156 #if defined(__STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
00160 template <ss_typename_param_k S>
00161 ss_explicit_k basic_current_directory_scope(S const &dir)
00162 {
00163 init_(c_str_ptr(dir));
00164 }
00165 #endif
00166
00167 ~basic_current_directory_scope() unixstl_throw_0();
00168
00169
00170 public:
00172 char_type const *get_previous() const;
00173
00174
00175 public:
00177 operator char_type const *() const;
00178
00181 private:
00182 STLSOFT_DEFINE_OPERATOR_BOOL_TYPES_T(class_type, operator_bool_generator_type, operator_bool_type);
00183 public:
00188 operator operator_bool_type() const
00189 {
00190 return operator_bool_generator_type::translate('\0' != m_previous[0]);
00191 }
00192
00194
00195
00196 private:
00197 void init_(char_type const *dir);
00198
00199
00200 private:
00201 basic_file_path_buffer<char_type> m_previous;
00202
00203
00204 private:
00205 basic_current_directory_scope();
00206 basic_current_directory_scope(class_type const &);
00207 class_type const &operator =(class_type const &);
00208 };
00209
00210
00211
00212
00213
00215 typedef basic_current_directory_scope<us_char_a_t, filesystem_traits<us_char_a_t> > current_directory_scope_a;
00217 typedef basic_current_directory_scope<us_char_w_t, filesystem_traits<us_char_w_t> > current_directory_scope_w;
00218
00219
00220
00221
00222
00223 template< ss_typename_param_k C
00224 , ss_typename_param_k T
00225 >
00226 inline C const *c_str_ptr_null(basic_current_directory_scope<C, T> const &b)
00227 {
00228 return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
00229 }
00230
00231 template< ss_typename_param_k C
00232 , ss_typename_param_k T
00233 >
00234 inline C const *c_str_ptr(basic_current_directory_scope<C, T> const &b)
00235 {
00236 return stlsoft_ns_qual(c_str_ptr)(b.c_str());
00237 }
00238
00239 template< ss_typename_param_k C
00240 , ss_typename_param_k T
00241 >
00242 inline us_size_t c_str_len(basic_current_directory_scope<C, T> const &b)
00243 {
00244 return stlsoft_ns_qual(c_str_len)(b.c_str());
00245 }
00246
00247 template< ss_typename_param_k C
00248 , ss_typename_param_k T
00249 >
00250 inline us_size_t c_str_size(basic_current_directory_scope<C, T> const &b)
00251 {
00252 return stlsoft_ns_qual(c_str_size)(b.c_str());
00253 }
00254
00255 template< ss_typename_param_k S
00256 , ss_typename_param_k C
00257 , ss_typename_param_k T
00258 >
00259 inline S &operator <<(S & s, basic_current_directory_scope<C, T> const &b)
00260 {
00261 s << b.c_str();
00262
00263 return s;
00264 }
00265
00267
00268
00269 #ifdef STLSOFT_UNITTEST
00270
00271 namespace unittest
00272 {
00273 ss_bool_t test_unixstl_current_directory_scope(unittest_reporter *r)
00274 {
00275 using stlsoft::unittest::unittest_initialiser;
00276
00277 ss_bool_t bSuccess = true;
00278
00279 unittest_initialiser init(r, "UNIXSTL", "current_directory_scope", __FILE__);
00280
00281 typedef basic_current_directory_scope<char> current_directory_scope;
00282
00283 {
00284 basic_file_path_buffer<char> sz;
00285
00286 getcwd(&sz[0], sz.size());
00287 #ifdef WIN32
00288 current_directory_scope cds("\\");
00289 #else
00290 current_directory_scope cds("/");
00291 #endif
00292
00293 if(0 != strcmp(sz.c_str(), cds.get_previous()))
00294 {
00295 r->report("current_directory_scope failed ", __LINE__);
00296 bSuccess = false;
00297 }
00298
00299 {
00300 current_directory_scope cds2(sz);
00301
00302 #ifdef WIN32
00303 if(0 != strcmp("\\", cds2.get_previous() + 2))
00304 #else
00305 if(0 != strcmp("/", cds2.get_previous()))
00306 #endif
00307 {
00308 r->report("current_directory_scope failed ", __LINE__);
00309 bSuccess = false;
00310 }
00311 }
00312 }
00313
00314 return bSuccess;
00315 }
00316
00317 unittest_registrar unittest_unixstl_current_directory_scope(test_unixstl_current_directory_scope);
00318
00319 }
00320
00321 #endif
00322
00323
00324
00325
00326
00327 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00328
00329 template< ss_typename_param_k C
00330 , ss_typename_param_k T
00331 >
00332 inline void basic_current_directory_scope<C, T>::init_(ss_typename_type_k basic_current_directory_scope<C, T>::char_type const *dir)
00333 {
00334 if( 0 == traits_type::get_current_directory(m_previous.size(), &m_previous[0]) ||
00335 !traits_type::set_current_directory(dir))
00336 {
00337 m_previous[0] = '\0';
00338 }
00339 }
00340
00341 template< ss_typename_param_k C
00342 , ss_typename_param_k T
00343 >
00344 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)
00345 {
00346 init_(dir);
00347 }
00348
00349 template< ss_typename_param_k C
00350 , ss_typename_param_k T
00351 >
00352 inline basic_current_directory_scope<C, T>::~basic_current_directory_scope() unixstl_throw_0()
00353 {
00354 if('\0' != m_previous[0])
00355 {
00356 traits_type::set_current_directory(&m_previous[0]);
00357 }
00358 }
00359
00360 template< ss_typename_param_k C
00361 , ss_typename_param_k T
00362 >
00363 inline ss_typename_type_k basic_current_directory_scope<C, T>::char_type const *basic_current_directory_scope<C, T>::get_previous() const
00364 {
00365 #if defined(__STLSOFT_COMPILER_IS_GCC) && \
00366 __GNUC__ < 3
00367 return m_previous.c_str();
00368 #else
00369 return stlsoft_ns_qual(c_str_ptr)(m_previous);
00370 #endif
00371 }
00372
00373 template< ss_typename_param_k C
00374 , ss_typename_param_k T
00375 >
00376 #if defined(__STLSOFT_COMPILER_IS_GCC)
00377 inline basic_current_directory_scope<C, T>::operator C const *() const
00378 #else
00379 inline basic_current_directory_scope<C, T>::operator ss_typename_type_k basic_current_directory_scope<C, T>::char_type const *() const
00380 #endif
00381 {
00382 return get_previous();
00383 }
00384
00385 #endif
00386
00387
00388
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 #endif
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 #ifndef _UNIXSTL_NO_NAMESPACE
00412 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00413 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00414 namespace stlsoft
00415 {
00416 # else
00417
00418 # endif
00419
00420 using ::unixstl::c_str_ptr_null;
00421
00422 using ::unixstl::c_str_ptr;
00423
00424 using ::unixstl::c_str_len;
00425
00426 using ::unixstl::c_str_size;
00427
00428 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00429 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00430 }
00431 # else
00432
00433 # endif
00434 #endif
00435
00436
00437
00438
00439
00440