00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: mfcstl/shims/access/string/cstring.hpp 00003 * 00004 * Purpose: Contains classes and functions for dealing with MFC strings. 00005 * 00006 * Created: 24th May 2002 00007 * Updated: 10th August 2009 00008 * 00009 * Home: http://stlsoft.org/ 00010 * 00011 * Copyright (c) 2002-2009, 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 00048 #ifndef MFCSTL_INCL_MFCSTL_SHIMS_ACCESS_STRING_HPP_CSTRING 00049 #define MFCSTL_INCL_MFCSTL_SHIMS_ACCESS_STRING_HPP_CSTRING 00050 00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION 00052 # define MFCSTL_VER_MFCSTL_SHIMS_ACCESS_STRING_HPP_CSTRING_MAJOR 4 00053 # define MFCSTL_VER_MFCSTL_SHIMS_ACCESS_STRING_HPP_CSTRING_MINOR 0 00054 # define MFCSTL_VER_MFCSTL_SHIMS_ACCESS_STRING_HPP_CSTRING_REVISION 1 00055 # define MFCSTL_VER_MFCSTL_SHIMS_ACCESS_STRING_HPP_CSTRING_EDIT 89 00056 #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */ 00057 00058 /* ///////////////////////////////////////////////////////////////////////// 00059 * Includes 00060 */ 00061 00062 #ifndef MFCSTL_INCL_MFCSTL_HPP_MFCSTL 00063 # include <mfcstl/mfcstl.hpp> 00064 #endif /* !MFCSTL_INCL_MFCSTL_HPP_MFCSTL */ 00065 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING 00066 # include <stlsoft/shims/access/string.hpp> 00067 #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */ 00068 00069 /* ///////////////////////////////////////////////////////////////////////// 00070 * Namespace 00071 */ 00072 00073 #ifndef _MFCSTL_NO_NAMESPACE 00074 # if defined(_STLSOFT_NO_NAMESPACE) || \ 00075 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) 00076 /* There is no stlsoft namespace, so must define ::mfcstl */ 00077 namespace mfcstl 00078 { 00079 # else 00080 /* Define stlsoft::mfcstl_project */ 00081 00082 namespace stlsoft 00083 { 00084 00085 namespace mfcstl_project 00086 { 00087 00088 # endif /* _STLSOFT_NO_NAMESPACE */ 00089 #endif /* !_MFCSTL_NO_NAMESPACE */ 00090 00091 /* ///////////////////////////////////////////////////////////////////////// 00092 * c_str_data 00093 * 00094 * This can be applied to an expression, and the return value is either a 00095 * pointer to the character string or to an empty string. 00096 */ 00097 00098 /* CString */ 00104 inline LPCTSTR c_str_data(CString const& s) 00105 { 00106 /* CString always points to valid memory, whether its own 00107 * CStringData or afxEmptyString.m_pchData 00108 */ 00109 return s; 00110 } 00111 #if defined(UNICODE) 00112 inline LPCTSTR c_str_data_w(CString const& s) 00113 #else /* ? UNICODE */ 00114 inline LPCTSTR c_str_data_a(CString const& s) 00115 #endif /* UNICODE */ 00116 { 00117 return c_str_data(s); 00118 } 00119 00120 /* ///////////////////////////////////////////////////////////////////////// 00121 * c_str_len 00122 * 00123 * This can be applied to an expression, and the return value is the number of 00124 * characters in the character string in the expression. 00125 */ 00126 00127 /* CString */ 00133 inline ms_size_t c_str_len(CString const& s) 00134 { 00135 return s.GetLength(); 00136 } 00137 00138 #if defined(UNICODE) 00139 inline ms_size_t c_str_len_w(CString const& s) 00140 #else /* ? UNICODE */ 00141 inline ms_size_t c_str_len_a(CString const& s) 00142 #endif /* UNICODE */ 00143 { 00144 return c_str_len(s); 00145 } 00146 00147 /* ///////////////////////////////////////////////////////////////////////// 00148 * c_str_ptr 00149 * 00150 * This can be applied to an expression, and the return value is either a 00151 * pointer to the character string or to an empty string. 00152 */ 00153 00154 /* CString */ 00160 inline LPCTSTR c_str_ptr(CString const& s) 00161 { 00162 /* CString always points to valid memory, whether its own 00163 * CStringData or afxEmptyString.m_pchData 00164 */ 00165 return s; 00166 } 00167 #if defined(UNICODE) 00168 inline LPCTSTR c_str_ptr_w(CString const& s) 00169 #else /* ? UNICODE */ 00170 inline LPCTSTR c_str_ptr_a(CString const& s) 00171 #endif /* UNICODE */ 00172 { 00173 return c_str_ptr(s); 00174 } 00175 00176 /* ///////////////////////////////////////////////////////////////////////// 00177 * c_str_ptr_null 00178 * 00179 * This can be applied to an expression, and the return value is either a 00180 * pointer to the character string or NULL. 00181 */ 00182 00183 /* CString */ 00189 inline LPCTSTR c_str_ptr_null(CString const& s) 00190 { 00191 /* CString always points to valid memory, whether its own 00192 * CStringData or afxEmptyString.m_pchData 00193 */ 00194 return s.IsEmpty() ? NULL : (LPCTSTR)s; 00195 } 00196 #if defined(UNICODE) 00197 inline LPCTSTR c_str_ptr_null_w(CString const& s) 00198 #else /* ? UNICODE */ 00199 inline LPCTSTR c_str_ptr_null_a(CString const& s) 00200 #endif /* UNICODE */ 00201 { 00202 return c_str_ptr_null(s); 00203 } 00204 00206 // Unit-testing 00207 00208 #ifdef STLSOFT_UNITTEST 00209 # include "./unittest/cstring_unittest_.h" 00210 #endif /* STLSOFT_UNITTEST */ 00211 00212 /* ////////////////////////////////////////////////////////////////////// */ 00213 00214 #ifndef _MFCSTL_NO_NAMESPACE 00215 # if defined(_STLSOFT_NO_NAMESPACE) || \ 00216 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) 00217 } // namespace mfcstl 00218 # else 00219 } // namespace stlsoft::mfcstl_project 00220 } // namespace stlsoft 00221 # endif /* _STLSOFT_NO_NAMESPACE */ 00222 #endif /* !_MFCSTL_NO_NAMESPACE */ 00223 00224 /* ///////////////////////////////////////////////////////////////////////// 00225 * Namespace 00226 * 00227 * The string access shims exist either in the stlsoft namespace, or in the 00228 * global namespace. This is required by the lookup rules. 00229 * 00230 */ 00231 00232 #ifndef _MFCSTL_NO_NAMESPACE 00233 # if !defined(_STLSOFT_NO_NAMESPACE) && \ 00234 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) 00235 namespace stlsoft 00236 { 00237 # else /* ? _STLSOFT_NO_NAMESPACE */ 00238 /* There is no stlsoft namespace, so must define in the global namespace */ 00239 # endif /* !_STLSOFT_NO_NAMESPACE */ 00240 00241 using ::mfcstl::c_str_data; 00242 #if defined(UNICODE) 00243 using ::mfcstl::c_str_data_w; 00244 #else /* ? UNICODE */ 00245 using ::mfcstl::c_str_data_a; 00246 #endif /* UNICODE */ 00247 00248 using ::mfcstl::c_str_len; 00249 #if defined(UNICODE) 00250 using ::mfcstl::c_str_len_w; 00251 #else /* ? UNICODE */ 00252 using ::mfcstl::c_str_len_a; 00253 #endif /* UNICODE */ 00254 00255 using ::mfcstl::c_str_ptr; 00256 #if defined(UNICODE) 00257 using ::mfcstl::c_str_ptr_w; 00258 #else /* ? UNICODE */ 00259 using ::mfcstl::c_str_ptr_a; 00260 #endif /* UNICODE */ 00261 00262 using ::mfcstl::c_str_ptr_null; 00263 #if defined(UNICODE) 00264 using ::mfcstl::c_str_ptr_null_w; 00265 #else /* ? UNICODE */ 00266 using ::mfcstl::c_str_ptr_null_a; 00267 #endif /* UNICODE */ 00268 00269 00270 # if !defined(_STLSOFT_NO_NAMESPACE) && \ 00271 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) 00272 } // namespace stlsoft 00273 # else /* ? _STLSOFT_NO_NAMESPACE */ 00274 /* There is no stlsoft namespace, so must define in the global namespace */ 00275 # endif /* !_STLSOFT_NO_NAMESPACE */ 00276 #endif /* !_MFCSTL_NO_NAMESPACE */ 00277 00278 /* ///////////////////////////////////////////////////////////////////////// 00279 * Global namespace shims 00280 */ 00281 00282 /* This defines a stream inserter shim function template for CString for use 00283 * with the Visual C++ <7.1 standard library. 00284 * 00285 * It cannot be defined as a template because that conflicts with operator << (CArchive &, CString const&) 00286 */ 00287 00288 #if defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_VC) && \ 00289 STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION < STLSOFT_CF_DINKUMWARE_VC_VERSION_7_1 00290 00291 # include <iosfwd> 00292 00293 /* Has to be like this otherwise it conflicts with operator <<(class CArchive &,const class CString &) (at least with VC++ <7.1). */ 00294 inline mfcstl_ns_qual_std(basic_ostream)<TCHAR>& operator <<(mfcstl_ns_qual_std(basic_ostream)<TCHAR> &stm, CString const& shim) 00295 { 00296 return stm << static_cast<LPCTSTR>(shim); 00297 } 00298 00299 #endif /* library */ 00300 00301 /* ////////////////////////////////////////////////////////////////////// */ 00302 00303 #endif /* !MFCSTL_INCL_MFCSTL_SHIMS_ACCESS_STRING_HPP_CSTRING */ 00304 00305 /* ///////////////////////////// end of file //////////////////////////// */