Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/messages byname"

From cppreference.com
< cpp‎ | locale
(+)
 
m (r2.7.3) (Robot: Adding de, es, fr, it, ja, pt, ru, zh)
Line 78: Line 78:
 
{{dcl list template | cpp/locale/dcl list messages}}
 
{{dcl list template | cpp/locale/dcl list messages}}
 
{{dcl list end}}
 
{{dcl list end}}
 +
 +
[[de:cpp/locale/messages byname]]
 +
[[es:cpp/locale/messages byname]]
 +
[[fr:cpp/locale/messages byname]]
 +
[[it:cpp/locale/messages byname]]
 +
[[ja:cpp/locale/messages byname]]
 +
[[pt:cpp/locale/messages byname]]
 +
[[ru:cpp/locale/messages byname]]
 +
[[zh:cpp/locale/messages byname]]

Revision as of 18:35, 2 November 2012

 
 
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
template< class CharT >
class messages_byname : public std::messages<CharT>;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

std::messages_byname is a std::messages facet which encapsulates retrieval of strings from message catalogs of the locale specified at its construction.

Two specializations are provided by the standard library

Defined in header <locale>
std::messages_byname<char> narrow/multibyte message catalog access
std::messages_byname<wchar_t> wide string message catalog access

Contents

Member types

Member type Definition
catalog std::messages_base<CharT>::catalog
string_type std::basic_string<CharT>

Member functions

constructs a new messages_byname facet
(public member function)
destructs a messages_byname facet
(protected member function)

Inherited from std::messages

Member types

Member type Definition
char_type CharT
string_type std::basic_string<CharT>

Member objects

Member name Type
id (static) std::locale::id

Member functions

invokes do_open
(public member function of std::messages<CharT>) [edit]
invokes do_get
(public member function of std::messages<CharT>) [edit]
invokes do_close
(public member function of std::messages<CharT>) [edit]

Protected member functions

[virtual]
opens a named message catalog
(virtual protected member function of std::messages<CharT>) [edit]
[virtual]
retrieves a message from an open message catalog
(virtual protected member function of std::messages<CharT>) [edit]
[virtual]
closes a message catalog
(virtual protected member function of std::messages<CharT>) [edit]

Example

#include <iostream>
#include <locale>
 
void try_with(const std::locale& loc)
{
    const std::messages<char>& facet = std::use_facet<std::messages<char> >(loc)
;
    std::messages<char>::catalog cat = facet.open("sed", std::cout.getloc());
    if(cat < 0 )
        std::cout << "Could not open german \"sed\" message catalog\n";
    else
        std::cout << "\"No match\" "
                  << facet.get(cat, 0, 0, "No match") << '\n'
                  << "\"Memory exhausted\" " 
                  << facet.get(cat, 0, 0, "Memory exhausted") << '\n';
    facet.close(cat);
}
int main()
{
    std::locale loc("en_US.utf8");
    std::cout.imbue(loc);
 
    try_with(std::locale(loc, new std::messages_byname<char>("de_DE.utf8")));
    try_with(std::locale(loc, new std::messages_byname<char>("fr_FR.utf8")));
    try_with(std::locale(loc, new std::messages_byname<char>("ja_JP.utf8")));
}

Possible output:

"No match" Keine Übereinstimmung
"Memory exhausted" Speicher erschöpft
"No match" Pas de concordance
"Memory exhausted" Mémoire épuisée
"No match" 照合しません
"Memory exhausted" メモリーが足りません

See also

Template:cpp/locale/dcl list messages