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/cpp/recls.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        recls/cpp/recls.hpp
00003  *
00004  * Purpose:     recls C++ mapping.
00005  *
00006  * Created:     18th August 2003
00007  * Updated:     11th 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 
00041 #ifndef RECLS_INCL_RECLS_CPP_HPP_RECLSHPP
00042 #define RECLS_INCL_RECLS_CPP_HPP_RECLSHPP
00043 
00044 /* File version */
00045 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00046 # define RECLS_VER_RECLS_CPP_HPP_RECLSHPP_MAJOR     3
00047 # define RECLS_VER_RECLS_CPP_HPP_RECLSHPP_MINOR     0
00048 # define RECLS_VER_RECLS_CPP_HPP_RECLSHPP_REVISION  6
00049 # define RECLS_VER_RECLS_CPP_HPP_RECLSHPP_EDIT      25
00050 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00051 
00059 /* /////////////////////////////////////////////////////////////////////////////
00060  * Includes
00061  */
00062 
00063 #include <recls/recls.h>
00064 
00065 #if !defined(RECLS_VER_1_8_1) || \
00066     RECLS_VER < RECLS_VER_1_8_1
00067 # error The recls C++ mapping now requires version 1.8.1 or later of the recls core API
00068 #endif /* RECLS_VER < 1.8.1 */
00069 
00070 #include <stlsoft/stlsoft.h>    /* If the compiler cannot find this, you are not using STLSoft 1.9.1 or later, as required. */
00071 #if !defined(_STLSOFT_VER_1_9_1_B22)
00072 # error STLSoft version 1.9.1 (beta 22) or greater required. (www.stlsoft.org/downloads.html)
00073 #endif /* STLSoft version */
00074 
00075 #ifdef RECLS_CPP_STRING_HEADER
00076 # include RECLS_CPP_STRING_HEADER
00077 #else /* ? RECLS_CPP_STRING_HEADER */
00078 # include <string>
00079 #endif /* RECLS_STRING_HEADER */
00080 
00081 #if defined(RECLS_COMPILER_IS_DMC)
00082 # include <stlsoft/util/std/library_discriminator.hpp>  // For standard library detection
00083 #endif /* RECLS_COMPILER_IS_DMC */
00084 #include <stlsoft/memory/auto_buffer.hpp>
00085 
00086 #ifdef RECLS_CPP_METHOD_PROPERTY_SUPPORT
00087 # undef RECLS_CPP_METHOD_PROPERTY_SUPPORT
00088 #endif /* RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00089 
00090 #if defined(RECLS_CPP_FORCE_METHOD_PROPERTY_SUPPORT)
00091 # define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00092 #elif defined(RECLS_CPP_NO_METHOD_PROPERTY_SUPPORT)
00093  /* Do not define RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00094 #else /* ? RECLS_CPP_???_METHOD_PROPERTY_SUPPORT */
00095 # if defined(STLSOFT_COMPILER_IS_BORLAND)
00096  /* Do not define RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00097 # elif defined(STLSOFT_COMPILER_IS_DMC)
00098 #  if __DMC__ >= 0x0846
00099 #   define RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00100 #  endif /* __DMC__ */
00101 # elif defined(STLSOFT_COMPILER_IS_GCC) && \
00102        (   __GNUC__ >= 4 || \
00103            (   __GNUC__ == 3 && \
00104                __GNUC_MINOR__ >= 3))
00105 #  define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00106 # elif defined(STLSOFT_COMPILER_IS_INTEL)
00107 #  define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00108 # elif defined(STLSOFT_COMPILER_IS_MSVC)
00109 #  if _MSC_VER >= 1310
00110 #   define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00111 #  endif /* _MSC_VER */
00112 # elif defined(STLSOFT_COMPILER_IS_MWERKS)
00113 #  define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00114 # endif /* compiler */
00115 #endif /* RECLS_CPP_???_METHOD_PROPERTY_SUPPORT */
00116 
00117 #ifdef RECLS_CPP_METHOD_PROPERTY_SUPPORT
00118 # include <stlsoft/properties/method_properties.hpp>
00119 #endif /* RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00120 
00121 /* /////////////////////////////////////////////////////////////////////////////
00122  * Property Macros - borrowed from STLSoft's XMLSTL sub-project
00123  */
00124 
00125 #ifdef RECLS_CPP_METHOD_PROPERTY_SUPPORT
00126 # define RECLS_CPP_OPT_METHOD_PROPERTY_GET(V, R, C, GM, P)                  STLSOFT_METHOD_PROPERTY_GET(V, R, C, GM, P)
00127 # define RECLS_CPP_OPT_METHOD_PROPERTY_GET_PROP(R, C, GM, P)                STLSOFT_METHOD_PROPERTY_GET_EXTERNAL_PROP(R, C, GM, P)
00128 # define RECLS_CPP_OPT_METHOD_PROPERTY_GETSET(V, RG, RS, C, GM, SM, P)      STLSOFT_METHOD_PROPERTY_GETSET_EXTERNAL(RG, RS, C, GM, SM, P)
00129 # define RECLS_CPP_OPT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)                  STLSOFT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)
00130 # define RECLS_CPP_OPT_METHOD_PROPERTY_GETSET_PROP(RG, RS, C, GM, SM, P)    STLSOFT_METHOD_PROPERTY_GETSET_EXTERNAL_PROP(RG, RS, C, GM, SM, P)
00131 #else /* ? RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00132 # define RECLS_CPP_OPT_METHOD_PROPERTY_GET(V, R, C, GM, P)
00133 # define RECLS_CPP_OPT_METHOD_PROPERTY_GET_PROP(R, C, GM, P)
00134 # define RECLS_CPP_OPT_METHOD_PROPERTY_GETSET(V, RG, RS, C, GM, SM, P)
00135 # define RECLS_CPP_OPT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)
00136 # define RECLS_CPP_OPT_METHOD_PROPERTY_GETSET_PROP(RG, RS, C, GM, SM, P)
00137 #endif /* RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00138 
00139 /* /////////////////////////////////////////////////////////////////////////////
00140  * Namespace
00141  */
00142 
00143 #if !defined(RECLS_NO_NAMESPACE)
00144 namespace recls
00145 {
00146 
00147 namespace cpp
00148 {
00149 #endif /* !RECLS_NO_NAMESPACE */
00150 
00151 /* /////////////////////////////////////////////////////////////////////////////
00152  * Typedefs
00153  */
00154 
00155 #ifdef RECLS_DOCUMENTATION_SKIP_SECTION
00156 
00165 typedef std::string                     string_a_t;
00166 typedef std::wstring                    string_w_t;
00167 
00168 # if defined(RECLS_CHAR_TYPE_IS_CHAR)
00169 typedef string_a_t                      string_t;
00170 # elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00171 typedef string_w_t                      string_t;
00172 # else /* ? RECLS_CHAR_TYPE_IS_??? */
00173 #  error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00174 # endif /* RECLS_CHAR_TYPE_IS_??? */
00175 
00176 #else /* ? RECLS_DOCUMENTATION_SKIP_SECTION */
00177 
00178 # ifdef RECLS_CPP_STRING_HEADER
00179 #  ifndef RECLS_CPP_STRING_T
00180 #   error RECLS_CPP_STRING_T must be defined when RECLS_CPP_STRING_HEADER is defined
00181 #  endif /* !RECLS_STRING_T */
00182 typedef RECLS_CPP_STRING_T              string_t;
00183 # else
00184 #  if defined(RECLS_COMPILER_IS_DMC) && \
00185       !defined(STLSOFT_CF_STD_LIBRARY_IS_STLPORT)
00186 typedef string                          string_a_t;
00187 typedef wstring                         string_w_t;
00188 #  else /* ? compiler */
00189 typedef std::string                     string_a_t;
00190 typedef std::wstring                    string_w_t;
00191 #  endif /* compiler */
00192 #  if defined(RECLS_CHAR_TYPE_IS_CHAR)
00193 typedef string_a_t                      string_t;
00194 #  elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00195 typedef string_w_t                      string_t;
00196 #  else /* ? RECLS_CHAR_TYPE_IS_??? */
00197 #   error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00198 #  endif /* RECLS_CHAR_TYPE_IS_??? */
00199 # endif /* RECLS_STRING_HEADER */
00200 #endif /* RECLS_DOCUMENTATION_SKIP_SECTION */
00201 
00202 /* /////////////////////////////////////////////////////////////////////////////
00203  * Classes
00204  */
00205 
00207 class ReclsException
00208     : public std::exception
00209 {
00212 public:
00213     typedef std::exception  parent_class_type;
00214     typedef ReclsException  class_type;
00215 private:
00216 #if defined(RECLS_CHAR_TYPE_IS_CHAR)
00217     typedef string_t        string_type;
00218 #else /* ? RECLS_CHAR_TYPE_IS_??? */
00219     typedef string_a_t      string_type;
00220 #endif /* RECLS_CHAR_TYPE_IS_??? */
00222 
00225 public:
00227     explicit ReclsException(recls_rc_t rc)
00228         : m_rc(rc)
00229         , m_message(create_message_(rc))
00230     {}
00231 #ifdef STLSOFT_COMPILER_IS_GCC
00232     virtual ~ReclsException() throw()
00233     {}
00234 #endif /* STLSOFT_COMPILER_IS_GCC */
00236 
00239 public:
00241     recls_rc_t rc() const
00242     {
00243         return m_rc;
00244     }
00245 
00247     virtual char const *what() const throw()
00248     {
00249         return m_message.c_str();
00250     }
00252 
00255 private:
00256     static string_type create_message_(recls_rc_t rc)
00257     {
00258         stlsoft::auto_buffer<recls_char_t>  buffer(1 + recls::Recls_GetErrorString(rc, NULL, 0));
00259 
00260         recls::Recls_GetErrorString(rc, &buffer[0], buffer.size());
00261 
00262 #if defined(RECLS_CHAR_TYPE_IS_CHAR)
00263         return string_type(buffer.data(), buffer.size() - 1);
00264 # elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00265 
00266         size_t                      cbRequired = ::wcstombs(NULL, buffer.data(), buffer.size());
00267         stlsoft::auto_buffer<char>  abuffer(1 + cbRequired);    // If wcstombs failed, this'll be 0
00268 
00269         cbRequired = ::wcstombs(&abuffer[0], buffer.data(), abuffer.size());
00270             
00271         return string_type(abuffer.data(), cbRequired);
00272 
00273 #else /* ? RECLS_CHAR_TYPE_IS_??? */
00274 # error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00275 #endif /* RECLS_CHAR_TYPE_IS_??? */
00276     }
00278 
00281 private:
00282     const recls_rc_t    m_rc;
00283     const string_type   m_message;
00285 
00286 // Not to be implemented
00287 private:
00288     class_type &operator =(class_type const &);
00289 };
00290 
00291 /* /////////////////////////////////////////////////////////////////////////////
00292  * Namespace
00293  */
00294 
00295 #if !defined(RECLS_NO_NAMESPACE)
00296 } /* namespace cpp */
00297 } /* namespace recls */
00298 namespace reclspp = ::recls::cpp;
00299 #endif /* !RECLS_NO_NAMESPACE */
00300 
00301 /* ////////////////////////////////////////////////////////////////////////// */
00302 
00303 #endif /* !RECLS_INCL_RECLS_CPP_HPP_RECLSHPP */
00304 
00305 /* ////////////////////////////////////////////////////////////////////////// */

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