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_UNIXSTL
00060 # include "unixstl.h"
00061 #endif
00062 #ifndef STLSOFT_INCL_H_STLSOFT_AUTO_BUFFER
00063 # include "stlsoft_auto_buffer.h"
00064 #endif
00065 #ifndef STLSOFT_INCL_H_STLSOFT_MALLOC_ALLOCATOR
00066 # include "stlsoft_malloc_allocator.h"
00067 #endif
00068 #ifndef UNIXSTL_INCL_H_UNIXSTL_STRING_ACCESS
00069 # include "unixstl_string_access.h"
00070 #endif
00071 #include <unistd.h>
00072
00073
00074
00075
00076
00077 #ifndef _UNIXSTL_NO_NAMESPACE
00078 # if defined(_STLSOFT_NO_NAMESPACE) || \
00079 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00080
00081 namespace unixstl
00082 {
00083 # else
00084
00085
00086 namespace stlsoft
00087 {
00088
00089 namespace unixstl_project
00090 {
00091
00092 # endif
00093 #endif
00094
00095
00096
00099
00103
00108
00109
00110
00111
00112
00113
00126
00127 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00128 , ss_typename_param_k A = stlsoft_ns_qual(malloc_allocator)<C>
00129 #else
00130 , ss_typename_param_k A
00131 #endif
00132 >
00133 class basic_file_path_buffer
00134 {
00135 #if defined(PATH_MAX)
00136 typedef stlsoft_ns_qual(auto_buffer)<C, A, 1 + PATH_MAX> buffer_type;
00137 #else
00138 typedef stlsoft_ns_qual(auto_buffer)<C, A, 1 + 512> buffer_type;
00139 #endif
00140 public:
00142 typedef basic_file_path_buffer<C, A> class_type;
00144 typedef ss_typename_type_k buffer_type::value_type value_type;
00146 typedef value_type &reference;
00148 typedef value_type const &const_reference;
00150 typedef ss_typename_type_k buffer_type::size_type size_type;
00151
00152
00153 public:
00155 basic_file_path_buffer()
00156 #if defined(PATH_MAX)
00157 : m_buffer(1 + PATH_MAX)
00158 #else
00159 : m_buffer(1 + pathconf("/", _PC_PATH_MAX))
00160 #endif
00161 {}
00162
00163 basic_file_path_buffer(class_type const &rhs)
00164 : m_buffer(rhs.size())
00165 {
00166 buffer_type::block_copy(m_buffer, rhs, rhs.size());
00167 }
00168
00169 const basic_file_path_buffer &operator =(class_type const &rhs)
00170 {
00171 m_buffer.resize(rhs.size());
00172 buffer_type::block_copy(m_buffer, rhs, rhs.size());
00173
00174 return *this;
00175 }
00176
00177
00178 public:
00179 void swap(class_type &rhs)
00180 {
00181 m_buffer.swap(rhs.m_buffer);
00182 }
00183
00184
00185 public:
00187 value_type const *c_str() const
00188 {
00189 return m_buffer.data();
00190 }
00191
00193 reference operator [](size_t index)
00194 {
00195 buffer_type &this_ = m_buffer;
00196
00197 return this_[index];
00198 }
00199 #if !defined(__STLSOFT_COMPILER_IS_COMO) && \
00200 !defined(__STLSOFT_COMPILER_IS_MWERKS)
00201
00202 const_reference operator [](size_t index) const
00203 {
00204 unixstl_message_assert("Index out of range", !(size() < index));
00205
00206 return m_buffer.data()[index];
00207 }
00208 #endif
00209
00211 size_type size() const
00212 {
00213 return m_buffer.size();
00214 }
00215
00216
00217 public:
00221 static void refresh() unixstl_throw_0()
00222 {}
00223
00224
00225 private:
00226 buffer_type m_buffer;
00227 };
00228
00229
00231 typedef basic_file_path_buffer<us_char_a_t, stlsoft_ns_qual(malloc_allocator)<us_char_a_t> > file_path_buffer_a;
00233 typedef basic_file_path_buffer<us_char_w_t, stlsoft_ns_qual(malloc_allocator)<us_char_w_t> > file_path_buffer_w;
00234
00235
00236
00237
00238
00239 template< ss_typename_param_k C
00240 , ss_typename_param_k A
00241 >
00242 inline C const *c_str_ptr_null(basic_file_path_buffer<C, A> const &b)
00243 {
00244 return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
00245 }
00246
00247 template< ss_typename_param_k C
00248 , ss_typename_param_k A
00249 >
00250 inline C const *c_str_ptr(basic_file_path_buffer<C, A> const &b)
00251 {
00252 return stlsoft_ns_qual(c_str_ptr)(b.c_str());
00253 }
00254
00255 template< ss_typename_param_k C
00256 , ss_typename_param_k A
00257 >
00258 inline us_size_t c_str_len(basic_file_path_buffer<C, A> const &b)
00259 {
00260 return stlsoft_ns_qual(c_str_len)(b.c_str());
00261 }
00262
00263 template< ss_typename_param_k C
00264 , ss_typename_param_k A
00265 >
00266 inline us_size_t c_str_size(basic_file_path_buffer<C, A> const &b)
00267 {
00268 return stlsoft_ns_qual(c_str_size)(b.c_str());
00269 }
00270
00271 template< ss_typename_param_k S
00272 , ss_typename_param_k C
00273 , ss_typename_param_k A
00274 >
00275 inline S &operator <<(S & s, basic_file_path_buffer<C, A> const &b)
00276 {
00277 s << b.c_str();
00278
00279 return s;
00280 }
00281
00282
00283
00284
00285
00286 #ifdef STLSOFT_UNITTEST
00287
00288 namespace unittest
00289 {
00290 ss_bool_t test_unixstl_file_path_buffer(unittest_reporter *r)
00291 {
00292 using stlsoft::unittest::unittest_initialiser;
00293
00294 ss_bool_t bSuccess = true;
00295
00296 unittest_initialiser init(r, "UNIXSTL", "file_path_buffer", __FILE__);
00297
00298 file_path_buffer_a buf_a;
00299
00300 #if defined(PATH_MAX)
00301 if(1 + PATH_MAX != buf_a.size())
00302 #else
00303 if(static_cast<ss_size_t>(1 + pathconf("/", _PC_PATH_MAX)) != buf_a.size())
00304 #endif
00305 {
00306 r->report("ANSI buffer size incorrect", __LINE__);
00307 bSuccess = false;
00308 }
00309
00310 file_path_buffer_w buf_w;
00311
00312 #if defined(PATH_MAX)
00313 if(1 + PATH_MAX != buf_w.size())
00314 #else
00315 if(static_cast<ss_size_t>(1 + pathconf("/", _PC_PATH_MAX)) != buf_w.size())
00316 #endif
00317 {
00318 r->report("Unicode (Win9x) buffer size incorrect", __LINE__);
00319 bSuccess = false;
00320 }
00321
00322 return bSuccess;
00323 }
00324
00325 unittest_registrar unittest_unixstl_file_path_buffer(test_unixstl_file_path_buffer);
00326
00327 }
00328
00329 #endif
00330
00331
00332
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 #endif
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 #ifndef _UNIXSTL_NO_NAMESPACE
00356 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00357 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00358 namespace stlsoft
00359 {
00360 # else
00361
00362 # endif
00363
00364 using ::unixstl::c_str_ptr_null;
00365
00366 using ::unixstl::c_str_ptr;
00367
00368 using ::unixstl::c_str_len;
00369
00370 using ::unixstl::c_str_size;
00371
00372 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00373 !defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00374 }
00375 # else
00376
00377 # endif
00378 #endif
00379
00380
00381
00382
00383
00384