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:     1st 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 
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  7
00049 # define RECLS_VER_RECLS_CPP_HPP_RECLSHPP_EDIT      27
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) || \
00072     _STLSOFT_VER < _STLSOFT_VER_1_9_1
00073 # error Requires STLSoft 1.9.1, or later. (www.stlsoft.org/downloads.html)
00074 #endif /* STLSoft version */
00075 
00076 #ifdef RECLS_CPP_STRING_HEADER
00077 # include RECLS_CPP_STRING_HEADER
00078 #else /* ? RECLS_CPP_STRING_HEADER */
00079 # include <string>
00080 #endif /* RECLS_STRING_HEADER */
00081 
00082 #if defined(RECLS_COMPILER_IS_DMC)
00083 # include <stlsoft/util/std/library_discriminator.hpp>  // For standard library detection
00084 #endif /* RECLS_COMPILER_IS_DMC */
00085 #include <stlsoft/memory/auto_buffer.hpp>
00086 
00087 #ifdef RECLS_CPP_METHOD_PROPERTY_SUPPORT
00088 # undef RECLS_CPP_METHOD_PROPERTY_SUPPORT
00089 #endif /* RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00090 
00091 #if defined(RECLS_CPP_FORCE_METHOD_PROPERTY_SUPPORT)
00092 # define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00093 #elif defined(RECLS_CPP_NO_METHOD_PROPERTY_SUPPORT)
00094  /* Do not define RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00095 #else /* ? RECLS_CPP_???_METHOD_PROPERTY_SUPPORT */
00096 # if defined(STLSOFT_COMPILER_IS_BORLAND)
00097  /* Do not define RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00098 # elif defined(STLSOFT_COMPILER_IS_DMC)
00099 #  if __DMC__ >= 0x0846
00100 #   define RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00101 #  endif /* __DMC__ */
00102 # elif defined(STLSOFT_COMPILER_IS_GCC) && \
00103        (   __GNUC__ >= 4 || \
00104            (   __GNUC__ == 3 && \
00105                __GNUC_MINOR__ >= 3))
00106 #  define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00107 # elif defined(STLSOFT_COMPILER_IS_INTEL)
00108 #  define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00109 # elif defined(STLSOFT_COMPILER_IS_MSVC)
00110 #  if _MSC_VER >= 1310
00111 #   define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00112 #  endif /* _MSC_VER */
00113 # elif defined(STLSOFT_COMPILER_IS_MWERKS)
00114 #  define RECLS_CPP_METHOD_PROPERTY_SUPPORT
00115 # endif /* compiler */
00116 #endif /* RECLS_CPP_???_METHOD_PROPERTY_SUPPORT */
00117 
00118 #ifdef RECLS_CPP_METHOD_PROPERTY_SUPPORT
00119 # include <stlsoft/properties/method_properties.hpp>
00120 #endif /* RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00121 
00122 /* /////////////////////////////////////////////////////////////////////////////
00123  * Property Macros - borrowed from STLSoft's XMLSTL sub-project
00124  */
00125 
00126 #ifdef RECLS_CPP_METHOD_PROPERTY_SUPPORT
00127 # define RECLS_CPP_OPT_METHOD_PROPERTY_GET(V, R, C, GM, P)                  STLSOFT_METHOD_PROPERTY_GET(V, R, C, GM, P)
00128 # define RECLS_CPP_OPT_METHOD_PROPERTY_GET_PROP(R, C, GM, P)                STLSOFT_METHOD_PROPERTY_GET_EXTERNAL_PROP(R, C, GM, P)
00129 # 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)
00130 # define RECLS_CPP_OPT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)                  STLSOFT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)
00131 # 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)
00132 #else /* ? RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00133 # define RECLS_CPP_OPT_METHOD_PROPERTY_GET(V, R, C, GM, P)
00134 # define RECLS_CPP_OPT_METHOD_PROPERTY_GET_PROP(R, C, GM, P)
00135 # define RECLS_CPP_OPT_METHOD_PROPERTY_GETSET(V, RG, RS, C, GM, SM, P)
00136 # define RECLS_CPP_OPT_METHOD_PROPERTY_DEFINE_OFFSET(C, P)
00137 # define RECLS_CPP_OPT_METHOD_PROPERTY_GETSET_PROP(RG, RS, C, GM, SM, P)
00138 #endif /* RECLS_CPP_METHOD_PROPERTY_SUPPORT */
00139 
00140 /* /////////////////////////////////////////////////////////////////////////////
00141  * Namespace
00142  */
00143 
00144 #if !defined(RECLS_NO_NAMESPACE)
00145 namespace recls
00146 {
00147 
00148 namespace cpp
00149 {
00150 #endif /* !RECLS_NO_NAMESPACE */
00151 
00152 /* /////////////////////////////////////////////////////////////////////////////
00153  * Typedefs
00154  */
00155 
00156 #ifdef RECLS_DOCUMENTATION_SKIP_SECTION
00157 
00166 typedef std::string                     string_a_t;
00167 typedef std::wstring                    string_w_t;
00168 
00169 # if defined(RECLS_CHAR_TYPE_IS_CHAR)
00170 typedef string_a_t                      string_t;
00171 # elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00172 typedef string_w_t                      string_t;
00173 # else /* ? RECLS_CHAR_TYPE_IS_??? */
00174 #  error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00175 # endif /* RECLS_CHAR_TYPE_IS_??? */
00176 
00177 #else /* ? RECLS_DOCUMENTATION_SKIP_SECTION */
00178 
00179 # ifdef RECLS_CPP_STRING_HEADER
00180 #  ifndef RECLS_CPP_STRING_T
00181 #   error RECLS_CPP_STRING_T must be defined when RECLS_CPP_STRING_HEADER is defined
00182 #  endif /* !RECLS_STRING_T */
00183 typedef RECLS_CPP_STRING_T              string_t;
00184 # else
00185 #  if defined(RECLS_COMPILER_IS_DMC) && \
00186       !defined(STLSOFT_CF_STD_LIBRARY_IS_STLPORT)
00187 typedef string                          string_a_t;
00188 typedef wstring                         string_w_t;
00189 #  else /* ? compiler */
00190 typedef std::string                     string_a_t;
00191 typedef std::wstring                    string_w_t;
00192 #  endif /* compiler */
00193 #  if defined(RECLS_CHAR_TYPE_IS_CHAR)
00194 typedef string_a_t                      string_t;
00195 #  elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00196 typedef string_w_t                      string_t;
00197 #  else /* ? RECLS_CHAR_TYPE_IS_??? */
00198 #   error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00199 #  endif /* RECLS_CHAR_TYPE_IS_??? */
00200 # endif /* RECLS_STRING_HEADER */
00201 
00202 #endif /* RECLS_DOCUMENTATION_SKIP_SECTION */
00203 
00204 /* /////////////////////////////////////////////////////////////////////////////
00205  * Classes
00206  */
00207 
00209 class ReclsException
00210     : public std::exception
00211 {
00214 public:
00215     typedef std::exception  parent_class_type;
00216     typedef ReclsException  class_type;
00217 private:
00218 #if defined(RECLS_CHAR_TYPE_IS_CHAR)
00219     typedef string_t        string_type;
00220 #else /* ? RECLS_CHAR_TYPE_IS_??? */
00221     typedef string_a_t      string_type;
00222 #endif /* RECLS_CHAR_TYPE_IS_??? */
00224 
00227 public:
00229     explicit ReclsException(recls_rc_t rc)
00230         : m_rc(rc)
00231         , m_message(create_message_(rc))
00232     {}
00233 #ifdef STLSOFT_COMPILER_IS_GCC
00234     virtual ~ReclsException() throw()
00235     {}
00236 #endif /* STLSOFT_COMPILER_IS_GCC */
00238 
00241 public:
00243     recls_rc_t rc() const
00244     {
00245         return m_rc;
00246     }
00247 
00249     virtual char const *what() const throw()
00250     {
00251         return m_message.c_str();
00252     }
00254 
00257 private:
00258     static string_type create_message_(recls_rc_t rc)
00259     {
00260         stlsoft::auto_buffer<recls_char_t>  buffer(1 + recls::Recls_GetErrorString(rc, NULL, 0));
00261 
00262         recls::Recls_GetErrorString(rc, &buffer[0], buffer.size());
00263 
00264 #if defined(RECLS_CHAR_TYPE_IS_CHAR)
00265         return string_type(buffer.data(), buffer.size() - 1);
00266 # elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00267 
00268         size_t                      cbRequired = ::wcstombs(NULL, buffer.data(), buffer.size());
00269         stlsoft::auto_buffer<char>  abuffer(1 + cbRequired);    // If wcstombs failed, this'll be 0
00270 
00271         cbRequired = ::wcstombs(&abuffer[0], buffer.data(), abuffer.size());
00272             
00273         return string_type(abuffer.data(), cbRequired);
00274 
00275 #else /* ? RECLS_CHAR_TYPE_IS_??? */
00276 # error RECLS_CHAR_TYPE_IS_CHAR or RECLS_CHAR_TYPE_IS_WCHAR must be defined.
00277 #endif /* RECLS_CHAR_TYPE_IS_??? */
00278     }
00280 
00283 private:
00284     const recls_rc_t    m_rc;
00285     const string_type   m_message;
00287 
00288 // Not to be implemented
00289 private:
00290     class_type &operator =(class_type const &);
00291 };
00292 
00293 /* /////////////////////////////////////////////////////////////////////////////
00294  * Namespace
00295  */
00296 
00297 #if !defined(RECLS_NO_NAMESPACE)
00298 } /* namespace cpp */
00299 } /* namespace recls */
00300 namespace reclspp = ::recls::cpp;
00301 #endif /* !RECLS_NO_NAMESPACE */
00302 
00303 /* ////////////////////////////////////////////////////////////////////////// */
00304 
00305 #endif /* !RECLS_INCL_RECLS_CPP_HPP_RECLSHPP */
00306 
00307 /* ////////////////////////////////////////////////////////////////////////// */

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