00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: winstl/system/module_filename.hpp (originally MWModFNm.h; ::SynesisWin) 00003 * 00004 * Purpose: Preposterously simple class that gets, and makes accessible, the 00005 * module filename. 00006 * 00007 * Created: 31st March 2002 00008 * Updated: 10th August 2009 00009 * 00010 * Home: http://stlsoft.org/ 00011 * 00012 * Copyright (c) 2002-2009, Matthew Wilson and Synesis Software 00013 * All rights reserved. 00014 * 00015 * Redistribution and use in source and binary forms, with or without 00016 * modification, are permitted provided that the following conditions are met: 00017 * 00018 * - Redistributions of source code must retain the above copyright notice, this 00019 * list of conditions and the following disclaimer. 00020 * - Redistributions in binary form must reproduce the above copyright notice, 00021 * this list of conditions and the following disclaimer in the documentation 00022 * and/or other materials provided with the distribution. 00023 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of 00024 * any contributors may be used to endorse or promote products derived from 00025 * this software without specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 * 00039 * ////////////////////////////////////////////////////////////////////// */ 00040 00041 00049 #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_MODULE_FILENAME 00050 #define WINSTL_INCL_WINSTL_SYSTEM_HPP_MODULE_FILENAME 00051 00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION 00053 # define WINSTL_VER_WINSTL_SYSTEM_HPP_MODULE_FILENAME_MAJOR 4 00054 # define WINSTL_VER_WINSTL_SYSTEM_HPP_MODULE_FILENAME_MINOR 1 00055 # define WINSTL_VER_WINSTL_SYSTEM_HPP_MODULE_FILENAME_REVISION 2 00056 # define WINSTL_VER_WINSTL_SYSTEM_HPP_MODULE_FILENAME_EDIT 72 00057 #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */ 00058 00059 /* ///////////////////////////////////////////////////////////////////////// 00060 * Compatibility 00061 */ 00062 00063 /* 00064 [Incompatibilies-start] 00065 STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1200 00066 [Incompatibilies-end] 00067 */ 00068 00069 /* ///////////////////////////////////////////////////////////////////////// 00070 * Includes 00071 */ 00072 00073 #ifndef WINSTL_INCL_WINSTL_H_WINSTL 00074 # include <winstl/winstl.h> 00075 #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */ 00076 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SPECIAL_STRING_INSTANCE 00077 # include <stlsoft/string/special_string_instance.hpp> 00078 #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SPECIAL_STRING_INSTANCE */ 00079 #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR 00080 # include <winstl/memory/processheap_allocator.hpp> 00081 #endif /* !WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR */ 00082 #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS 00083 # include <winstl/system/system_traits.hpp> 00084 #endif /* !WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS */ 00085 00086 #if defined(STLSOFT_COMPILER_IS_BORLAND) 00087 // Borland is a bit of a thicky, and requires a (valid) spin_mutex_type 00088 # include <winstl/synch/spin_mutex.hpp> 00089 #endif /* compiler */ 00090 00091 /* ///////////////////////////////////////////////////////////////////////// 00092 * Namespace 00093 */ 00094 00095 #ifndef _WINSTL_NO_NAMESPACE 00096 # if defined(_STLSOFT_NO_NAMESPACE) || \ 00097 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) 00098 /* There is no stlsoft namespace, so must define ::winstl */ 00099 namespace winstl 00100 { 00101 # else 00102 /* Define stlsoft::winstl_project */ 00103 00104 namespace stlsoft 00105 { 00106 00107 namespace winstl_project 00108 { 00109 00110 # endif /* _STLSOFT_NO_NAMESPACE */ 00111 #endif /* !_WINSTL_NO_NAMESPACE */ 00112 00113 /* ///////////////////////////////////////////////////////////////////////// 00114 * basic_module_filename 00115 * 00116 * This class wraps the GetModuleFilename() API function, and effectively acts 00117 * as an adaptor between HINSTANCE and a C-string to the name. 00118 */ 00119 00128 template <ss_typename_param_k C> 00129 struct modfname_policy 00130 { 00133 public: 00134 typedef C char_type; 00135 typedef HINSTANCE argument_0_type; 00136 typedef processheap_allocator<C> allocator_type; 00137 typedef ws_size_t size_type; 00138 typedef size_type (*pfn_type)(argument_0_type, char_type *, size_type); 00139 #if defined(STLSOFT_COMPILER_IS_BORLAND) 00140 // Borland is a bit of a thicky, and requires a (valid) spin_mutex_type 00141 typedef winstl::spin_mutex spin_mutex_type; 00142 #endif /* compiler */ 00144 00147 public: 00148 enum { internalBufferSize = 128 }; 00149 00150 enum { allowImplicitConversion = 1 }; 00151 00152 enum { sharedState = 0 }; 00154 00157 public: 00158 static pfn_type get_fn() 00159 { 00160 return winstl::system_traits<char_type>::get_module_filename; 00161 } 00163 }; 00164 00165 /* ///////////////////////////////////////////////////////////////////////// 00166 * Typedefs for commonly encountered types 00167 */ 00168 00174 typedef stlsoft_ns_qual(special_string_instance_1)<modfname_policy<ws_char_a_t> > module_filename_a; 00180 typedef stlsoft_ns_qual(special_string_instance_1)<modfname_policy<ws_char_w_t> > module_filename_w; 00186 typedef stlsoft_ns_qual(special_string_instance_1)<modfname_policy<TCHAR> > module_filename; 00187 00188 /* ////////////////////////////////////////////////////////////////////////// 00189 * Unit-testing 00190 */ 00191 00192 #ifdef STLSOFT_UNITTEST 00193 # include "./unittest/module_filename_unittest_.h" 00194 #endif /* STLSOFT_UNITTEST */ 00195 00196 /* ////////////////////////////////////////////////////////////////////// */ 00197 00198 #ifndef _WINSTL_NO_NAMESPACE 00199 # if defined(_STLSOFT_NO_NAMESPACE) || \ 00200 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) 00201 } // namespace winstl 00202 # else 00203 } // namespace winstl_project 00204 } // namespace stlsoft 00205 # endif /* _STLSOFT_NO_NAMESPACE */ 00206 #endif /* !_WINSTL_NO_NAMESPACE */ 00207 00208 /* ////////////////////////////////////////////////////////////////////// */ 00209 00210 #endif /* WINSTL_INCL_WINSTL_SYSTEM_HPP_MODULE_FILENAME */ 00211 00212 /* ///////////////////////////// end of file //////////////////////////// */