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  

winstl_absolute_path.h

Go to the documentation of this file.
00001 /* 
00002  * File:        winstl_absolute_path.h
00003  *
00004  * Purpose:     Simple class that converts a relative path to an absolute one.
00005  *
00006  * Created:     20th December 2002
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 2002-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 WINSTL_INCL_H_WINSTL_ABSOLUTE_PATH
00046 #define WINSTL_INCL_H_WINSTL_ABSOLUTE_PATH
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define WINSTL_VER_H_WINSTL_ABSOLUTE_PATH_MAJOR        2
00050 # define WINSTL_VER_H_WINSTL_ABSOLUTE_PATH_MINOR        0
00051 # define WINSTL_VER_H_WINSTL_ABSOLUTE_PATH_REVISION     1
00052 # define WINSTL_VER_H_WINSTL_ABSOLUTE_PATH_EDIT         29
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Includes
00057  */
00058 
00059 #ifndef WINSTL_INCL_H_WINSTL
00060 # include "winstl.h"                    // Include the WinSTL root header
00061 #endif /* !WINSTL_INCL_H_WINSTL */
00062 #ifndef WINSTL_INCL_H_WINSTL_SYSTEM_VERSION
00063 # include "winstl_filesystem_traits.h"  // Include the WinSTL system_version
00064 #endif /* !WINSTL_INCL_H_WINSTL_SYSTEM_VERSION */
00065 #ifndef WINSTL_INCL_H_WINSTL_FILE_PATH_BUFFER
00066 # include "winstl_file_path_buffer.h"   // basic_file_path_buffer
00067 #endif /* !WINSTL_INCL_H_WINSTL_FILE_PATH_BUFFER */
00068 #ifndef STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00069 # include "stlsoft_string_access.h"     // stlsoft::c_str_ptr
00070 #endif /* !STLSOFT_INCL_H_STLSOFT_STRING_ACCESS */
00071 #ifndef WINSTL_INCL_H_WINSTL_STRING_ACCESS
00072 # include "winstl_string_access.h"      // winstl::c_str_ptr
00073 #endif /* !WINSTL_INCL_H_WINSTL_STRING_ACCESS */
00074 
00075 /* 
00076  * Namespace
00077  */
00078 
00079 #ifndef _WINSTL_NO_NAMESPACE
00080 # if defined(_STLSOFT_NO_NAMESPACE) || \
00081      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00082 /* There is no stlsoft namespace, so must define ::winstl */
00083 namespace winstl
00084 {
00085 # else
00086 /* Define stlsoft::winstl_project */
00087 
00088 namespace stlsoft
00089 {
00090 
00091 namespace winstl_project
00092 {
00093 
00094 # endif /* _STLSOFT_NO_NAMESPACE */
00095 #endif /* !_WINSTL_NO_NAMESPACE */
00096 
00097 #if !defined(__STLSOFT_COMPILER_IS_MWERKS)
00098 stlsoft_ns_using(c_str_ptr)
00099 #endif /* compiler */
00100 
00101 /* 
00102 
00105 
00109 
00114 
00115 /* 
00116  * basic_absolute_path
00117  *
00118  * This class converts a relative path to an absolute one, and effectively acts
00119  * as a C-string of its value.
00120  */
00121 
00126 template<   ss_typename_param_k C
00127 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00128         ,   ss_typename_param_k T = filesystem_traits<C>
00129 #else
00130         ,   ss_typename_param_k T /* = filesystem_traits<C> */
00131 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00132         >
00133 class basic_absolute_path
00134 {
00135 public:
00137     typedef C                           char_type;
00139     typedef T                           traits_type;
00141     typedef basic_absolute_path<C, T>   class_type;
00143     typedef ws_size_t                   size_type;
00144 
00145 // Construction
00146 public:
00148     ss_explicit_k basic_absolute_path(char_type const *path)
00149         : m_len(traits_type::get_full_path_name(path, winstl_num_elements(m_path), &m_path[0]))
00150     {}
00151 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00152 
00153     template<ss_typename_param_k S>
00154     ss_explicit_k basic_absolute_path(S const &path)
00155         : m_len(traits_type::get_full_path_name(c_str_ptr(path), winstl_num_elements(m_path), &m_path[0]))
00156     {}
00157 #endif /* __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
00158 
00159 // Conversions
00160 public:
00162     operator char_type const *() const
00163     {
00164         return stlsoft_ns_qual(c_str_ptr)(m_path);
00165     }
00166 
00167 // Attributes
00168 public:
00170     size_type length() const
00171     {
00172         return m_len;
00173     }
00174 
00175 // Members
00176 private:
00177     basic_file_path_buffer<char_type>   m_path;
00178     size_type const                     m_len;
00179 
00180 // Not to be implemented
00181 private:
00182     basic_absolute_path(const class_type &);
00183     basic_absolute_path &operator =(const class_type &);
00184 };
00185 
00186 /* 
00187  * Typedefs for commonly encountered types
00188  */
00189 
00191 typedef basic_absolute_path<ws_char_a_t, filesystem_traits<ws_char_a_t> >       absolute_path_a;
00193 typedef basic_absolute_path<ws_char_w_t, filesystem_traits<ws_char_w_t> >       absolute_path_w;
00195 typedef basic_absolute_path<TCHAR, filesystem_traits<TCHAR> >                   absolute_path;
00196 
00197 /* 
00198  * Helper functions
00199  */
00200 
00201 #if !defined(__STLSOFT_COMPILER_IS_MSVC) || \
00202     _MSC_VER >= 1100
00203 
00206 template<ss_typename_param_k C>
00207 inline basic_absolute_path<C> make_absolute_path(C const *path)
00208 {
00209     return basic_absolute_path<C>(path);
00210 }
00211 
00212 #endif /* !(_MSC_VER < 1100) */
00213 
00215 // Unit-testing
00216 
00217 #ifdef STLSOFT_UNITTEST
00218 
00219 namespace unittest
00220 {
00221     ss_bool_t test_winstl_absolute_path(unittest_reporter *r)
00222     {
00223         using stlsoft::unittest::unittest_initialiser;
00224 
00225         ss_bool_t               bSuccess    =   true;
00226 
00227         unittest_initialiser    init(r, "UNIXSTL", "absolute_path", __FILE__);
00228 
00229         TCHAR   cwd[1 + _MAX_PATH];
00230 
00231         ::GetCurrentDirectory(stlsoft_num_elements(cwd), cwd);
00232 
00233         if(0 != lstrcmp(cwd, absolute_path(".")))
00234         {
00235             r->report("absolute path for \".\" failed ", __LINE__);
00236             bSuccess = false;
00237         }
00238 
00239         return bSuccess;
00240     }
00241 
00242     unittest_registrar    unittest_winstl_absolute_path(test_winstl_absolute_path);
00243 
00244 } // namespace unittest
00245 
00246 #endif /* STLSOFT_UNITTEST */
00247 
00248 /* 
00249 
00251 
00252 /* 
00253 
00254 #ifndef _WINSTL_NO_NAMESPACE
00255 # if defined(_STLSOFT_NO_NAMESPACE) || \
00256      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00257 } // namespace winstl
00258 # else
00259 } // namespace winstl_project
00260 } // namespace stlsoft
00261 # endif /* _STLSOFT_NO_NAMESPACE */
00262 #endif /* !_WINSTL_NO_NAMESPACE */
00263 
00264 /* 
00265 
00266 #endif /* WINSTL_INCL_H_WINSTL_ABSOLUTE_PATH */
00267 
00268 /* 

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