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:     8th September 2006
00008  *
00009  * Home:        http://recls.org/
00010  *
00011  * Copyright (c) 2003-2006, 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 3
00055 # define RECLS_VER_RECLS_STL_HPP_RECLS_EDIT     23
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_B22)
00078 # error STLSoft version 1.9.1 (beta 22) or greater required. (www.stlsoft.org/downloads.html)
00079 #endif /* STLSoft version */
00080 
00081 #ifdef RECLS_STL_STRING_HEADER
00082 # include RECLS_STL_STRING_HEADER
00083 #else /* ? RECLS_STL_STRING_HEADER */
00084 # include <string>
00085 #endif /* RECLS_STL_STRING_HEADER */
00086 
00087 #if defined(RECLS_COMPILER_IS_DMC)
00088 # include <stlsoft/util/std/library_discriminator.hpp>  // For standard library detection
00089 #endif /* RECLS_COMPILER_IS_DMC */
00090 #include <stlsoft/memory/auto_buffer.hpp>
00091 #include <stlsoft/shims/access/string.hpp>
00092 
00093 #ifdef RECLS_STL_METHOD_PROPERTY_SUPPORT
00094 # undef RECLS_STL_METHOD_PROPERTY_SUPPORT
00095 #endif /* RECLS_STL_METHOD_PROPERTY_SUPPORT */
00096 
00097 #if defined(RECLS_STL_FORCE_METHOD_PROPERTY_SUPPORT)
00098 # define RECLS_STL_METHOD_PROPERTY_SUPPORT
00099 #elif defined(RECLS_STL_NO_METHOD_PROPERTY_SUPPORT)
00100  /* Do not define RECLS_STL_METHOD_PROPERTY_SUPPORT */
00101 #else /* ? RECLS_STL_???_METHOD_PROPERTY_SUPPORT */
00102 # if defined(STLSOFT_COMPILER_IS_BORLAND)
00103  /* Do not define RECLS_STL_METHOD_PROPERTY_SUPPORT */
00104 # elif defined(STLSOFT_COMPILER_IS_DMC)
00105 #  if __DMC__ >= 0x0846
00106 #   define RECLS_STL_METHOD_PROPERTY_SUPPORT */
00107 #  endif /* __DMC__ */
00108  /* Do not define RECLS_STL_METHOD_PROPERTY_SUPPORT */
00109 # elif defined(STLSOFT_COMPILER_IS_GCC) && \
00110        (   __GNUC__ >= 4 || \
00111            (   __GNUC__ == 3 && \
00112                __GNUC_MINOR__ >= 3))
00113 #  define RECLS_STL_METHOD_PROPERTY_SUPPORT
00114 # elif defined(STLSOFT_COMPILER_IS_INTEL)
00115 #  define RECLS_STL_METHOD_PROPERTY_SUPPORT
00116 # elif defined(STLSOFT_COMPILER_IS_MSVC)
00117 #  if _MSC_VER >= 1310
00118 #   define RECLS_STL_METHOD_PROPERTY_SUPPORT
00119 #  endif /* _MSC_VER */
00120 # elif defined(STLSOFT_COMPILER_IS_MWERKS)
00121 #  define RECLS_STL_METHOD_PROPERTY_SUPPORT
00122 # endif /* compiler */
00123 #endif /* RECLS_STL_???_METHOD_PROPERTY_SUPPORT */
00124 
00125 #ifdef RECLS_STL_METHOD_PROPERTY_SUPPORT
00126 # include <stlsoft/method_properties.hpp>
00127 #endif /* RECLS_STL_METHOD_PROPERTY_SUPPORT */
00128 
00129 /* /////////////////////////////////////////////////////////////////////////////
00130  * Property Macros - borrowed from STLSoft's XMLSTL sub-project
00131  */
00132 
00133 #ifdef RECLS_STL_METHOD_PROPERTY_SUPPORT
00134 # define RECLS_STL_OPT_METHOD_PROPERTY_GET(V, R, C, GM, P)                  STLSOFT_METHOD_PROPERTY_GET(V, R, C, GM, P)
00135 # define RECLS_STL_OPT_METHOD_PROPERTY_GET_PROP(R, C, GM, P)                STLSOFT_METHOD_PROPERTY_GET_EXTERNAL_PROP(R, C, GM, P)
00136 # 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)
00137 # define RECLS_STL_OPT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)                  STLSOFT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)
00138 # 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)
00139 #else /* ? RECLS_STL_METHOD_PROPERTY_SUPPORT */
00140 # define RECLS_STL_OPT_METHOD_PROPERTY_GET(V, R, C, GM, P)
00141 # define RECLS_STL_OPT_METHOD_PROPERTY_GET_PROP(R, C, GM, P)
00142 # define RECLS_STL_OPT_METHOD_PROPERTY_GETSET(V, RG, RS, C, GM, SM, P)
00143 # define RECLS_STL_OPT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)
00144 # define RECLS_STL_OPT_METHOD_PROPERTY_GETSET_PROP(RG, RS, C, GM, SM, P)
00145 #endif /* RECLS_STL_METHOD_PROPERTY_SUPPORT */
00146 
00147 /* /////////////////////////////////////////////////////////////////////////////
00148  * Namespace
00149  */
00150 
00151 #if !defined(RECLS_NO_NAMESPACE)
00152 namespace recls
00153 {
00154 
00155 namespace stl
00156 {
00157 #endif /* !RECLS_NO_NAMESPACE */
00158 
00159 /* /////////////////////////////////////////////////////////////////////////////
00160  * Typedefs
00161  */
00162 
00163 #ifdef RECLS_DOCUMENTATION_SKIP_SECTION
00164 
00173 typedef std::string             string_t;
00174 
00175 #else /* ? RECLS_DOCUMENTATION_SKIP_SECTION */
00176 
00177 # ifdef RECLS_STL_STRING_HEADER
00178 #  ifndef RECLS_STL_STRING_T
00179 #   error RECLS_STL_STRING_T must be defined when RECLS_STL_STRING_HEADER is defined
00180 #  endif /* !RECLS_STRING_T */
00181 typedef RECLS_STL_STRING_T          string_t;
00182 # else /* ? RECLS_STRING_HEADER */
00183 typedef stlsoft_ns_qual_std(string) string_t;
00184 # endif /* RECLS_STRING_HEADER */
00185 #endif /* RECLS_DOCUMENTATION_SKIP_SECTION */
00186 
00187 /* /////////////////////////////////////////////////////////////////////////////
00188  * Classes
00189  */
00190 
00192 class recls_exception
00193     : public std::exception
00194 {
00197 public:
00198     typedef std::exception      parent_class_type;
00199     typedef recls_exception  class_type;
00201 
00204 public:
00206     explicit recls_exception(recls_rc_t rc)
00207         : m_rc(rc)
00208         , m_message(create_message_(rc))
00209     {}
00210 #ifdef STLSOFT_COMPILER_IS_GCC
00211     virtual ~recls_exception() throw()
00212     {}
00213 #endif /* STLSOFT_COMPILER_IS_GCC */
00215 
00218 public:
00220     recls_rc_t rc() const
00221     {
00222         return m_rc;
00223     }
00224 
00226     virtual char const *what() const throw()
00227     {
00228         return m_message.c_str();
00229     }
00231 
00234 private:
00235     static string_t create_message_(recls_rc_t rc)
00236     {
00237         string_t    msg(recls::Recls_GetErrorString(rc, NULL, 0), '~');
00238 
00239         recls::Recls_GetErrorString(rc, &msg[0], msg.size());
00240 
00241         return msg;
00242     }
00244 
00247 private:
00248     const recls_rc_t    m_rc;
00249     const string_t      m_message;
00251 
00254 private:
00255     class_type &operator =(class_type const &);
00257 };
00258 
00259 /* /////////////////////////////////////////////////////////////////////////////
00260  * Functions
00261  */
00262 
00263 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00264 struct functions_impl
00265 {
00266     static string_t combine_paths(recls_char_t const *path1, recls_char_t const *path2)
00267     {
00268         stlsoft_ns_qual(auto_buffer)<recls_char_t>  result(Recls_CombinePaths(path1, path2, NULL, 0));
00269 
00270         Recls_CombinePaths(path1, path2, &result[0], result.size());
00271 
00272         return string_t(result.data(), result.size());
00273     }
00274     static string_t derive_relative_path(recls_char_t const *origin, recls_char_t const *target)
00275     {
00276         stlsoft_ns_qual(auto_buffer)<recls_char_t>  result(Recls_DeriveRelativePath(origin, target, NULL, 0));
00277 
00278         Recls_DeriveRelativePath(origin, target, &result[0], result.size());
00279 
00280         return string_t(result.data(), result.size());
00281     }
00282     static string_t squeeze_path(recls_char_t const *path, size_t width)
00283     {
00284         stlsoft_ns_qual(auto_buffer)<recls_char_t>  result(width);
00285         size_t                                      cch =   Recls_SqueezePath(path, &result[0], result.size());
00286 
00287 //      RECLS_ASSERT(cch <= result.size());
00288 
00289         return string_t(result.data(), cch);
00290     }
00291 };
00292 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00293 
00294 
00295 inline string_t combine_paths(string_t const &path1, string_t const &path2)
00296 {
00297     return functions_impl::combine_paths(stlsoft_ns_qual(c_str_ptr)(path1), stlsoft_ns_qual(c_str_ptr)(path2));
00298 }
00299 
00300 inline string_t derive_relative_path(string_t const &origin, string_t const &target)
00301 {
00302     return functions_impl::derive_relative_path(stlsoft_ns_qual(c_str_ptr)(origin), stlsoft_ns_qual(c_str_ptr)(target));
00303 }
00304 
00305 inline string_t squeeze_path(string_t const &path, size_t width)
00306 {
00307     return functions_impl::squeeze_path(stlsoft_ns_qual(c_str_ptr)(path), width);
00308 }
00309 
00310 /* /////////////////////////////////////////////////////////////////////////////
00311  * Namespace
00312  */
00313 
00314 #if !defined(RECLS_NO_NAMESPACE)
00315 } /* namespace stl */
00316 } /* namespace recls */
00317 namespace reclstl = ::recls::stl;
00318 #endif /* !RECLS_NO_NAMESPACE */
00319 
00320 /* ////////////////////////////////////////////////////////////////////////// */
00321 
00322 #endif /* !RECLS_INCL_RECLS_STL_HPP_RECLS */
00323 
00324 /* ////////////////////////////////////////////////////////////////////////// */

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