00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 #ifndef WINSTL_INCL_H_WINSTL
00071 # include "winstl.h"
00072 #endif
00073
00074 #if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00075 _MSC_VER < 1200
00076 # error winstl_module_filename.h is not compatible with Visual C++ 5.0 or earlier
00077 #endif
00078
00079 #ifndef WINSTL_INCL_H_WINSTL_FILESYSTEM_TRAITS
00080 # include "winstl_filesystem_traits.h"
00081 #endif
00082 #ifndef WINSTL_INCL_H_WINSTL_FILE_PATH_BUFFER
00083 # include "winstl_file_path_buffer.h"
00084 #endif
00085
00086
00087
00088
00089
00090 #ifndef _WINSTL_NO_NAMESPACE
00091 # if defined(_STLSOFT_NO_NAMESPACE) || \
00092 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00093
00094 namespace winstl
00095 {
00096 # else
00097
00098
00099 namespace stlsoft
00100 {
00101
00102 namespace winstl_project
00103 {
00104
00105 # endif
00106 #endif
00107
00108
00109
00112
00116
00121
00122
00123
00124
00125
00126
00127
00128
00133 template< ss_typename_param_k C
00134 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00135 , ss_typename_param_k T = filesystem_traits<C>
00136 #else
00137 , ss_typename_param_k T
00138 #endif
00139 >
00140 class basic_module_filename
00141 {
00142 public:
00144 typedef C char_type;
00146 typedef T traits_type;
00148 typedef basic_module_filename<C, T> class_type;
00150 typedef ws_size_t size_type;
00151
00152
00153 public:
00155 basic_module_filename();
00157 ss_explicit_k basic_module_filename(HINSTANCE hinst);
00158
00159
00160 public:
00162 size_type get_filename(ws_char_a_t *buffer, size_type cchBuffer) const;
00164 size_type get_filename(ws_char_w_t *buffer, size_type cchBuffer) const;
00166 static size_type get_filename(HINSTANCE hinst, ws_char_a_t *buffer, size_type cchBuffer);
00168 static size_type get_filename(HINSTANCE hinst, ws_char_w_t *buffer, size_type cchBuffer);
00169
00170
00171 public:
00173 char_type const *get_filename() const;
00175 size_type length() const;
00176
00177
00178 public:
00180 operator char_type const *() const
00181 {
00182 return get_filename();
00183 }
00184
00185
00186 private:
00187 basic_file_path_buffer<char_type> m_path;
00188 HINSTANCE const m_hinst;
00189 size_type const m_len;
00190
00191
00192 private:
00193 basic_module_filename(class_type const &);
00194 basic_module_filename &operator =(class_type const &);
00195 };
00196
00197
00198
00199
00200
00202 typedef basic_module_filename<ws_char_a_t, filesystem_traits<ws_char_a_t> > module_filename_a;
00204 typedef basic_module_filename<ws_char_w_t, filesystem_traits<ws_char_w_t> > module_filename_w;
00206 typedef basic_module_filename<TCHAR, filesystem_traits<TCHAR> > module_filename;
00207
00208
00209
00210
00211
00212 #ifdef STLSOFT_UNITTEST
00213
00214 namespace unittest
00215 {
00216 ss_bool_t test_winstl_module_filename(unittest_reporter *r)
00217 {
00218 using stlsoft::unittest::unittest_initialiser;
00219
00220 ss_bool_t bSuccess = true;
00221
00222 unittest_initialiser init(r, "WinSTL", "module_filename", __FILE__);
00223
00224 TCHAR mfn[1 + _MAX_PATH];
00225
00226 ::GetModuleFileName(NULL, &mfn[0], stlsoft_num_elements(mfn));
00227
00228 if(0 != lstrcmp(mfn, module_filename()))
00229 {
00230 r->report("module filename failed ", __LINE__);
00231 bSuccess = false;
00232 }
00233
00234 return bSuccess;
00235 }
00236
00237 unittest_registrar unittest_winstl_module_filename(test_winstl_module_filename);
00238
00239 }
00240
00241 #endif
00242
00243
00244
00245
00246
00247 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00248
00249 template< ss_typename_param_k C
00250 , ss_typename_param_k T
00251 >
00252 inline basic_module_filename<C, T>::basic_module_filename()
00253 : m_hinst(::GetModuleHandle(NULL))
00254 , m_len(get_filename(&m_path[0], m_path.size()))
00255 {
00256 stlsoft_static_assert(stlsoft_raw_offsetof(class_type, m_hinst) < stlsoft_raw_offsetof(class_type, m_len));
00257 }
00258
00259 template< ss_typename_param_k C
00260 , ss_typename_param_k T
00261 >
00262 inline basic_module_filename<C, T>::basic_module_filename(HINSTANCE hinst)
00263 : m_hinst(hinst)
00264 , m_len(get_filename(hinst, &m_path[0], m_path.size()))
00265 {
00266 stlsoft_static_assert(stlsoft_raw_offsetof(class_type, m_hinst) < stlsoft_raw_offsetof(class_type, m_len));
00267 }
00268
00269 template< ss_typename_param_k C
00270 , ss_typename_param_k T
00271 >
00272 inline ss_typename_type_k basic_module_filename<C, T>::size_type basic_module_filename<C, T>::get_filename(ws_char_a_t *buffer, ss_typename_type_k basic_module_filename<C, T>::size_type cchBuffer) const
00273 {
00274 return static_cast<size_type>(::GetModuleFileNameA(m_hinst, buffer, cchBuffer));
00275 }
00276
00277 template< ss_typename_param_k C
00278 , ss_typename_param_k T
00279 >
00280 inline ss_typename_type_k basic_module_filename<C, T>::size_type basic_module_filename<C, T>::get_filename(ws_char_w_t *buffer, ss_typename_type_k basic_module_filename<C, T>::size_type cchBuffer) const
00281 {
00282 return static_cast<size_type>(::GetModuleFileNameW(m_hinst, buffer, cchBuffer));
00283 }
00284
00285 template< ss_typename_param_k C
00286 , ss_typename_param_k T
00287 >
00288 inline ss_typename_type_k basic_module_filename<C, T>::size_type basic_module_filename<C, T>::get_filename(HINSTANCE hinst, ws_char_a_t *buffer, ss_typename_type_k basic_module_filename<C, T>::size_type cchBuffer)
00289 {
00290 return static_cast<size_type>(::GetModuleFileNameA(hinst, buffer, cchBuffer));
00291 }
00292
00293 template< ss_typename_param_k C
00294 , ss_typename_param_k T
00295 >
00296 inline ss_typename_type_k basic_module_filename<C, T>::size_type basic_module_filename<C, T>::get_filename(HINSTANCE hinst, ws_char_w_t *buffer, ss_typename_type_k basic_module_filename<C, T>::size_type cchBuffer)
00297 {
00298 return static_cast<size_type>(::GetModuleFileNameW(hinst, buffer, cchBuffer));
00299 }
00300
00301 template< ss_typename_param_k C
00302 , ss_typename_param_k T
00303 >
00304 inline ss_typename_type_k basic_module_filename<C, T>::char_type const *basic_module_filename<C, T>::get_filename() const
00305 {
00306 return stlsoft_ns_qual(c_str_ptr)(m_path);
00307 }
00308
00309 template< ss_typename_param_k C
00310 , ss_typename_param_k T
00311 >
00312 inline ss_typename_type_k basic_module_filename<C, T>::size_type basic_module_filename<C, T>::length() const
00313 {
00314 return m_len;
00315 }
00316
00317 #endif
00318
00319
00320
00321
00322
00323 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00324
00325 template< ss_typename_param_k C
00326 , ss_typename_param_k T
00327 >
00328 inline ws_char_a_t const *c_str_ptr_a_null(basic_module_filename<C, T> const &mfn)
00329 {
00330 return mfn;
00331 }
00332
00333 template< ss_typename_param_k C
00334 , ss_typename_param_k T
00335 >
00336 inline ws_char_w_t const *c_str_ptr_w_null(basic_module_filename<C, T> const &mfn)
00337 {
00338 return mfn;
00339 }
00340
00341 template< ss_typename_param_k C
00342 , ss_typename_param_k T
00343 >
00344 inline ws_char_a_t const *c_str_ptr_a(basic_module_filename<C, T> const &mfn)
00345 {
00346 return mfn;
00347 }
00348
00349 template< ss_typename_param_k C
00350 , ss_typename_param_k T
00351 >
00352 inline ws_char_w_t const *c_str_ptr_w(basic_module_filename<C, T> const &mfn)
00353 {
00354 return mfn;
00355 }
00356
00357 template< ss_typename_param_k C
00358 , ss_typename_param_k T
00359 >
00360 inline ss_typename_type_k basic_module_filename<C, T>::size_type c_str_len_a(basic_module_filename<C, T> const &mfn)
00361 {
00362 return mfn.length();
00363 }
00364
00365 template< ss_typename_param_k C
00366 , ss_typename_param_k T
00367 >
00368 inline ss_typename_type_k basic_module_filename<C, T>::size_type c_str_size(basic_module_filename<C, T> const &mfn)
00369 {
00370 return mfn.length() * sizeof(ss_typename_type_k basic_module_filename<C, T>::char_type);
00371 }
00372
00373 #endif
00374
00375
00376
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 #endif
00390
00391
00392
00393
00394
00395