#include <winstl/string/resource_string.hpp>
It is an adaptor template, so is parameterised with the underlying string type. For example, winstl::basic_resource_string<std::string>
is parameterised from std::string
, and can therefore use its methods and is compatible with its client code:
winstl::basic_resource_string<std::string> str(1024); std::cout << "String with id 1024: " << str << std::endl; fprintf(stdout, "String with id 1024: %.*s\n", str.size(), str.data());
The second template parameter is the exception policy, which determines how the string reacts to a failure to load a string resource corresponding to the given Id. It is defaulted to stlsoft::null_exception_policy, which means that, when a corresponding string resource is not loaded, the resource string instance will be correctly constructed but will contain the empty string, i.e.:
// Assuming 9999999 is not a valid string resource identifier in the // module whose instance handle is in hinst ... winstl::basic_resource_string<std::string> str(hinst, 9999999); assert(0 == str.size()); assert(str == "");
If you want your parameterisation to throw an exception when the string resource is not found, simply specify a policy that throws an exception to the parameterisation, as in:
// Assuming 9999999 is not a valid string resource identifier in the // module whose instance handle is in hinst ... try { winstl::basic_resource_string<std::string, throw_MyX_policy> str(hinst, 9999999); std::cerr << "Should never get here!!" << std::endl; } catch(MyX &x) { std::cerr << "This is what's expected" << std::endl; }
S | The string class, e.g. std::string, stlsoft::simple_string, etc. | |
X | The exception class |
Public Types | |
typedef S | string_type |
The type of the underlying string. | |
typedef basic_resource_string < S, X > | class_type |
The type of the current parameterisation. | |
typedef X | exception_policy_type |
The exception policy type. | |
typedef exception_policy_type | exception_type |
The exception policy type. | |
typedef string_type::value_type | value_type |
The value type. | |
Public Member Functions | |
Construction | |
basic_resource_string (int id) throw ( typename exception_policy_type::thrown_type ) | |
Constructs an around the string loaded from the given id . | |
basic_resource_string (HINSTANCE hinst, int id) throw ( typename exception_policy_type::thrown_type ) | |
Constructs an around the string loaded from the given id and hinst . | |
basic_resource_string (int id, value_type const *defaultValue) | |
Constructs an around the string loaded from the given id , or uses the given default. | |
basic_resource_string (HINSTANCE hinst, int id, value_type const *defaultValue) | |
Constructs an around the string loaded from the given id and hinst . | |
basic_resource_string (class_type const &rhs) | |
Copy constructor. | |
basic_resource_string (string_type const &rhs) | |
Copy constructor. | |
class_type & | operator= (class_type const &rhs) |
Copy assignment operator. | |
class_type & | operator= (string_type const &rhs) |
Copy assignment operator. |
typedef S string_type |
The type of the underlying string.
typedef basic_resource_string<S, X> class_type |
The type of the current parameterisation.
typedef X exception_policy_type |
The exception policy type.
typedef exception_policy_type exception_type |
typedef string_type::value_type value_type |
The value type.
basic_resource_string | ( | int | id | ) | throw ( typename exception_policy_type::thrown_type ) [inline, explicit] |
Constructs an around the string loaded from the given id
.
basic_resource_string | ( | HINSTANCE | hinst, | |
int | id | |||
) | throw ( typename exception_policy_type::thrown_type ) [inline] |
Constructs an around the string loaded from the given id
and hinst
.
basic_resource_string | ( | int | id, | |
value_type const * | defaultValue | |||
) | [inline, explicit] |
Constructs an around the string loaded from the given id
, or uses the given default.
basic_resource_string | ( | HINSTANCE | hinst, | |
int | id, | |||
value_type const * | defaultValue | |||
) | [inline] |
Constructs an around the string loaded from the given id
and hinst
.
basic_resource_string | ( | class_type const & | rhs | ) | [inline] |
Copy constructor.
basic_resource_string | ( | string_type const & | rhs | ) | [inline] |
Copy constructor.
class_type& operator= | ( | class_type const & | rhs | ) | [inline] |
Copy assignment operator.
class_type& operator= | ( | string_type const & | rhs | ) | [inline] |
Copy assignment operator.