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
00042
00043
00044
00052 #ifndef WINSTL_INCL_WINSTL_STRING_HPP_RESOURCE_STRING
00053 #define WINSTL_INCL_WINSTL_STRING_HPP_RESOURCE_STRING
00054
00055 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00056 # define WINSTL_VER_WINSTL_STRING_HPP_RESOURCE_STRING_MAJOR 4
00057 # define WINSTL_VER_WINSTL_STRING_HPP_RESOURCE_STRING_MINOR 2
00058 # define WINSTL_VER_WINSTL_STRING_HPP_RESOURCE_STRING_REVISION 4
00059 # define WINSTL_VER_WINSTL_STRING_HPP_RESOURCE_STRING_EDIT 83
00060 #endif
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00077 # include <winstl/winstl.h>
00078 #endif
00079
00080
00081
00082
00083 #ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_EXCEPTIONS
00084 # include <stlsoft/error/exceptions.hpp>
00085 #endif
00086 #ifndef WINSTL_INCL_WINSTL_ERROR_HPP_WINDOWS_EXCEPTIONS
00087 # include <winstl/error/exceptions.hpp>
00088 #endif
00089
00090 #ifndef STLSOFT_INCL_EXCEPTION
00091 # define STLSOFT_INCL_EXCEPTION
00092 # include <exception>
00093 #endif
00094
00095 #ifdef STLSOFT_UNITTEST
00096 # include <iostream>
00097 # include <string>
00098 #endif
00099
00100
00101
00102
00103
00104 #ifndef _WINSTL_NO_NAMESPACE
00105 # if defined(_STLSOFT_NO_NAMESPACE) || \
00106 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00107
00108 namespace winstl
00109 {
00110 # else
00111
00112
00113 namespace stlsoft
00114 {
00115
00116 namespace winstl_project
00117 {
00118
00119 # endif
00120 #endif
00121
00122
00123
00124
00125
00187 template< ss_typename_param_k S
00188 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00189 # ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00190 , ss_typename_param_k X = resource_exception_policy
00191 # else
00192 , ss_typename_param_k X = stlsoft_ns_qual(null_exception_policy)
00193 # endif
00194 #else
00195 , ss_typename_param_k X
00196 #endif
00197 >
00198
00199 class basic_resource_string
00200 : public S
00201 , protected X
00202 {
00203 private:
00204 typedef S parent_class_type;
00205 public:
00207 typedef S string_type;
00209 typedef basic_resource_string<S, X> class_type;
00211 typedef X exception_policy_type;
00215 typedef exception_policy_type exception_type;
00216
00217
00219 typedef ss_typename_type_k string_type::value_type value_type;
00220
00223 public:
00225 ss_explicit_k basic_resource_string(ws_int_t id) stlsoft_throw_1(ss_typename_type_k exception_policy_type::thrown_type)
00226 {
00227 this->load_(::GetModuleHandle(NULL), id, NULL);
00228 }
00229
00231 basic_resource_string(HINSTANCE hinst, ws_int_t id) stlsoft_throw_1(ss_typename_type_k exception_policy_type::thrown_type)
00232 {
00233 this->load_(hinst, id, NULL);
00234 }
00235
00237 ss_explicit_k basic_resource_string(ws_int_t id, value_type const* defaultValue)
00238 {
00239 this->load_(::GetModuleHandle(NULL), id, defaultValue);
00240 }
00241
00243 basic_resource_string(HINSTANCE hinst, ws_int_t id, value_type const* defaultValue)
00244 {
00245 this->load_(hinst, id, defaultValue);
00246 }
00247
00249 basic_resource_string(class_type const& rhs)
00250 : parent_class_type(rhs)
00251 {}
00252
00254 basic_resource_string(string_type const& rhs)
00255 : parent_class_type(rhs)
00256 {}
00257
00259 class_type& operator =(class_type const& rhs)
00260 {
00261 parent_class_type::operator =(rhs);
00262
00263 return *this;
00264 }
00266 class_type& operator =(string_type const& rhs)
00267 {
00268 parent_class_type::operator =(rhs);
00269
00270 return *this;
00271 }
00273
00274
00275 private:
00276 ws_int_t load_string_(HINSTANCE hinst, int uID, ws_char_a_t *buffer, ws_size_t cchBuffer)
00277 {
00278 return ::LoadStringA(hinst, static_cast<UINT>(uID), buffer, static_cast<int>(cchBuffer));
00279 }
00280 ws_int_t load_string_(HINSTANCE hinst, int uID, ws_char_w_t *buffer, ws_size_t cchBuffer)
00281 {
00282 if(::GetVersion() & 0x80000000)
00283 {
00284
00285 int block = (uID >> 4) + 1;
00286 int num = uID & 0xf;
00287 HRSRC hRC = ::FindResourceEx( hinst
00288 , RT_STRING
00289 , MAKEINTRESOURCE(block)
00290 , MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
00291
00292 if(NULL != hRC)
00293 {
00294 HGLOBAL hgl = ::LoadResource(hinst, hRC);
00295
00296 if(NULL != hgl)
00297 {
00298 LPWSTR res_str = (LPWSTR)::LockResource(hgl);
00299
00300 if(NULL != res_str)
00301 {
00302 for(int i = 0; i < num; ++i)
00303 {
00304 res_str += *res_str + 1;
00305 }
00306
00307 const LPCWSTR ptr = res_str + 1;
00308 const ws_size_t cch = static_cast<ws_size_t>(*res_str);
00309
00310 if(cch < cchBuffer)
00311 {
00312 cchBuffer = cch + 1;
00313 buffer[cch] = L'\0';
00314 }
00315
00316 ::lstrcpynW(buffer, ptr, static_cast<int>(cchBuffer));
00317
00318 return static_cast<ws_int_t>(cchBuffer);
00319 }
00320 }
00321 }
00322
00323 return 0;
00324 }
00325
00326 return ::LoadStringW(hinst, static_cast<UINT>(uID), buffer, static_cast<int>(cchBuffer));
00327 }
00328
00329 void load_(HINSTANCE hinst, ws_int_t id, value_type const* defaultValue) stlsoft_throw_1(ss_typename_type_k exception_policy_type::thrown_type)
00330 {
00331
00332
00333 value_type sz[1024];
00334
00335 if(0 == this->load_string_(hinst, id, sz, STLSOFT_NUM_ELEMENTS(sz)))
00336 {
00337 if(NULL != defaultValue)
00338 {
00339 parent_class_type::operator =(defaultValue);
00340 }
00341 else
00342 {
00343 exception_policy_type()("string did not load", ::GetLastError(), MAKEINTRESOURCE(id), RT_STRING);
00344
00345 parent_class_type::operator =(string_type());
00346 }
00347 }
00348 else
00349 {
00350 parent_class_type::operator =(sz);
00351 }
00352 }
00353 };
00354
00355
00356
00357
00358
00359
00360
00361
00363
00364
00365 #ifdef STLSOFT_UNITTEST
00366 # include "./unittest/resource_string_unittest_.h"
00367 #endif
00368
00369
00370
00371
00372
00373 #if 0
00374
00375
00380 template< ss_typename_param_k S
00381 , ss_typename_param_k X
00382 >
00383 inline C const* c_str_ptr_null(basic_resource_string<S, X> const& s)
00384 {
00385 return (s.length() == 0) ? 0 : s.c_str();
00386 }
00387
00388
00389
00394 template< ss_typename_param_k S
00395 , ss_typename_param_k X
00396 >
00397 inline C const* c_str_ptr(basic_resource_string<S, X> const& s)
00398 {
00399 return s.c_str();
00400 }
00401
00402
00403
00408 template< ss_typename_param_k S
00409 , ss_typename_param_k X
00410 >
00411 inline C const* c_str_data(basic_resource_string<S, X> const& s)
00412 {
00413 return s.c_str();
00414 }
00415
00416
00417
00422 template< ss_typename_param_k S
00423 , ss_typename_param_k X
00424 >
00425 inline ss_size_t c_str_len(basic_resource_string<S, X> const& s)
00426 {
00427 return s.length();
00428 }
00429 #endif
00430
00431
00432
00433 #ifndef _WINSTL_NO_NAMESPACE
00434 # if defined(_STLSOFT_NO_NAMESPACE) || \
00435 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00436 }
00437 # else
00438 }
00439 }
00440 # endif
00441 #endif
00442
00443
00444
00445 #endif
00446
00447