Click on the banner to return to the Class Reference home page.

©Copyright 1996 Rogue Wave Software

RWLocaleSnapshot


RWLocaleSnapshotRWLocale

Synopsis

#include <locale.h>
#include <rw/locale.h>

RWLocaleSnapshot ourLocale("");  // encapsulate user's formats

Description

The class RWLocaleSnapshot implements the RWLocale interface using Standard C library facilities. To use it, the program creates an RWLocaleSnapshot instance. The constructor of the instance queries the program's environment (using standard C library functions such as localeconv(), strftime(), and, if available , vendor specific library functions) to learn everything it can about formatting conventions in effect at the moment of instantiation. When done, the locale can then be switched and another instance of RWLocaleSnapshot created. By creating multiple instances of RWLocaleSnapshot, your program can have more than one locale active at the same time, something that is difficult to do with the Standard C library facilities.

Note: RWLocaleSnapshot does not encapsulate character set, collation, or message information.

Class RWLocaleSnapshot has a set of public data members initialized by its constructor with information extracted from its execution environment.

Persistence

None

Example

Try this program with the environmental variable LANG set to various locales:

#include <rw/rwdate.h>
#include <rw/locale.h>
#include <iostream.h>
main(){
 RWLocaleSnapshot *userLocale = new RWLocaleSnapshot("");
 RWLocale::global(userLocale);
 // Print a number using the global locale:
 cout << RWLocale::global().asString(1234567.6543) << endl;
 // Now get and print a date:
 cout << "enter a date: " << flush;
 RWDate date;
 cin >> date;
 if (date.isValid())
 cout << date << endl;
 else
 cout << "bad date" << endl;
 delete userLocale;
 return 0;
}

Enumerations

enum 
RWDateOrder { DMY, MDY, YDM, YMD };

Public Constructor

RWLocaleSnapshot(const char* localeName = 0);

Public Member Functions

virtual RWCString
asString(long) const;
virtual RWCString
asString(unsigned long) const;
virtual RWCString
asString(double f, int precision = 6,
RWBoolean showpoint = 0) const;
virtual RWCString
asString(struct tm* tmbuf,char format, const RWZone& zone);
         const;
virtual RWCString
asString(struct tm* tmbuf,char* format, 
         const RWZone& zone) const;
virtual RWCString
moneyAsString(double value,enum CurrSymbol = LOCAL) const;
virtual RWBoolean
stringToNum  (const RWCString&, double* fp) const;
virtual RWBoolean
stringToNum  (const RWCString&, long* ip  ) const;
virtual RWBoolean
stringToDate (const RWCString&, struct tm*) const;
virtual RWBoolean
stringToTime (const RWCString&, struct tm*) const;
virtual RWBoolean
stringToMoney(const RWCString&, double*   ,
              RWLocale::CurrSymbol=LOCAL) const;

Public Data Members

RWCString     decimal_point_;
RWCString     thousands_sep_;
RWCString     grouping_;
RWCString     int_curr_symbol_;
RWCString     currency_symbol_;
RWCString     mon_decimal_point_;
RWCString     mon_thousands_sep_;
RWCString     mon_grouping_;
RWCString     positive_sign_;
RWCString     negative_sign_;
char          int_frac_digits_;
char          frac_digits_;
char          p_cs_precedes_;
char          p_sep_by_space_;
char          n_cs_precedes_;
char          n_sep_by_space_;
char          p_sign_posn_;
char          n_sign_posn_;