STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

unixstl_file_path_buffer.h

Go to the documentation of this file.
00001 /* 
00002  * File:        unixstl_file_path_buffer.h
00003  *
00004  * Purpose:     Contains the basic_file_path_buffer template class.
00005  *
00006  * Created:     24th May 2004
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 2004, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00044 
00045 #ifndef UNIXSTL_INCL_H_UNIXSTL_FILE_PATH_BUFFER
00046 #define UNIXSTL_INCL_H_UNIXSTL_FILE_PATH_BUFFER
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define UNIXSTL_VER_H_UNIXSTL_FILE_PATH_BUFFER_MAJOR     2
00050 # define UNIXSTL_VER_H_UNIXSTL_FILE_PATH_BUFFER_MINOR     0
00051 # define UNIXSTL_VER_H_UNIXSTL_FILE_PATH_BUFFER_REVISION  1
00052 # define UNIXSTL_VER_H_UNIXSTL_FILE_PATH_BUFFER_EDIT      13
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Includes
00057  */
00058 
00059 #ifndef UNIXSTL_INCL_H_UNIXSTL
00060 # include "unixstl.h"                        // Include the UNIXSTL root header
00061 #endif /* !UNIXSTL_INCL_H_UNIXSTL */
00062 #ifndef STLSOFT_INCL_H_STLSOFT_AUTO_BUFFER
00063 # include "stlsoft_auto_buffer.h"           // stlsoft::auto_buffer
00064 #endif /* !STLSOFT_INCL_H_STLSOFT_AUTO_BUFFER */
00065 #ifndef STLSOFT_INCL_H_STLSOFT_MALLOC_ALLOCATOR
00066 # include "stlsoft_malloc_allocator.h"      // stlsoft::malloc_allocator
00067 #endif /* !STLSOFT_INCL_H_STLSOFT_MALLOC_ALLOCATOR */
00068 #ifndef UNIXSTL_INCL_H_UNIXSTL_STRING_ACCESS
00069 # include "unixstl_string_access.h"         // unixstl::c_str_ptr, etc.
00070 #endif /* !UNIXSTL_INCL_H_UNIXSTL_STRING_ACCESS */
00071 #include <unistd.h>
00072 
00073 /* 
00074  * Namespace
00075  */
00076 
00077 #ifndef _UNIXSTL_NO_NAMESPACE
00078 # if defined(_STLSOFT_NO_NAMESPACE) || \
00079      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00080 /* There is no stlsoft namespace, so must define ::unixstl */
00081 namespace unixstl
00082 {
00083 # else
00084 /* Define stlsoft::unixstl_project */
00085 
00086 namespace stlsoft
00087 {
00088 
00089 namespace unixstl_project
00090 {
00091 
00092 # endif /* _STLSOFT_NO_NAMESPACE */
00093 #endif /* !_UNIXSTL_NO_NAMESPACE */
00094 
00095 /* 
00096 
00099 
00103 
00108 
00109 /* 
00110  * Classes
00111  */
00112 
00113 // class basic_file_path_buffer
00126 template<   ss_typename_param_k C
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 /* = stlsoft_ns_qual(malloc_allocator)<C> */
00131 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
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 /* ? PATH_MAX */
00138     typedef stlsoft_ns_qual(auto_buffer)<C, A, 1 + 512>         buffer_type;
00139 #endif /* PATH_MAX */
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 // Construction
00153 public:
00155     basic_file_path_buffer()
00156 #if defined(PATH_MAX)
00157         : m_buffer(1 + PATH_MAX)
00158 #else /* ? PATH_MAX */
00159         : m_buffer(1 + pathconf("/", _PC_PATH_MAX))
00160 #endif /* PATH_MAX */
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 // Operations
00178 public:
00179     void swap(class_type &rhs)
00180     {
00181         m_buffer.swap(rhs.m_buffer);
00182     }
00183 
00184 // Accessors
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 /* compiler */
00209 
00211     size_type size() const
00212     {
00213         return m_buffer.size();
00214     }
00215 
00216 // Operations
00217 public:
00221     static void refresh() unixstl_throw_0()
00222     {}
00223 
00224 // Members
00225 private:
00226     buffer_type m_buffer;
00227 };
00228 
00229 /* Typedefs to commonly encountered types. */
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  * Shims
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  * Unit-testing
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 /* ? PATH_MAX */
00303         if(static_cast<ss_size_t>(1 + pathconf("/", _PC_PATH_MAX)) != buf_a.size())
00304 #endif /* PATH_MAX */
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 /* ? PATH_MAX */
00315         if(static_cast<ss_size_t>(1 + pathconf("/", _PC_PATH_MAX)) != buf_w.size())
00316 #endif /* PATH_MAX */
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 } // namespace unittest
00328 
00329 #endif /* STLSOFT_UNITTEST */
00330 
00331 /* 
00332 
00334 
00335 /* 
00336 
00337 #ifndef _UNIXSTL_NO_NAMESPACE
00338 # if defined(_STLSOFT_NO_NAMESPACE) || \
00339      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00340 } // namespace unixstl
00341 # else
00342 } // namespace unixstl_project
00343 } // namespace stlsoft
00344 # endif /* _STLSOFT_NO_NAMESPACE */
00345 #endif /* !_UNIXSTL_NO_NAMESPACE */
00346 
00347 /* 
00348  * Namespace
00349  *
00350  * The string access shims exist either in the stlsoft namespace, or in the
00351  * global namespace. This is required by the lookup rules.
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 /* ? _STLSOFT_NO_NAMESPACE */
00361 /* There is no stlsoft namespace, so must define in the global namespace */
00362 # endif /* !_STLSOFT_NO_NAMESPACE */
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 } // namespace stlsoft
00375 # else /* ? _STLSOFT_NO_NAMESPACE */
00376 /* There is no stlsoft namespace, so must define in the global namespace */
00377 # endif /* !_STLSOFT_NO_NAMESPACE */
00378 #endif /* !_UNIXSTL_NO_NAMESPACE */
00379 
00380 /* 
00381 
00382 #endif /* UNIXSTL_INCL_H_UNIXSTL_FILE_PATH_BUFFER */
00383 
00384 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004