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 UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE
00049 #define UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE_MAJOR 5
00053 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE_MINOR 1
00054 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE_REVISION 4
00055 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_SCOPE_EDIT 115
00056 #endif
00057
00058
00059
00060
00061
00062 #ifndef UNIXSTL_INCL_UNIXSTL_H_UNIXSTL
00063 # include <unixstl/unixstl.h>
00064 #endif
00065 #ifndef UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
00066 # include <unixstl/filesystem/filesystem_traits.hpp>
00067 #endif
00068 #ifndef UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER
00069 # include <unixstl/filesystem/file_path_buffer.hpp>
00070 #endif
00071 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00072 # include <stlsoft/shims/access/string.hpp>
00073 #endif
00074 #ifndef UNIXSTL_INCL_UNIXSTL_SHIMS_ACCESS_HPP_STRING
00075 # include <unixstl/shims/access/string.hpp>
00076 #endif
00077 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_OPERATOR_BOOL
00078 # include <stlsoft/util/operator_bool.hpp>
00079 #endif
00080
00081
00082
00083
00084
00085 #ifndef _UNIXSTL_NO_NAMESPACE
00086 # if defined(_STLSOFT_NO_NAMESPACE) || \
00087 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00088
00089 namespace unixstl
00090 {
00091 # else
00092
00093
00094 namespace stlsoft
00095 {
00096
00097 namespace unixstl_project
00098 {
00099
00100 # endif
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109
00122 template< ss_typename_param_k C
00123 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00124 , ss_typename_param_k T = filesystem_traits<C>
00125 #else
00126 , ss_typename_param_k T
00127 #endif
00128 >
00129 class basic_current_directory_scope
00130 {
00131 public:
00132 typedef C char_type;
00133 private:
00134 typedef T traits_type;
00135 typedef basic_current_directory_scope<C, T> class_type;
00136
00137
00138 public:
00142 ss_explicit_k basic_current_directory_scope(char_type const* dir);
00143 #if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
00147 template <ss_typename_param_k S>
00148 ss_explicit_k basic_current_directory_scope(S const& dir)
00149 {
00150 init_(stlsoft_ns_qual(c_str_ptr)(dir));
00151 }
00152 #endif
00154 ~basic_current_directory_scope() stlsoft_throw_0();
00155
00156
00157 public:
00159 char_type const* get_previous() const;
00160
00161
00162 public:
00164 operator char_type const* () const;
00165
00168 private:
00169 STLSOFT_DEFINE_OPERATOR_BOOL_TYPES_T(class_type, operator_bool_generator_type, operator_bool_type);
00170 public:
00175 operator operator_bool_type() const
00176 {
00177 return operator_bool_generator_type::translate('\0' != m_previous[0]);
00178 }
00179
00181
00182
00183 private:
00184 void init_(char_type const* dir);
00185
00186
00187 private:
00188 basic_file_path_buffer<char_type> m_previous;
00189
00190
00191 private:
00192 basic_current_directory_scope();
00193 basic_current_directory_scope(class_type const&);
00194 class_type const& operator =(class_type const&);
00195 };
00196
00197
00198
00199
00200
00205 typedef basic_current_directory_scope<us_char_a_t, filesystem_traits<us_char_a_t> > current_directory_scope_a;
00210 typedef basic_current_directory_scope<us_char_w_t, filesystem_traits<us_char_w_t> > current_directory_scope_w;
00215 typedef basic_current_directory_scope<char, filesystem_traits<char> > current_directory_scope;
00216
00217
00218
00219
00220
00221 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00222
00223 template <ss_typename_param_k C>
00224 inline us_char_a_t const* c_str_ptr_null_a(unixstl_ns_qual(basic_current_directory_scope)<us_char_a_t, C> const& b)
00225 {
00226 return stlsoft_ns_qual(c_str_ptr_null_a)(b.c_str());
00227 }
00228 template <ss_typename_param_k C>
00229 inline us_char_w_t const* c_str_ptr_null_w(unixstl_ns_qual(basic_current_directory_scope)<us_char_w_t, C> const& b)
00230 {
00231 return stlsoft_ns_qual(c_str_ptr_null_w)(b.c_str());
00232 }
00233
00234 #endif
00235
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
00249 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00250
00251 template <ss_typename_param_k C>
00252 inline us_char_a_t const* c_str_ptr_a(unixstl_ns_qual(basic_current_directory_scope)<us_char_a_t, C> const& b)
00253 {
00254 return b.c_str();
00255 }
00256 template <ss_typename_param_k C>
00257 inline us_char_w_t const* c_str_ptr_w(unixstl_ns_qual(basic_current_directory_scope)<us_char_w_t, C> const& b)
00258 {
00259 return b.c_str();
00260 }
00261
00262 #endif
00263
00268 template< ss_typename_param_k C
00269 , ss_typename_param_k T
00270 >
00271 inline C const* c_str_ptr(basic_current_directory_scope<C, T> const& b)
00272 {
00273 return b.get_previous();
00274 }
00275
00276
00277 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00278
00279 template <ss_typename_param_k C>
00280 inline us_char_a_t const* c_str_data_a(unixstl_ns_qual(basic_current_directory_scope)<us_char_a_t, C> const& b)
00281 {
00282 return b.c_str();
00283 }
00284 template <ss_typename_param_k C>
00285 inline us_char_w_t const* c_str_data_w(unixstl_ns_qual(basic_current_directory_scope)<us_char_w_t, C> const& b)
00286 {
00287 return b.c_str();
00288 }
00289
00290 #endif
00291
00296 template< ss_typename_param_k C
00297 , ss_typename_param_k T
00298 >
00299 inline C const* c_str_data(basic_current_directory_scope<C, T> const& b)
00300 {
00301 return b.get_previous();
00302 }
00303
00304
00305
00306 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00307
00308 template <ss_typename_param_k C>
00309 inline us_size_t c_str_len_a(unixstl_ns_qual(basic_current_directory_scope)<us_char_a_t, C> const& b)
00310 {
00311 return stlsoft_ns_qual(c_str_len_a)(b.c_str());
00312 }
00313 template <ss_typename_param_k C>
00314 inline us_size_t c_str_len_w(unixstl_ns_qual(basic_current_directory_scope)<us_char_w_t, C> const& b)
00315 {
00316 return stlsoft_ns_qual(c_str_len_w)(b.c_str());
00317 }
00318
00319 #endif
00320
00325 template< ss_typename_param_k C
00326 , ss_typename_param_k T
00327 >
00328 inline us_size_t c_str_len(basic_current_directory_scope<C, T> const& b)
00329 {
00330 return stlsoft_ns_qual(c_str_len)(b.get_previous());
00331 }
00332
00333
00334
00335
00336 template< ss_typename_param_k S
00337 , ss_typename_param_k C
00338 , ss_typename_param_k T
00339 >
00340 inline S& operator <<(S& s, basic_current_directory_scope<C, T> const& b)
00341 {
00342 s << b.get_previous();
00343
00344 return s;
00345 }
00346
00348
00349
00350 #ifdef STLSOFT_UNITTEST
00351 # include "./unittest/current_directory_scope_unittest_.h"
00352 #endif
00353
00354
00355
00356
00357
00358 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00359
00360 template< ss_typename_param_k C
00361 , ss_typename_param_k T
00362 >
00363 inline void basic_current_directory_scope<C, T>::init_(ss_typename_type_k basic_current_directory_scope<C, T>::char_type const* dir)
00364 {
00365 if( 0 == traits_type::get_current_directory(m_previous.size(), &m_previous[0]) ||
00366 !traits_type::set_current_directory(dir))
00367 {
00368 m_previous[0] = '\0';
00369 }
00370 }
00371
00372 template< ss_typename_param_k C
00373 , ss_typename_param_k T
00374 >
00375 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)
00376 {
00377 init_(dir);
00378 }
00379
00380 template< ss_typename_param_k C
00381 , ss_typename_param_k T
00382 >
00383 inline basic_current_directory_scope<C, T>::~basic_current_directory_scope() stlsoft_throw_0()
00384 {
00385 if('\0' != m_previous[0])
00386 {
00387 traits_type::set_current_directory(m_previous.data());
00388 }
00389 }
00390
00391 template< ss_typename_param_k C
00392 , ss_typename_param_k T
00393 >
00394 inline ss_typename_type_ret_k basic_current_directory_scope<C, T>::char_type const* basic_current_directory_scope<C, T>::get_previous() const
00395 {
00396 #if defined(STLSOFT_COMPILER_IS_GCC) && \
00397 __GNUC__ < 3
00398 return m_previous.c_str();
00399 #else
00400 return stlsoft_ns_qual(c_str_ptr)(m_previous);
00401 #endif
00402 }
00403
00404 template< ss_typename_param_k C
00405 , ss_typename_param_k T
00406 >
00407 #if defined(STLSOFT_COMPILER_IS_GCC)
00408 inline basic_current_directory_scope<C, T>::operator C const* () const
00409 #else
00410 inline basic_current_directory_scope<C, T>::operator ss_typename_type_k basic_current_directory_scope<C, T>::char_type const* () const
00411 #endif
00412 {
00413 return get_previous();
00414 }
00415
00416 #endif
00417
00418
00419
00420 #ifndef _UNIXSTL_NO_NAMESPACE
00421 # if defined(_STLSOFT_NO_NAMESPACE) || \
00422 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00423 }
00424 # else
00425 }
00426 }
00427 # endif
00428 #endif
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 #ifndef _UNIXSTL_NO_NAMESPACE
00439 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00440 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00441 namespace stlsoft
00442 {
00443 # else
00444
00445 # endif
00446
00447 using ::unixstl::c_str_data;
00448 using ::unixstl::c_str_data_a;
00449 using ::unixstl::c_str_data_w;
00450
00451 using ::unixstl::c_str_len;
00452 using ::unixstl::c_str_len_a;
00453 using ::unixstl::c_str_len_w;
00454
00455 using ::unixstl::c_str_ptr;
00456 using ::unixstl::c_str_ptr_a;
00457 using ::unixstl::c_str_ptr_w;
00458
00459 using ::unixstl::c_str_ptr_null;
00460 using ::unixstl::c_str_ptr_null_a;
00461 using ::unixstl::c_str_ptr_null_w;
00462
00463 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00464 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00465 }
00466 # else
00467
00468 # endif
00469 #endif
00470
00471
00472
00473 #endif
00474
00475