basic_resource_string Class Template Reference
[String Library]

#include <winstl/string/resource_string.hpp>

List of all members.


Detailed Description

template<typename S, typename X = resource_exception_policy>
class winstl::basic_resource_string< S, X >

Instances of this class represent Windows string resources, and are constructed from instance identifiers.

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;
}

Note:
The handling of Unicode strings under Windows 9x family operating systems eschews the use of LoadStringW(), instead manipulating the resource information via FindResourceEx() / LoadResource() / LockResource(). This code kindly provided by Ryan Ginstrom.
Parameters:
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_typeoperator= (class_type const &rhs)
 Copy assignment operator.
class_typeoperator= (string_type const &rhs)
 Copy assignment operator.

Member Typedef Documentation

typedef S string_type

The type of the underlying string.

The type of the current parameterisation.

The exception policy type.

The exception policy type.

Deprecated:

typedef string_type::value_type value_type

The value type.


Constructor & Destructor Documentation

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.


Member Function Documentation

class_type& operator= ( class_type const &  rhs  )  [inline]

Copy assignment operator.

class_type& operator= ( string_type const &  rhs  )  [inline]

Copy assignment operator.


The documentation for this class was generated from the following file:

Generated on Thu Jun 10 08:59:36 2010 for STLSoft by  doxygen 1.5.6