Open-RJ C/C++ User's Journal Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

openrj/stl/openrj.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:    openrj/stl/openrj.hpp
00003  *
00004  * Purpose: Root header file for the STL mapping of the Open-RJ library
00005  *
00006  * Created: 28th September 2004
00007  * Updated: 13th July 2006
00008  *
00009  * Home:    http://openrj.org/
00010  *
00011  * Copyright (c) 2004-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 names 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 OPENRJ_INCL_OPENRJ_STL_HPP_OPENRJ
00048 #define OPENRJ_INCL_OPENRJ_STL_HPP_OPENRJ
00049 
00050 /* /////////////////////////////////////////////////////////////////////////////
00051  * Version information
00052  */
00053 
00054 #ifndef OPENRJ_DOCUMENTATION_SKIP_SECTION
00055 # define OPENRJ_VER_OPENRJ_STL_HPP_OPENRJ_MAJOR     1
00056 # define OPENRJ_VER_OPENRJ_STL_HPP_OPENRJ_MINOR     4
00057 # define OPENRJ_VER_OPENRJ_STL_HPP_OPENRJ_REVISION  2
00058 # define OPENRJ_VER_OPENRJ_STL_HPP_OPENRJ_EDIT      19
00059 #endif /* !OPENRJ_DOCUMENTATION_SKIP_SECTION */
00060 
00061 /* /////////////////////////////////////////////////////////////////////////////
00062  * Includes
00063  */
00064 
00065 #include <openrj/openrj.h>
00066 #include <openrj/openrj_assert.h>
00067 
00068 #ifdef OPENRJ_DOCUMENTATION_SKIP_SECTION
00069 # include <openrj/stl/openrjfwd.hpp>
00070 #endif /* !OPENRJ_DOCUMENTATION_SKIP_SECTION */
00071 
00072 
00073 #if defined(ORJ_NO_EXCEPTIONS)
00074 # error The Open-RJ STL mapping is not compilable in the absence of exceptions
00075 #endif /* ORJ_NO_EXCEPTIONS */
00076 
00077 #include <stlsoft/stlsoft.h>
00078 
00079 #if !defined(_STLSOFT_VER_1_9_1)
00080 # error STLSoft version 1.9.1 or greater required. (www.stlsoft.org/downloads.html)
00081 #endif /* STLSoft version */
00082 
00083 #include <stlsoft/conversion/integer_to_string.hpp>
00084 
00085 #include <exception>
00086 #if defined(OPENRJ_USE_CUSTOM_STRING)
00087 # include OPENRJ_CUSTOM_STRING_INCLUDE
00088 #else /* OPENRJ_USE_CUSTOM_STRING */
00089 # include <string>
00090 #endif /* !OPENRJ_USE_CUSTOM_STRING */
00091 
00092 #include <string.h>
00093 
00094 /* /////////////////////////////////////////////////////////////////////////////
00095  * Compiler warnings
00096  */
00097 
00098 #ifdef __BORLANDC__
00099 # pragma warn -8027
00100 #endif /* __BORLANDC__ */
00101 
00102 /* /////////////////////////////////////////////////////////////////////////////
00103  * Namespace
00104  */
00105 
00106 namespace openrj
00107 {
00108 namespace stl
00109 {
00110 
00111 /* /////////////////////////////////////////////////////////////////////////////
00112  * Typedefs
00113  */
00114 
00116 #if defined(OPENRJ_USE_CUSTOM_STRING)
00117 typedef OPENRJ_CUSTOM_STRING_TYPE       string_t;
00118 #else /* OPENRJ_USE_CUSTOM_STRING */
00119 typedef std::string                     string_t;
00120 #endif /* !OPENRJ_USE_CUSTOM_STRING */
00121 
00122 /* /////////////////////////////////////////////////////////////////////////////
00123  * Classes
00124  */
00125 
00127 class database_exception
00128     : public std::exception
00129 {
00132 public:
00133     typedef std::exception      parent_class_type;
00134     typedef database_exception  class_type;
00136 
00139 public:
00141     database_exception(ORJRC rc, ORJError const &error)
00142         : m_rc(rc)
00143         , m_error(error)
00144         , m_message(create_message_(rc, error))
00145     {}
00146 #ifdef STLSOFT_COMPILER_IS_GCC
00147     virtual ~database_exception() throw()
00148     {}
00149 #endif /* compiler */
00151 
00154 public:
00156     ORJRC rc() const
00157     {
00158         return m_rc;
00159     }
00161     ORJError const &error() const
00162     {
00163         return m_error;
00164     }
00165 
00167     virtual char const *what() const throw()
00168     {
00169         return (ORJ_RC_PARSEERROR == m_rc) ? m_message.c_str() : ORJ_GetErrorStringA(m_rc);
00170     }
00172 
00175 private:
00176     static string_t create_message_(ORJRC rc, ORJError const &error)
00177     {
00178         string_t    s;
00179 
00180         if(ORJ_RC_PARSEERROR == rc)
00181         {
00182             char    message[201];
00183             char    sz1[21];
00184             char    sz2[21];
00185 
00186             // This was originally all done with string class methods, but it causes a
00187             // ridiculous number of reallocations, so we do it the old crusty way
00188             ::strcpy(message, "' at line ");
00189             ::strcat(message, ::stlsoft::integer_to_string(&sz1[0], stlsoft_num_elements(sz1), error.invalidLine));
00190             ::strcat(message, " column ");
00191             ::strcat(message, ::stlsoft::integer_to_string(&sz2[0], stlsoft_num_elements(sz2), error.invalidColumn));
00192 
00193             s   =   "Parse error '";
00194             s   +=  ORJ_GetParseErrorStringA(error.parseError);
00195             s   +=  message;
00196         }
00197 
00198         return s;
00199     }
00201 
00204 private:
00205     ORJRC           m_rc;
00206     ORJError        m_error;
00207     const string_t  m_message;
00209 
00210 // Not to be implemented
00211 private:
00212     class_type &operator =(class_type const &);
00213 };
00214 
00215 /* /////////////////////////////////////////////////////////////////////////////
00216  * Namespace
00217  */
00218 
00219 } // namespace stl
00220 } // namespace openrj
00221 
00222 /* ////////////////////////////////////////////////////////////////////////// */
00223 
00224 #endif /* !OPENRJ_INCL_OPENRJ_STL_HPP_OPENRJ */
00225 
00226 /* ////////////////////////////////////////////////////////////////////////// */

Open-RJ Library documentation © Synesis Software Pty Ltd, 2004-2005