CppCMS
Classes | Public Types | Public Member Functions
booster::locale::basic_format< CharType > Class Template Reference

a printf like class that allows type-safe and locale aware message formatting More...

#include <booster/booster/locale/format.h>

List of all members.

Classes

class  format_guard

Public Types

typedef CharType char_type
 Underlying character type.
typedef basic_message< char_typemessage_type
typedef std::basic_string
< CharType > 
string_type
typedef std::basic_ostream
< CharType > 
stream_type
 output stream type for this type of character

Public Member Functions

 basic_format (string_type format_string)
 basic_format (message_type const &trans)
template<typename Formattible >
basic_formatoperator% (Formattible const &object)
string_type str (std::locale const &loc=std::locale()) const
void write (stream_type &out) const

Detailed Description

template<typename CharType>
class booster::locale::basic_format< CharType >

a printf like class that allows type-safe and locale aware message formatting

This class creates a formatted message similar to printf or boost::format and receives formatted entries via operator %.

For example

  cout << format("Hello {1}, you are {2} years old") % name % age << endl;

Formatting is enclosed between curly brackets { } and defined by a comma separated list of flags in the format key[=value] value may also be text included between single quotes ' that is used for special purposes where inclusion of non-ASCII text is allowed

Including of literal { and } is possible by specifying double brackets {{ and }} accordingly.

For example:

   cout << format("The height of water at {1,time} is {2,num=fixed,precision=3}") % time % height;

The special key -- a number without a value defines the position of an input parameter. List of keys:

Invalid formatting strings are slightly ignored. This would prevent from translator to crash the program in unexpected location.


Member Typedef Documentation

template<typename CharType >
typedef basic_message<char_type> booster::locale::basic_format< CharType >::message_type

The translation message type

template<typename CharType >
typedef std::basic_string<CharType> booster::locale::basic_format< CharType >::string_type

string type for this type of character


Constructor & Destructor Documentation

template<typename CharType >
booster::locale::basic_format< CharType >::basic_format ( string_type  format_string) [inline]

Create a format class for format_string

template<typename CharType >
booster::locale::basic_format< CharType >::basic_format ( message_type const &  trans) [inline]

Create a format class using message trans. The message if translated first according to the rules of target locale and then interpreted as format string


Member Function Documentation

template<typename CharType >
template<typename Formattible >
basic_format& booster::locale::basic_format< CharType >::operator% ( Formattible const &  object) [inline]

Add new parameter to format list. The object should be a type with defined expression out << object where out is std::basic_ostream.

template<typename CharType >
string_type booster::locale::basic_format< CharType >::str ( std::locale const &  loc = std::locale()) const [inline]

Format a string using a locale loc

References booster::locale::basic_format< CharType >::write().

template<typename CharType >
void booster::locale::basic_format< CharType >::write ( stream_type out) const [inline]

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