messages class template — Facet for retrieving strings from a message catalog
template <typename charT> class messages : public locale::facet, public messages_base { public: typedef charT char_type; typedef basic_string<charT> string_type; explicit messages(size_t refs = 0); catalog open(const basic_string<char>& fn, const locale&) const; string_type get(catalog c, int set, int msgid, const string_type& dfault) const; void close(catalog c) const; static locale::id id; protected: virtual ~messages( ); virtual catalog do_open(const basic_string<char>&, const locale&) const; virtual string_type do_get(catalog, int set, int msgid, const string_type& dfault) const; virtual void do_close(catalog) const; };
The messages
class template
is a facet for a message catalog. A message catalog is a database of
textual messages that can be translated into different languages.
The messages<char>
and
messages<wchar_t>
instantiations are standard.
How a message catalog is found is implementation-defined. For example, a catalog name could be the name of an external file, or it could be the name of a special resource section in the program's executable file. The mapping of message identifiers to a particular message is also implementation-defined.
As with other facets, the public members call virtual,
protected members with the same name prefaced by do_
. Thus, to use the facet, call the
public functions, such as get
,
which calls do_get
. The
descriptions below are for the virtual functions because they do the
real work. Imagine that for each virtual-function description, there
is a corresponding description for a public, nonvirtual function,
such as:
void
close
(catalog
cat)
const
Calls do_close(cat)
.
The following are the virtual, protected members of messages
:
virtual
void
do_close
(catalog
cat)
const
Closes the message catalog cat
.
virtual
string_type
do_get
(catalog
cat
, int
set,
int
msgid
, const
string_type&
dfault)
const
Gets a message that is identified by set
, msgid
, and dfault
from catalog cat
. If the message cannot be found,
dfault
is returned.
virtual
catalog
do_open
(const
basic_string<char>&
name, const
locale&
loc)
const
Opens a message catalog name
. If the catalog cannot be
opened, a negative value is returned. Otherwise, the catalog
value can be passed to
get
to retrieve messages.
Call close
to close the
catalog.