C/C++ User's Journal STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - where the Standard Template Library meets the Active Template Library COMSTL - where the Standard Template Library meets the Component Object Model
Synesis Software InetSTL - where the Standard Template Library meets the Internet UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

recls/stl/recls.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        recls/stl/recls.hpp
00003  *
00004  * Purpose:     recls STL mapping.
00005  *
00006  * Created:     10th September 2003
00007  * Updated:     2nd June 2007
00008  *
00009  * Home:        http://recls.org/
00010  *
00011  * Copyright (c) 2003-2007, 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 
00047 #ifndef RECLS_INCL_RECLS_STL_HPP_RECLS
00048 #define RECLS_INCL_RECLS_STL_HPP_RECLS
00049 
00050 /* File version */
00051 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00052 # define RECLS_VER_RECLS_STL_HPP_RECLS_MAJOR    4
00053 # define RECLS_VER_RECLS_STL_HPP_RECLS_MINOR    1
00054 # define RECLS_VER_RECLS_STL_HPP_RECLS_REVISION 6
00055 # define RECLS_VER_RECLS_STL_HPP_RECLS_EDIT     26
00056 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00057 
00058 /* /////////////////////////////////////////////////////////////////////////////
00059  * Includes
00060  */
00061 
00062 #include <recls/recls.h>
00063 
00064 #if !defined(RECLS_VER_1_8_1) || \
00065     RECLS_VER < RECLS_VER_1_8_1
00066 # error The recls C++ mapping now requires version 1.8.1 or later of the recls core API
00067 #endif /* RECLS_VER < 1.8.1 */
00068 
00069 // FTP?
00070 #if defined(RECLS_PLATFORM_IS_WIN32)
00071 # if !defined(RECLS_INCL_H_RECLS_FTP)
00072 #  include <recls/ftp.h>
00073 # endif /* !RECLS_INCL_H_RECLS_FTP */
00074 #endif /* RECLS_PLATFORM_IS_WIN32 */
00075 
00076 #include <stlsoft/stlsoft.h>    /* If the compiler cannot find this, you are not using STLSoft 1.9.1 or later, as required. */
00077 #if !defined(_STLSOFT_VER_1_9_1) || \
00078     _STLSOFT_VER < _STLSOFT_VER_1_9_1
00079 # error Requires STLSoft 1.9.1, or later. (www.stlsoft.org/downloads.html)
00080 #endif /* STLSoft version */
00081 
00082 #ifdef RECLS_STL_STRING_HEADER
00083 # include RECLS_STL_STRING_HEADER
00084 #else /* ? RECLS_STL_STRING_HEADER */
00085 # include <string>
00086 #endif /* RECLS_STL_STRING_HEADER */
00087 
00088 #if defined(RECLS_COMPILER_IS_DMC)
00089 # include <stlsoft/util/std/library_discriminator.hpp>  // For standard library detection
00090 #endif /* RECLS_COMPILER_IS_DMC */
00091 #include <stlsoft/memory/auto_buffer.hpp>
00092 #include <stlsoft/shims/access/string.hpp>
00093 
00094 #ifdef RECLS_STL_METHOD_PROPERTY_SUPPORT
00095 # undef RECLS_STL_METHOD_PROPERTY_SUPPORT
00096 #endif /* RECLS_STL_METHOD_PROPERTY_SUPPORT */
00097 
00098 #if defined(RECLS_STL_FORCE_METHOD_PROPERTY_SUPPORT)
00099 # define RECLS_STL_METHOD_PROPERTY_SUPPORT
00100 #elif defined(RECLS_STL_NO_METHOD_PROPERTY_SUPPORT)
00101  /* Do not define RECLS_STL_METHOD_PROPERTY_SUPPORT */
00102 #else /* ? RECLS_STL_???_METHOD_PROPERTY_SUPPORT */
00103 # if defined(STLSOFT_COMPILER_IS_BORLAND)
00104  /* Do not define RECLS_STL_METHOD_PROPERTY_SUPPORT */
00105 # elif defined(STLSOFT_COMPILER_IS_DMC)
00106 #  if __DMC__ >= 0x0846
00107 #   define RECLS_STL_METHOD_PROPERTY_SUPPORT */
00108 #  endif /* __DMC__ */
00109  /* Do not define RECLS_STL_METHOD_PROPERTY_SUPPORT */
00110 # elif defined(STLSOFT_COMPILER_IS_GCC) && \
00111        (   __GNUC__ >= 4 || \
00112            (   __GNUC__ == 3 && \
00113                __GNUC_MINOR__ >= 3))
00114 #  define RECLS_STL_METHOD_PROPERTY_SUPPORT
00115 # elif defined(STLSOFT_COMPILER_IS_INTEL)
00116 #  define RECLS_STL_METHOD_PROPERTY_SUPPORT
00117 # elif defined(STLSOFT_COMPILER_IS_MSVC)
00118 #  if _MSC_VER >= 1310
00119 #   define RECLS_STL_METHOD_PROPERTY_SUPPORT
00120 #  endif /* _MSC_VER */
00121 # elif defined(STLSOFT_COMPILER_IS_MWERKS)
00122 #  define RECLS_STL_METHOD_PROPERTY_SUPPORT
00123 # endif /* compiler */
00124 #endif /* RECLS_STL_???_METHOD_PROPERTY_SUPPORT */
00125 
00126 #ifdef RECLS_STL_METHOD_PROPERTY_SUPPORT
00127 # include <stlsoft/properties/method_properties.hpp>
00128 #endif /* RECLS_STL_METHOD_PROPERTY_SUPPORT */
00129 
00130 /* /////////////////////////////////////////////////////////////////////////////
00131  * Property Macros - borrowed from STLSoft's XMLSTL sub-project
00132  */
00133 
00134 #ifdef RECLS_STL_METHOD_PROPERTY_SUPPORT
00135 # define RECLS_STL_OPT_METHOD_PROPERTY_GET(V, R, C, GM, P)                  STLSOFT_METHOD_PROPERTY_GET(V, R, C, GM, P)
00136 # define RECLS_STL_OPT_METHOD_PROPERTY_GET_PROP(R, C, GM, P)                STLSOFT_METHOD_PROPERTY_GET_EXTERNAL_PROP(R, C, GM, P)
00137 # define RECLS_STL_OPT_METHOD_PROPERTY_GETSET(V, RG, RS, C, GM, SM, P)      STLSOFT_METHOD_PROPERTY_GETSET_EXTERNAL(RG, RS, C, GM, SM, P)
00138 # define RECLS_STL_OPT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)                  STLSOFT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)
00139 # define RECLS_STL_OPT_METHOD_PROPERTY_GETSET_PROP(RG, RS, C, GM, SM, P)    STLSOFT_METHOD_PROPERTY_GETSET_EXTERNAL_PROP(RG, RS, C, GM, SM, P)
00140 #else /* ? RECLS_STL_METHOD_PROPERTY_SUPPORT */
00141 # define RECLS_STL_OPT_METHOD_PROPERTY_GET(V, R, C, GM, P)
00142 # define RECLS_STL_OPT_METHOD_PROPERTY_GET_PROP(R, C, GM, P)
00143 # define RECLS_STL_OPT_METHOD_PROPERTY_GETSET(V, RG, RS, C, GM, SM, P)
00144 # define RECLS_STL_OPT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)
00145 # define RECLS_STL_OPT_METHOD_PROPERTY_GETSET_PROP(RG, RS, C, GM, SM, P)
00146 #endif /* RECLS_STL_METHOD_PROPERTY_SUPPORT */
00147 
00148 /* /////////////////////////////////////////////////////////////////////////////
00149  * Namespace
00150  */
00151 
00152 #if !defined(RECLS_NO_NAMESPACE)
00153 namespace recls
00154 {
00155 
00156 namespace stl
00157 {
00158 #endif /* !RECLS_NO_NAMESPACE */
00159 
00160 /* /////////////////////////////////////////////////////////////////////////////
00161  * Typedefs
00162  */
00163 
00164 #ifdef RECLS_DOCUMENTATION_SKIP_SECTION
00165 
00174 typedef std::string                     string_a_t;
00175 typedef std::wstring                    string_w_t;
00176 
00177 # if defined(RECLS_CHAR_TYPE_IS_CHAR)
00178 typedef string_a_t                      string_t;
00179 # elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00180 typedef string_w_t                      string_t;
00181 # else /* ? RECLS_CHAR_TYPE_IS_??? */
00182 #  error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00183 # endif /* RECLS_CHAR_TYPE_IS_??? */
00184 
00185 #else /* ? RECLS_DOCUMENTATION_SKIP_SECTION */
00186 
00187 # ifdef RECLS_CPP_STRING_HEADER
00188 #  ifndef RECLS_CPP_STRING_T
00189 #   error RECLS_CPP_STRING_T must be defined when RECLS_CPP_STRING_HEADER is defined
00190 #  endif /* !RECLS_STRING_T */
00191 typedef RECLS_CPP_STRING_T              string_t;
00192 # else
00193 #  if defined(RECLS_COMPILER_IS_DMC) && \
00194       !defined(STLSOFT_CF_STD_LIBRARY_IS_STLPORT)
00195 typedef string                          string_a_t;
00196 typedef wstring                         string_w_t;
00197 #  else /* ? compiler */
00198 typedef std::string                     string_a_t;
00199 typedef std::wstring                    string_w_t;
00200 #  endif /* compiler */
00201 #  if defined(RECLS_CHAR_TYPE_IS_CHAR)
00202 typedef string_a_t                      string_t;
00203 #  elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00204 typedef string_w_t                      string_t;
00205 #  else /* ? RECLS_CHAR_TYPE_IS_??? */
00206 #   error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00207 #  endif /* RECLS_CHAR_TYPE_IS_??? */
00208 # endif /* RECLS_STRING_HEADER */
00209 
00210 #endif /* RECLS_DOCUMENTATION_SKIP_SECTION */
00211 
00212 /* /////////////////////////////////////////////////////////////////////////////
00213  * Classes
00214  */
00215 
00217 class recls_exception
00218     : public std::exception
00219 {
00222 public:
00223     typedef std::exception  parent_class_type;
00224     typedef recls_exception class_type;
00225 private:
00226 #if defined(RECLS_CHAR_TYPE_IS_CHAR)
00227     typedef string_t        string_type;
00228 #else /* ? RECLS_CHAR_TYPE_IS_??? */
00229     typedef string_a_t      string_type;
00230 #endif /* RECLS_CHAR_TYPE_IS_??? */
00232 
00235 public:
00237     explicit recls_exception(recls_rc_t rc)
00238         : m_rc(rc)
00239         , m_message(create_message_(rc))
00240     {}
00241 #ifdef STLSOFT_COMPILER_IS_GCC
00242     virtual ~recls_exception() throw()
00243     {}
00244 #endif /* STLSOFT_COMPILER_IS_GCC */
00246 
00249 public:
00251     recls_rc_t rc() const
00252     {
00253         return m_rc;
00254     }
00255 
00257     virtual char const *what() const throw()
00258     {
00259         return m_message.c_str();
00260     }
00262 
00265 private:
00266     static string_type create_message_(recls_rc_t rc)
00267     {
00268         stlsoft::auto_buffer<recls_char_t>  buffer(1 + recls::Recls_GetErrorString(rc, NULL, 0));
00269 
00270         recls::Recls_GetErrorString(rc, &buffer[0], buffer.size());
00271 
00272 #if defined(RECLS_CHAR_TYPE_IS_CHAR)
00273         return string_type(buffer.data(), buffer.size() - 1);
00274 # elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00275 
00276         size_t                      cbRequired = ::wcstombs(NULL, buffer.data(), buffer.size());
00277         stlsoft::auto_buffer<char>  abuffer(1 + cbRequired);    // If wcstombs failed, this'll be 0
00278 
00279         cbRequired = ::wcstombs(&abuffer[0], buffer.data(), abuffer.size());
00280             
00281         return string_type(abuffer.data(), cbRequired);
00282 
00283 #else /* ? RECLS_CHAR_TYPE_IS_??? */
00284 # error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00285 #endif /* RECLS_CHAR_TYPE_IS_??? */
00286     }
00288 
00291 private:
00292     const recls_rc_t    m_rc;
00293     const string_type   m_message;
00295 
00298 private:
00299     class_type &operator =(class_type const &);
00301 };
00302 
00303 /* /////////////////////////////////////////////////////////////////////////////
00304  * Functions
00305  */
00306 
00307 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00308 struct functions_impl
00309 {
00310     static string_t combine_paths(recls_char_t const *path1, recls_char_t const *path2)
00311     {
00312         stlsoft_ns_qual(auto_buffer)<recls_char_t>  result(Recls_CombinePaths(path1, path2, NULL, 0));
00313 
00314         Recls_CombinePaths(path1, path2, &result[0], result.size());
00315 
00316         return string_t(result.data(), result.size());
00317     }
00318     static string_t derive_relative_path(recls_char_t const *origin, recls_char_t const *target)
00319     {
00320         stlsoft_ns_qual(auto_buffer)<recls_char_t>  result(Recls_DeriveRelativePath(origin, target, NULL, 0));
00321 
00322         Recls_DeriveRelativePath(origin, target, &result[0], result.size());
00323 
00324         return string_t(result.data(), result.size());
00325     }
00326     static string_t squeeze_path(recls_char_t const *path, size_t width)
00327     {
00328         stlsoft_ns_qual(auto_buffer)<recls_char_t>  result(width);
00329         size_t                                      cch =   Recls_SqueezePath(path, &result[0], result.size());
00330 
00331 //      RECLS_ASSERT(cch <= result.size());
00332 
00333         return string_t(result.data(), cch);
00334     }
00335 };
00336 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00337 
00338 
00339 inline string_t combine_paths(string_t const &path1, string_t const &path2)
00340 {
00341     return functions_impl::combine_paths(stlsoft_ns_qual(c_str_ptr)(path1), stlsoft_ns_qual(c_str_ptr)(path2));
00342 }
00343 
00344 inline string_t derive_relative_path(string_t const &origin, string_t const &target)
00345 {
00346     return functions_impl::derive_relative_path(stlsoft_ns_qual(c_str_ptr)(origin), stlsoft_ns_qual(c_str_ptr)(target));
00347 }
00348 
00349 inline string_t squeeze_path(string_t const &path, size_t width)
00350 {
00351     return functions_impl::squeeze_path(stlsoft_ns_qual(c_str_ptr)(path), width);
00352 }
00353 
00354 /* /////////////////////////////////////////////////////////////////////////////
00355  * Namespace
00356  */
00357 
00358 #if !defined(RECLS_NO_NAMESPACE)
00359 } /* namespace stl */
00360 } /* namespace recls */
00361 namespace reclstl = ::recls::stl;
00362 #endif /* !RECLS_NO_NAMESPACE */
00363 
00364 /* ////////////////////////////////////////////////////////////////////////// */
00365 
00366 #endif /* !RECLS_INCL_RECLS_STL_HPP_RECLS */
00367 
00368 /* ////////////////////////////////////////////////////////////////////////// */

recls Library documentation © Synesis Software Pty Ltd, 2001-2006