Tools.h++ Manual
104011 Tandem Computers Incorporated 4-3
4
The Standard C Library provides, with
<locale.h>
, some facilities to
accommodate differences in currency, number, date, and time formats, but it is
maddeningly incomplete. It offers no help for conversion from strings to these
types, and is practically impossible to use if you must do conversions
involving two or more locales. Common time zone facilities (such as those
defined in POSIX.1) are similarly limited, usually offering no way to compute
wall clock time for other locations, or even for the following year in the same
location.
4.1 RWLocale and RWZone
Tools.h++ addresses these problems with the abstract classes
RWLocale
and
RWZone
. If you have used
RWDate
you have used
RWLocale
already, perhaps
unknowingly. Every time you convert a date or time to or from a string, a
default argument carries along a
RWLocale
reference. This is a reference to a
global instance of the class
RWLocaleDefault
(derived from
RWLocale
)
which was created at program startup. To use
RWLocale
explicitly, construct
your own instance and pass it in place of the default. Similarly, when you
manipulate times, a default
RWZone
reference is passed along, but you can
substitute your own.
You can also install your own instance of
RWLocale
or
RWZone
as the global
default. You can even install your
RWLocale
instance in a stream (this is
called “imbuing the stream”) so that dates and times inserted on (or extracted
from) that stream are formatted (or parsed) accordingly, without any special
arguments.
Let us look at how all this works, with some examples. Here are the header
files we will use:
#incluce <assert.h>
#include <rw/rstream.h>
#include <rw/cstring.h>
#include <rw/locale.h>
#include <rw/rwdate.h>
#include <rw/rwtime.h>