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_FILE_PATH_BUFFER
00049 #define UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER_MAJOR 4
00053 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER_MINOR 2
00054 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER_REVISION 1
00055 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER_EDIT 64
00056 #endif
00057
00058
00059
00060
00061
00062 #ifndef UNIXSTL_INCL_UNIXSTL_H_UNIXSTL
00063 # include <unixstl/unixstl.h>
00064 #endif
00065 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
00066 # include <stlsoft/memory/auto_buffer.hpp>
00067 #endif
00068 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_SELECTOR
00069 # include <stlsoft/memory/allocator_selector.hpp>
00070 #endif
00071 #ifndef UNIXSTL_INCL_UNIXSTL_SHIMS_ACCESS_HPP_STRING
00072 # include <unixstl/shims/access/string.hpp>
00073 #endif
00074 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_COPY_FUNCTIONS
00075 # include <stlsoft/string/copy_functions.hpp>
00076 #endif
00077
00078 #ifndef STLSOFT_INCL_H_UNISTD
00079 # define STLSOFT_INCL_H_UNISTD
00080 # include <unistd.h>
00081 #endif
00082
00083
00084
00085
00086
00087 #ifndef _UNIXSTL_NO_NAMESPACE
00088 # if defined(_STLSOFT_NO_NAMESPACE) || \
00089 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00090
00091 namespace unixstl
00092 {
00093 # else
00094
00095
00096 namespace stlsoft
00097 {
00098
00099 namespace unixstl_project
00100 {
00101
00102 # endif
00103 #endif
00104
00105
00106
00107
00108
00109
00125 template< ss_typename_param_k C
00126 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00127 , ss_typename_param_k A = ss_typename_type_def_k allocator_selector<C>::allocator_type
00128 #else
00129 , ss_typename_param_k A
00130 #endif
00131 >
00132 class basic_file_path_buffer
00133 {
00136 private:
00137 enum
00138 {
00139 #ifdef PATH_MAX
00140 internalBufferSize = 1 + PATH_MAX
00141 #else
00142 internalBufferSize = 1 + 512
00143 #endif
00144 };
00145
00146 enum
00147 {
00148 indeterminateMaxPathGuess = 2048
00149 };
00150
00151 typedef stlsoft_ns_qual(auto_buffer)<
00152 C
00153 , internalBufferSize
00154 , A
00155 > buffer_type_;
00157
00160 public:
00162 typedef C char_type;
00164 typedef A allocator_type;
00166 typedef basic_file_path_buffer<C, A> class_type;
00168 typedef ss_typename_type_k buffer_type_::value_type value_type;
00170 typedef value_type& reference;
00172 typedef value_type const& const_reference;
00174 typedef ss_typename_type_k buffer_type_::size_type size_type;
00176
00179 public:
00181 basic_file_path_buffer()
00182 : m_buffer(1 + calc_path_max_())
00183 {
00184 #ifdef _DEBUG
00185 ::memset(&m_buffer[0], '?', m_buffer.size());
00186 m_buffer[m_buffer.size() - 1] = '\0';
00187 #endif
00188 }
00190 basic_file_path_buffer(class_type const& rhs)
00191 : m_buffer(rhs.size())
00192 {
00193 stlsoft_ns_qual(pod_copy_n)(data(), rhs.data(), m_buffer.size());
00194 }
00196 class_type& operator =(class_type const& rhs)
00197 {
00198 m_buffer.resize(rhs.size());
00199 stlsoft_ns_qual(pod_copy_n)(data(), rhs.data(), m_buffer.size());
00200
00201 return *this;
00202 }
00204
00207 public:
00217 void swap(class_type& rhs) stlsoft_throw_0()
00218 {
00219 m_buffer.swap(rhs.m_buffer);
00220 }
00222 us_bool_t grow(size_type newSize)
00223 {
00224 return m_buffer.resize(newSize);
00225 }
00227 us_bool_t grow()
00228 {
00229 return grow(2 * size());
00230 }
00232
00235 public:
00236 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00237 value_type const *data() const
00238 {
00239 return m_buffer.data();
00240 }
00241 value_type *data()
00242 {
00243 return m_buffer.data();
00244 }
00245 #endif
00246
00248 value_type const* c_str() const
00249 {
00250 return this->data();
00251 }
00252
00254 reference operator [](us_size_t index)
00255 {
00256 buffer_type_& this_ = m_buffer;
00257
00258 return this_[index];
00259 }
00260 #if !defined(STLSOFT_COMPILER_IS_COMO) && \
00261 !defined(STLSOFT_COMPILER_IS_MWERKS)
00263 const_reference operator [](us_size_t index) const
00264 {
00265 UNIXSTL_MESSAGE_ASSERT("Index out of range", !(size() < index));
00266
00267 return data()[index];
00268 }
00269 #endif
00270
00272 size_type size() const
00273 {
00274 return m_buffer.size();
00275 }
00276
00278 static size_type max_size()
00279 {
00280 return calc_path_max_();
00281 }
00282
00288 size_type copy(char_type *buffer, size_type cchBuffer) const
00289 {
00290 return stlsoft_ns_qual(copy_contents)(buffer, cchBuffer, m_buffer.data(), m_buffer.size());
00291 }
00293
00296 public:
00300 static void refresh() stlsoft_throw_0()
00301 {}
00303
00306 private:
00307 static size_type calc_path_max_()
00308 {
00309 #ifdef PATH_MAX
00310 return PATH_MAX;
00311 #else
00312 int pathMax = ::pathconf("/", _PC_PATH_MAX);
00313
00314 if(pathMax < 0)
00315 {
00316 pathMax = indeterminateMaxPathGuess;
00317 }
00318 else
00319 {
00320 ++pathMax;
00321 }
00322
00323 return static_cast<size_type>(pathMax);
00324 #endif
00325 }
00327
00330 private:
00331 buffer_type_ m_buffer;
00333 };
00334
00335
00340 typedef basic_file_path_buffer<us_char_a_t, stlsoft_ns_qual(allocator_selector)<us_char_a_t>::allocator_type> file_path_buffer_a;
00345 typedef basic_file_path_buffer<us_char_w_t, stlsoft_ns_qual(allocator_selector)<us_char_w_t>::allocator_type> file_path_buffer_w;
00350 typedef basic_file_path_buffer<us_char_a_t, stlsoft_ns_qual(allocator_selector)<us_char_a_t>::allocator_type> file_path_buffer;
00351
00352
00353
00354
00355
00356
00357 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00358
00359 template< ss_typename_param_k C
00360 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00361 , ss_typename_param_k A = ss_typename_type_def_k allocator_selector<C>::allocator_type
00362 #else
00363 , ss_typename_param_k A
00364 #endif
00365 >
00366 class basic_file_path_buffer__
00367 : public unixstl_ns_qual(basic_file_path_buffer)<C, A>
00368 {
00369 private:
00370 typedef unixstl_ns_qual(basic_file_path_buffer)<C, A> parent_class_type;
00371 public:
00372 typedef basic_file_path_buffer__<C, A> class_type;
00373 typedef ss_typename_type_k parent_class_type::value_type value_type;
00374 typedef ss_typename_type_k parent_class_type::reference reference;
00375 typedef ss_typename_type_k parent_class_type::const_reference const_reference;
00376 typedef ss_typename_type_k parent_class_type::size_type size_type;
00377 };
00378
00379 #endif
00380
00381
00382
00383
00384
00385 template< ss_typename_param_k C
00386 , ss_typename_param_k A
00387 >
00388 inline void swap(basic_file_path_buffer<C, A>& lhs, basic_file_path_buffer<C, A>& rhs)
00389 {
00390 lhs.swap(rhs);
00391 }
00392
00393
00394
00395
00396
00397 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00398
00399 template <ss_typename_param_k A>
00400 inline us_char_a_t const* c_str_data_a(unixstl_ns_qual(basic_file_path_buffer)<us_char_a_t, A> const& b)
00401 {
00402 return b.c_str();
00403 }
00404 template <ss_typename_param_k A>
00405 inline us_char_w_t const* c_str_data_w(unixstl_ns_qual(basic_file_path_buffer)<us_char_w_t, A> const& b)
00406 {
00407 return b.c_str();
00408 }
00409
00410 #endif
00411
00416 template< ss_typename_param_k C
00417 , ss_typename_param_k A
00418 >
00419 inline C const* c_str_data(unixstl_ns_qual(basic_file_path_buffer)<C, A> const& b)
00420 {
00421 return b.c_str();
00422 }
00423
00424
00425 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00426
00427 template <ss_typename_param_k A>
00428 inline us_size_t c_str_len_a(unixstl_ns_qual(basic_file_path_buffer)<us_char_a_t, A> const& b)
00429 {
00430 return stlsoft_ns_qual(c_str_len_a)(b.c_str());
00431 }
00432 template <ss_typename_param_k A>
00433 inline us_size_t c_str_len_w(unixstl_ns_qual(basic_file_path_buffer)<us_char_w_t, A> const& b)
00434 {
00435 return stlsoft_ns_qual(c_str_len_w)(b.c_str());
00436 }
00437
00438 #endif
00439
00444 template< ss_typename_param_k C
00445 , ss_typename_param_k A
00446 >
00447 inline us_size_t c_str_len(unixstl_ns_qual(basic_file_path_buffer)<C, A> const& b)
00448 {
00449 return stlsoft_ns_qual(c_str_len)(b.c_str());
00450 }
00451
00452
00453 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00454
00455 template <ss_typename_param_k A>
00456 inline us_char_a_t const* c_str_ptr_a(unixstl_ns_qual(basic_file_path_buffer)<us_char_a_t, A> const& b)
00457 {
00458 return b.c_str();
00459 }
00460 template <ss_typename_param_k A>
00461 inline us_char_w_t const* c_str_ptr_w(unixstl_ns_qual(basic_file_path_buffer)<us_char_w_t, A> const& b)
00462 {
00463 return b.c_str();
00464 }
00465
00466 #endif
00467
00472 template< ss_typename_param_k C
00473 , ss_typename_param_k A
00474 >
00475 inline C const* c_str_ptr(unixstl_ns_qual(basic_file_path_buffer)<C, A> const& b)
00476 {
00477 return b.c_str();
00478 }
00479
00480
00481
00482 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00483
00484 template <ss_typename_param_k A>
00485 inline us_char_a_t const* c_str_ptr_null_a(unixstl_ns_qual(basic_file_path_buffer)<us_char_a_t, A> const& b)
00486 {
00487 return stlsoft_ns_qual(c_str_ptr_null_a)(b.c_str());
00488 }
00489 template <ss_typename_param_k A>
00490 inline us_char_w_t const* c_str_ptr_null_w(unixstl_ns_qual(basic_file_path_buffer)<us_char_w_t, A> const& b)
00491 {
00492 return stlsoft_ns_qual(c_str_ptr_null_w)(b.c_str());
00493 }
00494
00495 #endif
00496
00501 template< ss_typename_param_k C
00502 , ss_typename_param_k A
00503 >
00504 inline C const* c_str_ptr_null(unixstl_ns_qual(basic_file_path_buffer)<C, A> const& b)
00505 {
00506 return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
00507 }
00508
00509
00510
00511
00516 template< ss_typename_param_k S
00517 , ss_typename_param_k C
00518 , ss_typename_param_k A
00519 >
00520 inline S& operator <<(S& s, unixstl_ns_qual(basic_file_path_buffer)<C, A> const& b)
00521 {
00522 s << b.c_str();
00523
00524 return s;
00525 }
00526
00527
00528
00529
00530
00531 #ifdef STLSOFT_UNITTEST
00532 # include "./unittest/file_path_buffer_unittest_.h"
00533 #endif
00534
00535
00536
00537 #ifndef _UNIXSTL_NO_NAMESPACE
00538 # if defined(_STLSOFT_NO_NAMESPACE) || \
00539 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00540 }
00541 # else
00542 }
00543 }
00544 # endif
00545 #endif
00546
00547
00548
00549
00550 #if defined(STLSOFT_CF_std_NAMESPACE)
00551 # if ( ( defined(STLSOFT_COMPILER_IS_INTEL) && \
00552 defined(_MSC_VER))) && \
00553 _MSC_VER < 1310
00554 namespace std
00555 {
00556 template< ss_typename_param_k C
00557 , ss_typename_param_k A
00558 >
00559 inline void swap(unixstl_ns_qual(basic_file_path_buffer)<C, A>& lhs, unixstl_ns_qual(basic_file_path_buffer)<C, A>& rhs)
00560 {
00561 lhs.swap(rhs);
00562 }
00563 }
00564 # endif
00565 #endif
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575 #ifndef _UNIXSTL_NO_NAMESPACE
00576 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00577 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00578 namespace stlsoft
00579 {
00580 # else
00581
00582 # endif
00583
00584 using ::unixstl::c_str_data;
00585 using ::unixstl::c_str_data_a;
00586 using ::unixstl::c_str_data_w;
00587
00588 using ::unixstl::c_str_len;
00589 using ::unixstl::c_str_len_a;
00590 using ::unixstl::c_str_len_w;
00591
00592 using ::unixstl::c_str_ptr;
00593 using ::unixstl::c_str_ptr_a;
00594 using ::unixstl::c_str_ptr_w;
00595
00596 using ::unixstl::c_str_ptr_null;
00597 using ::unixstl::c_str_ptr_null_a;
00598 using ::unixstl::c_str_ptr_null_w;
00599
00600 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00601 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00602 }
00603 # else
00604
00605 # endif
00606 #endif
00607
00608
00609
00610 #endif
00611
00612