Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

pantheios/util/string/strdup.h

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/util/string/strdup.h (formerly part of pantheios/pantheios.h)
00003  *
00004  * Purpose:     String duplication utilty functions.
00005  *
00006  * Created:     19th April 2008
00007  * Updated:     22nd March 2010
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 2008-2010, 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
00016  * met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice,
00019  *   this list of conditions and the following disclaimer.
00020  * - Redistributions in binary form must reproduce the above copyright
00021  *   notice, this list of conditions and the following disclaimer in the
00022  *   documentation and/or other materials provided with the distribution.
00023  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
00024  *   names of any contributors may be used to endorse or promote products
00025  *   derived from this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00028  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00029  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00031  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00036  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  * ////////////////////////////////////////////////////////////////////// */
00040 
00041 
00047 #ifndef PANTHEIOS_INCL_PANTHEIOS_UTIL_STRING_H_STRDUP
00048 #define PANTHEIOS_INCL_PANTHEIOS_UTIL_STRING_H_STRDUP
00049 
00050 /* /////////////////////////////////////////////////////////////////////////
00051  * Version information
00052  */
00053 
00054 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00055 # define PANTHEIOS_VER_PANTHEIOS_UTIL_STRING_H_STRDUP_MAJOR     1
00056 # define PANTHEIOS_VER_PANTHEIOS_UTIL_STRING_H_STRDUP_MINOR     2
00057 # define PANTHEIOS_VER_PANTHEIOS_UTIL_STRING_H_STRDUP_REVISION  2
00058 # define PANTHEIOS_VER_PANTHEIOS_UTIL_STRING_H_STRDUP_EDIT      6
00059 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00060 
00061 /* /////////////////////////////////////////////////////////////////////////
00062  * Includes
00063  */
00064 
00065 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00066 # include <pantheios/pantheios.h>
00067 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00068 
00069 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00070 # include <stlsoft/stlsoft.h>
00071 #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
00072 
00073 /* Standard C & C++ header files */
00074 #ifdef STLSOFT_CF_THROW_BAD_ALLOC
00075 # include <new>
00076 # ifdef STLSOFT_COMPILER_IS_BORLAND
00077 #  include <memory.h>
00078 # endif /* compiler */
00079 #endif /* STLSOFT_CF_THROW_BAD_ALLOC */
00080 
00081 /* /////////////////////////////////////////////////////////////////////////
00082  * API
00083  */
00084 
00085 #if !defined(PANTHEIOS_NO_NAMESPACE)
00086 namespace pantheios
00087 {
00088 #endif /* !PANTHEIOS_NO_NAMESPACE */
00089 
00090 /* /////////////////////////////////////////////////////////////////////////
00091  * API
00092  */
00093 
00103 PANTHEIOS_CALL(pan_char_t*) pantheios_util_strdup_nothrow(pan_char_t const* s) /* stlsoft_throw_0() */;
00104 
00110 PANTHEIOS_CALL(void) pantheios_util_strfree(pan_char_t* s) /* stlsoft_throw_0() */;
00111 
00112 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00113 PANTHEIOS_CALL(char*) pantheios_util_strdup_nothrow_m(char const* s) /* stlsoft_throw_0() */;
00114 PANTHEIOS_CALL(void) pantheios_util_strfree_m(char* s) /* stlsoft_throw_0() */;
00115 
00116 PANTHEIOS_CALL(wchar_t*) pantheios_util_strdup_nothrow_w(wchar_t const* s) /* stlsoft_throw_0() */;
00117 PANTHEIOS_CALL(void) pantheios_util_strfree_w(wchar_t* s) /* stlsoft_throw_0() */;
00118 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00119 
00120 /* /////////////////////////////////////////////////////////////////////////
00121  * API (C++)
00122  */
00123 
00124 #if defined(__cplusplus) && \
00125     defined(STLSOFT_CF_THROW_BAD_ALLOC)
00126 
00136 inline pan_char_t* pantheios_util_strdup_throw(pan_char_t const* s)
00137 {
00138     pan_char_t* s2 = pantheios_util_strdup_nothrow(s);
00139 
00140     if( NULL == s2 &&
00141         NULL != s)
00142     {
00143         throw std::bad_alloc();
00144     }
00145 
00146     return s2;
00147 }
00148 #endif /* C++ && exceptions */
00149 
00150 
00151 #if !defined(PANTHEIOS_NO_NAMESPACE)
00152 namespace util
00153 {
00154 
00159 inline pan_char_t* strdup_nothrow(pan_char_t const* s) stlsoft_throw_0()
00160 {
00161     return pantheios_util_strdup_nothrow(s);
00162 }
00163 
00164 # if defined(STLSOFT_CF_THROW_BAD_ALLOC)
00165 
00169 inline pan_char_t* strdup_throw(pan_char_t const* s)
00170 {
00171     return pantheios_util_strdup_throw(s);
00172 }
00173 # endif /* exceptions */
00174 
00179 inline void strfree(pan_char_t* s) stlsoft_throw_0()
00180 {
00181     pantheios_util_strfree(s);
00182 }
00183 
00184 } /* namespace util */
00185 #endif /* !PANTHEIOS_NO_NAMESPACE */
00186 
00187 /* /////////////////////////////////////////////////////////////////////////
00188  * Namespace
00189  */
00190 
00191 #if !defined(PANTHEIOS_NO_NAMESPACE)
00192 } /* namespace pantheios */
00193 #endif /* !PANTHEIOS_NO_NAMESPACE */
00194 
00195 /* /////////////////////////////////////////////////////////////////////////
00196  * Inclusion
00197  */
00198 
00199 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00200 # pragma once
00201 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00202 
00203 /* ////////////////////////////////////////////////////////////////////// */
00204 
00205 #endif /* !PANTHEIOS_INCL_PANTHEIOS_UTIL_STRING_H_STRDUP */
00206 
00207 /* ///////////////////////////// end of file //////////////////////////// */

pantheios Library documentation Matthew Wilson & Synesis Software, 2006-2011 SourceForge.net Logo