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
00047 #ifndef FASTFORMAT_INCL_FASTFORMAT_BUNDLES_HPP_WINDOWS_RESOURCE_BUNDLE
00048 #define FASTFORMAT_INCL_FASTFORMAT_BUNDLES_HPP_WINDOWS_RESOURCE_BUNDLE
00049
00050
00051
00052
00053
00054 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00055 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_WINDOWS_RESOURCE_BUNDLE_MAJOR 1
00056 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_WINDOWS_RESOURCE_BUNDLE_MINOR 0
00057 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_WINDOWS_RESOURCE_BUNDLE_REVISION 2
00058 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_WINDOWS_RESOURCE_BUNDLE_EDIT 3
00059 #endif
00060
00061
00062
00063
00064
00065 #ifndef __cplusplus
00066 # error This file can only be included in C++ compilation units
00067 #endif
00068
00069
00070
00071
00072
00073
00074 #include <fastformat/fastformat.h>
00075 #include <fastformat/exceptions.hpp>
00076 #include <fastformat/util/bundle/windows_replacement_translation_functions.hpp>
00077
00078
00079 #include <winstl/winstl.h>
00080
00081
00082 #include <stlsoft/conversion/integer_to_string.hpp>
00083 #include <stlsoft/shims/access/string.hpp>
00084 #include <stlsoft/util/minmax.hpp>
00085 #include <winstl/error/error_desc.hpp>
00086 #include <winstl/string/resource_string.hpp>
00087
00088
00089 #include <stdexcept>
00090 #include <string>
00091
00092
00093
00094
00095
00096 #if !defined(FASTFORMAT_NO_NAMESPACE)
00097 namespace fastformat
00098 {
00099 #endif
00100
00101
00102
00103
00104
00107 class windows_resource_bundle
00108 {
00111 public:
00113 typedef ff_char_t char_type;
00115 typedef std::basic_string<char_type> string_type;
00117 typedef windows_resource_bundle class_type;
00119 class missing_resource_id_exception
00120 : public bundle_exception
00121 {
00122 public:
00123
00124 typedef bundle_exception parent_class_type;
00126 typedef missing_resource_id_exception class_type;
00128 typedef parent_class_type::string_type string_type;
00129
00130 public:
00131
00135 explicit missing_resource_id_exception(int id)
00136 : parent_class_type(create_message_(NULL, 0u, id, NULL).c_str())
00137 , id(id)
00138 , code(-1)
00139 {
00140 FASTFORMAT_COVER_MARK_ENTRY();
00141 }
00153 missing_resource_id_exception(char const* msg, DWORD code, ff_char_t const* id, ff_char_t const* resourceType)
00154 : parent_class_type(create_message_(msg, code, reinterpret_cast<int>(id), resourceType).c_str())
00155 , id(reinterpret_cast<int>(id))
00156 , code(code)
00157 {
00158 FASTFORMAT_COVER_MARK_ENTRY();
00159 }
00171 missing_resource_id_exception(char const* msg, DWORD code, int id, ff_char_t const* resourceType)
00172 : parent_class_type(create_message_(msg, code, id, resourceType).c_str())
00173 , id(id)
00174 , code(code)
00175 {
00176 FASTFORMAT_COVER_MARK_ENTRY();
00177 }
00178
00179 private:
00181 class_type& operator =(class_type const&);
00182
00183 public:
00184
00185 const int id;
00187 const DWORD code;
00188
00189 private:
00190 static multibyte_string_type create_message_(char const* msg, DWORD code, int id, ff_char_t const* resourceType)
00191 {
00192 static const char string0[] = "could not load bundle resource corresponding to identifier ";
00193 static const char string1[] = ": ";
00194 char num_[21];
00195 char const* num = stlsoft::integer_to_string(&num_[0], STLSOFT_NUM_ELEMENTS(num_), id);
00196 winstl::error_desc_a reason(code);
00197 multibyte_string_type message;
00198
00199 if(0 != code)
00200 {
00201 message.reserve(STLSOFT_NUM_ELEMENTS(string0) + 21 + STLSOFT_NUM_ELEMENTS(string1) + reason.size());
00202 }
00203 else
00204 {
00205 message.reserve(STLSOFT_NUM_ELEMENTS(string0) + 21);
00206 }
00207
00208 message += string0;
00209 message += num;
00210
00211 if(0 != code)
00212 {
00213 message += string1;
00214 message += reason;
00215 }
00216
00217 return message;
00218 }
00219 };
00220 typedef missing_resource_id_exception exception_type;
00221 private:
00222 typedef winstl::basic_resource_string<
00223 string_type
00224 , stlsoft::throw_exception_policy<exception_type>
00225 > resource_string_type_;
00227
00230 public:
00231 explicit windows_resource_bundle(HINSTANCE hinst);
00232 ~windows_resource_bundle() throw();
00233 private:
00234 windows_resource_bundle(class_type const&);
00235 class_type& operator =(class_type const&);
00237
00240 public:
00241 string_type operator [](int id) const throw(missing_resource_id_exception);
00243
00246 private:
00248
00251 private:
00252 HINSTANCE m_instance;
00254 };
00255
00256
00257
00258
00259
00260 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00261
00262 inline windows_resource_bundle::windows_resource_bundle(HINSTANCE hinst)
00263 : m_instance(hinst)
00264 {}
00265
00266 inline windows_resource_bundle::~windows_resource_bundle() throw()
00267 {
00268 ::FreeLibrary(m_instance);
00269 }
00270
00271 inline windows_resource_bundle::string_type windows_resource_bundle::operator [](int id) const throw(windows_resource_bundle::missing_resource_id_exception)
00272 {
00273 resource_string_type_ str(m_instance, id);
00274 string_type s2 = str;
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 if( 0 == fastformat::util::calculate_number_of_fastformat_replacement_parameters(s2.data(), s2.length()) &&
00288 0 != fastformat::util::calculate_number_of_windows_replacement_parameters(s2.data(), s2.length()))
00289 {
00290 s2 = fastformat::util::escape_fastformat_replacement_parameters(s2);
00291
00292 s2 = fastformat::util::change_windows_replacement_parameters_to_fastformat(s2);
00293 }
00294
00295 return s2;
00296 }
00297
00298 #endif
00299
00300
00301
00302
00303
00304 #if !defined(FASTFORMAT_NO_NAMESPACE)
00305 }
00306 #endif
00307
00308
00309
00310 #endif
00311
00312