Chapter 10. RWWSubString - RWZoneSimple

RWWSubString

Synopsis

#include <rw/wstring.h>
 
RWWString s(L"test string");
s(6,3);   // "tri"

Description

The class RWWSubString allows some subsection of an RWWString to be addressed by defining a starting position and an extent. For example the 7th through the 11th elements, inclusive, would have a starting position of 7 and an extent of 5. The specification of a starting position and extent can also be done in your behalf by such functions as RWWString::strip() or the overloaded function call operator taking a regular expression as an argument. There are no public constructors —RWWSubStrings are constructed by various functions of the RWWString class and then destroyed immediately.

A zero lengthsubstring is one with a defined starting position and an extent of zero. It can be thought of as starting just before the indicated character, but not including it. It can be used as an lvalue. A null substring is also legal and is frequently used to indicate that a requested substring, perhaps through a search, does not exist. A null substring can be detected with member function isNull(). However, it cannot be used as an lvalue.

Persistence

None

Example

#include <rw/rstream.h>
#include <rw/wstring.h>
 
main(){
 RWWString s(L"What I tell you is true.");
 // Create a substring and use it as an lvalue:
 s(15,0) = RWWString(L" three times");
 cout << s << endl;
 return 0;
}

Program Output:

What I tell you three times is true.

Assignment Operators

void operator=(const RWWString&);

Assignment from an RWWString. The statements:

RWWString a;

RWWString b;

...

b(2, 3) = a;

will copy a's data into the substring b(2,3). The number of elements need not match: if they differ, b will be resized appropriately. If self is the null substring, then the statement has no effect.

void operator=(const wchar_t*);

Assignment from a wide character string. Example:

RWWString wstr(L"Mary had a little lamb");

wchar_t dat[] = L"Perrier";

wstr(11,4) = dat;// "Mary had a Perrier"

Note that the number of characters selected need not match: if they differ, wstr will be resized appropriately. If self is the null substring, then the statement has no effect.

Indexing Operators

wchar_t operator[](size_t i); wchar_t& operator[](size_t i) const;

Returns the ith character of the substring. The first variant can be used as an lvalue, the second cannot. The index i must be between zero and the length of the substring less one. Bounds checking is performed: if the index is out of range, then an exception of type RWBoundsErr will be thrown.

wchar_t operator()(size_t i); wchar_t& operator()(size_t i) const;

Returns the ith character of the substring. The first variant can be used as an lvalue, the second cannot. The index i must be between zero and the length of the substring less one. Bounds checking is enabled by defining the pre-processor macro RWBOUNDS_CHECK before including <rw/wstring.h>. In that case, if the index is out of range, then an exception of type RWBoundsErr will be thrown.

Public Member Functions

RWBoolean isNull() const;

Returns TRUE if this is a null substring.

size_t length() const;

Returns the extent (length) of the RWWSubString.

RWBoolean operator!() const;

Returns TRUE if this is a null substring.

size_t start() const;

Returns the starting element of the RWWSubString.

void toLower();

Changes all upper-case letters in self to lower-case. Uses the C library function towlower().

void toUpper();

Changes all lower-case letters in self to upper-case. Uses the C library function towupper().

Global Logical Operators

RWBoolean operator==(const RWWSubString&, const RWWSubString&); RWBoolean operator==(const RWWString&, const RWWSubString&); RWBoolean operator==(const RWWSubString&, const RWWString& ); RWBoolean operator==(const wchar_t*, const RWWSubString&); RWBoolean operator==(const RWWSubString&, const wchar_t* );

Returns TRUE if the substring is lexicographically equal to the wide character string or RWWString argument. Case sensitivity is exact.

RWBoolean operator!=(const RWWString&, const RWWString& ); RWBoolean operator!=(const RWWString&, const RWWSubString&); RWBoolean operator!=(const RWWSubString&, const RWWString& ); RWBoolean operator!=(const wchar_t*, const RWWString& ); RWBoolean operator!=(const RWWString&, const wchar_t* );

Returns the negation of the respective operator==()

RWWTokenizer

Synopsis

#include <rw/wtoken.h>
 
RWWString str("a string of tokens", RWWString::ascii);
RWWTokenizer(str);  // Lex the above string

Description

Class RWWTokenizer is designed to break a string up into separate tokens, delimited by arbitrary "white space." It can be thought of as an iterator for strings and as an alternative to the C library function wstok() which has the unfortunate side effect of changing the string being tokenized.

Persistence

None

Example

#include <rw/wtoken.h>
#include <rw/rstream.h>
 
main(){
  RWWString a(L"Something is rotten in the state of Denmark");
 
  RWWTokenizer next(a);   // Tokenize the string a
 
  RWWString token;        // Will receive each token
 
  // Advance until the null string is returned:
  while (!(token=next()).isNull())
    cout << token << "\n";
}

Program Output:

Something
is
rotten
in
the
state
of
Denmark

Public Constructor

RWWTokenizer(const RWWString& s);

Construct a tokenizer to lex the string s.

Public Member Function

RWWSubString operator();

Advance to the next token and return it as a substring. The tokens are delimited by any of the four wide characters in L" \t\n\0". (space, tab, newline and null).

RWWSubString operator()(const wchar_t* s);

Advance to the next token and return it as a widesubstring. The tokens are delimited by any wide character in s, or any embedded wide null.

RWWSubString operator()(const wchar_t* s,size_t num);

Advance to the next token and return it as a substring. The tokens are delimited by any of the first num wide characters in s. Buffer s may contain embedded nulls, and must contain at least num wide characters. Tokens will not be delimited by nulls unless s contains nulls.

RWXDRistream (Unix only)

              ->- RWvistream ->- RWvios 
RWXDRistream 
              ->- RWios 

Synopsis

#include <rw/xdrstrea.h>
 
XDR xdr;
xdrstdio_create(&xdr, stdin, XDR_DECODE);
RWXDRistream rw_xdr(&xdr);

Description

Class RWXDRistream is a portable input stream based on XDR routines. Class RWXDRistream encapsulates a portion of the XDR library routines that are used for external data representation. XDR routines allow programmers to describe arbitrary data structures in a machine-independent fashion. Data for remote procedure calls (RPC) are transmitted using XDR routines.

Class RWXDRistream enables one to decode an XDR structure to a machine representation. Class RWXDRistream provides the capability to decode all the standard data types and vectors of those data types.

An XDR stream must first be created by calling the appropriate creation routine. XDR streams currently exist for encoding/decoding of data to or from standard iostreams and file streams, TCP/IP connections and Unix files, and memory. These creation routines take arguments that are tailored to the specific properties of the stream. After the XDR stream has been created, it can then be used as the argument to the constructor for a RWXDRistream object.

RWXDRistream can be interrogated as to the status of the stream using member functions bad(), clear(), eof(), fail(), good(), and rdstate().

Persistence

None

Example

The example that follows is a "reader" program that decodes an XDR structure from a file stream. The example for class RWXDRostream is the "writer" program that encodes the XDR structures onto the file stream.

The library that supports XDR routines must be linked in. The name of this library is not standard.

#include <rw/xdrstrea.h>
 
#include <rw/rstream.h>
#include <stdio.h>
 
main(){
 XDR xdr;
 FILE* fp = fopen("test","r+");
 xdrstdio_create(&xdr, fp, XDR_DECODE);
  
 RWXDRistream rw_xdr(&xdr);
 int data;
 for(int i=0; i<10; ++i) {
   rw_xdr >> data;      // decode integer data
   if(data == i)
     cout << data << endl;
   else
     cout << "Bad input value" << endl;
 }
 fclose(fp);
}

Public Constructor

RWXDRistream(XDR* xp);

Initialize an RWXDRistream from the XDR structure xp.

RWXDristream(streambuf*);

Initialize RWXDRistream with a pointer to streambuf. Streambuf must be already allocated.

RWXDRistream(istream&);

Initialize RWXDRistream with an input stream.

Public Destructor

~virtual RWXDRistream();

Deallocate previously allocated resources.

Public Member Functions

virtual int get();

Redefined from class RWvistream. Gets and returns the next character from the XDR input stream. If the operation fails, it sets the failbit and returns EOF.

virtual RWvistream& get(char& c);

Redefined from class RWvistream. Gets the next character from the XDR input stream and stores it in c. If the operation fails, it sets the failbit. This member only preserves ASCII numerical codes, not the coresponding character symbol.

virtual RWvistream& get(wchar_t& wc);

Redefined from class RWvistream. Gets the next wide character from the XDR input stream and stores it in wc. If the operation fails, it sets the failbit.

virtual RWvistream& get(unsigned char& c);

Redefined from class RWvistream. Gets the next unsigned character from the XDR input stream and stores it in c. If the operation fails, it sets the failbit.

virtual RWvistream& get(char* v, size_t N);

Redefined from class RWvistream. Gets a vector of N characters from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(unsigned char* v, size_t N);

Redefined from class RWvistream. Gets a vector of N unsigned characters from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(double* v, size_t N);

Redefined from class RWvistream. Gets a vector of N doubles from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(float* v, size_t N);

Redefined from class RWvistream. Gets a vector of N floats from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(int* v, size_t N);

Redefined from class RWvistream. Gets a vector of Nints from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(unsigned int* v, size_t N);

Redefined from class RWvistream. Gets a vector of N unsigned ints from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(long* v, size_t N);

Redefined from class RWvistream. Gets a vector of N longs from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(unsigned long* v, size_t N);

Redefined from class RWvistream. Gets a vector of N unsigned longs from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(short* v, size_t N);

Redefined from class RWvistream. Gets a vector of N shorts from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(unsigned short* v, size_t N);

Redefined from class RWvistream. Gets a vector of N unsigned shorts from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& get(wchar_t* v, size_t N);

Redefined from class RWvistream. Gets a vector of N wide characters from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.

virtual RWvistream& getString(char* s, size_t maxlen);

Redefined from class RWvistream. Restores a character string from the XDR input stream that was stored to the XDR output stream with RWXDRistream::putstring and stores the characters in the array starting at s. The function stops reading at the end of the string or after maxlen-1 characters, whichever comes first. If maxlen-1 characters have been read and the maxlenth character is not the string terminator, then the failbit of the stream will be set. In either case, the string will be terminated with a null byte.

virtual RWvistream& operator>>(char& c );

Redefined from class RWvistream. Gets the next character from the XDR input stream and stores it in c. If the operation fails, it sets the failbit. This member attempts to preserve the symbolic characters' values transmitted over the stream.

virtual RWvistream& operator>>(double& d);

Redefined from class RWvistream. Gets the next double from the XDR input stream and stores it in d. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(float& f);

Redefined from class RWvistream. Gets the next float from the XDR input stream and stores it in f. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(int& i);

Redefined from class RWvistream. Gets the next integer from the XDR input stream and stores it in i. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(long& l);

Redefined from class RWvistream. Gets the next long from the XDR input stream and stores it in l. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(short& s);

Redefined from class RWvistream. Gets the next short from the XDR input stream and stores it in s. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(wchar_t& wc);

Redefined from class RWvistream. Gets the next wide character from the XDR input stream and stores it in wc. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(unsigned char& c);

Redefined from class RWvistream. Gets the next unsigned character from the XDR input stream and stores it in c. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(unsigned int& i);

Redefined from class RWvistream. Gets the next unsigned integer from the XDR input stream and stores it in i. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(unsigned long& l);

Redefined from class RWvistream. Gets the next unsigned long from the XDR input stream and stores it in l. If the operation fails, it sets the failbit.

virtual RWvistream& operator>>(unsigned short& s);

Redefined from class RWvistream. Gets the next unsigned short from the XDR input stream and stores it in s. If the operation fails, it sets the failbit.

RWXDRostream (Unix only)

             ->- RWvostream ->- RWvios 
RWXDRostream 
             ->- RWios 

Synopsis

#include <rw/xdrstrea.h>
 
XDR xdr;
xdrstdio_create(&xdr, stdout, XDR_ENCODE) ;
RWXDRostream rw_xdr(&xdr);

Description

Class RWXDRostream is a portable output stream based on XDR routines. Class RWXDRostream encapsulates a portion of the XDR library routines that are used for external data representation. XDR routines allow programmers to describe arbitrary data structures in a machine-independent fashion. Data for remote procedure calls (RPC) are transmitted using XDR routines.

Class RWXDRostream enables one to output from a stream and encode an XDR structure from a machine representation. Class RWXDRostream provides the capability to encode the standard data types and vectors of those data types.

An XDR stream must first be created by calling the appropriate creation routine. XDR streams currently exist for encoding/decoding of data to or from standard iostreams and file streams, TCP/IP connections and Unix files, and memory. These creation routines take arguments that are tailored to the specific properties of the stream. After the XDR stream has been created, it can then be used as an argument to the constructor for a RWXDRostream object.

RWXDRostream can be interrogated as to the status of the stream using member functions bad(), clear(), eof(), fail(), good(), and rdstate().

Persistence

None

Example

The example that follows is a "writer" program that encodes an XDR structure onto a file stream. The example for class RWXDRistream is the "reader" program that decodes the XDR structures into a machine representation for a data type. The library that supports XDR routines must be linked in. The name of this library is not standard.

#include <rw/xdrstrea.h>
 
#include <rw/rstream.h>
#include <stdio.h>
 
main(){
 XDR xdr;
 FILE* fp = fopen("test","w+");
 xdrstdio_create(&xdr, fp, XDR_ENCODE);
 
 RWXDRostream rw_xdr(&xdr);
 for(int i=0; i<10; ++i)
 rw_xdr << i;                       // encode integer data
 fclose(fp);
}

Public Constructor

RWXDRostream(XDR* xp);

Initialize a RWXDRostream from the XDR structure xp.

RWXDRostream(streambuf*);

Initialize RWXDRostream with a pointer to streambuf. streambuf must already be allocated.

RWXDRostream(ostream&);

Initialize RWXDRostream with an output stream.

Public Destructor

virtual ~RWXDRostream();

Deallocate previously allocated resources.

Public Member Functions

virtual RWvostream& operator<<(const char* s);

Redefined from class RWvostream. Store the character string starting at s to the output stream using the XDR format. The character string is expected to be null terminated.

virtual RWvostream& operator<<(char c);

Redefined from class RWvostream. Store the character c to the output stream using the XDR format. Note that c is treated as a character, not a number. This member attempts to preserve the symbolic characters values transmitted over the stream.

virtual RWvostream& operator<<(wchar_t wc);

Redefined from class RWvostream. Store the wide character wc to the output stream using the XDR format. Note that wc is treated as a character, not a number.

virtual RWvostream& operator<<(unsigned char c);

Redefined from class RWvostream. Store the unsigned character c to the output stream using the XDR format. Note that c is treated as a character, not a number.

virtual RWvostream& operator<<(double d);

Redefined from class RWvostream. Store the doubled to the output stream using the XDR format.

virtual RWvostream& operator<<(float f);

Redefined from class RWvostream. Store the floatf to the output stream using the XDR format.

virtual RWvostream& operator<<(int i);

Redefined from class RWvostream. Store the integer i to the output stream using the XDR format.

virtual RWvostream& operator<<(unsigned int i);

Redefined from class RWvostream. Store the unsigned integer i to the output stream using the XDR format.

virtual RWvostream& operator<<(long l);

Redefined from class RWvostream. Store the longl to the output stream using the XDR format.

virtual RWvostream& operator<<(unsigned long l);

Redefined from class RWvostream. Store the unsigned longl to the output stream using the XDR format.

virtual RWvostream& operator<<(short s);

Redefined from class RWvostream. Store the shorts to the output stream using the XDR format.

virtual RWvostream& operator<<(unsigned short );

Redefined from class RWvostream. Store the unsigned shorts to the output stream using the XDR format.

virtual RWvostream& put(char c);

Redefined from class RWvostream. Store the character c to the output stream using the XDR format. If the operation fails, it sets the failbit. This member only preserves ASCII numerical codes, not the coresponding character symbol.

virtual RWvostream& put(unsigned char c);

Redefined from class RWvostream. Store the unsigned character c to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(wchar_t wc);

Redefined from class RWvostream. Store the wide character wc to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const char* p, size_t N);

Redefined from class RWvostream. Store the vector of N characters starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const wchar_t* p, size_t N);

Redefined from class RWvostream. Store the vector of N wide characters starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const short* p, size_t N);

Redefined from class RWvostream. Store the vector of N shorts starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const unsigned short* p, size_t N);

Redefined from class RWvostream. Store the vector of N unsigned shorts starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const int* p, size_t N);

Redefined from class RWvostream. Store the vector of N integers starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const unsigned int* p, size_t N);

Redefined from class RWvostream. Store the vector of N unsigned integers starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const long* p, size_t N);

Redefined from class RWvostream. Store the vector of N longs starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const unsigned long* p, size_t N);

Redefined from class RWvostream. Store the vector of N unsigned longs starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const float* p, size_t N);

Redefined from class RWvostream. Store the vector of N floats starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

virtual RWvostream& put(const double* p, size_t N);

Redefined from class RWvostream. Store the vector of N doubles starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.

Virtual RWXDRostream& flush();

Send the contents of the stream buffer to output immediately.

Virtual RWXDRostream& putString(const char*s, size_t N);

Store the character string for retrieval by RWXDRistream::getString.

RWZone

Synopsis

#include <time.h>
 
#include <rw/zone.h>
 
(abstract base class) 
 

Description

RWZone is an abstract base class. It defines an interface for time zone issues such as whether or not daylight-saving time is in use, the names and offsets from UTC (also known as GMT) for both standard and daylight-saving times, and the start and stop dates for daylight-saving time, if used.

Note that because it is an abstract base class, there is no way to actually enforce these goals — the description here is merely the model of how a class derived from RWZone should act.

Most programs interact with RWZone only by passing an RWZone reference to an RWTime or RWDate member function that expects one.

RWZoneSimple is an implementation of the abstract RWZone interface sufficient to represent U.S. daylight-saving time rules. Three instances of RWZoneSimple are initialized from the global environment at program startup to represent local, standard, and universal time. They are available via calls to the static member functions RWZone::local(), RWZone::standard(), and RWZone::utc(), respectively. See the class RWZoneSimple for details.

Persistence

None

Example

#include <rw/zone.h>
#include <rw/rwtime.h>
#include <rw/rstream.h>
 
main(){
 RWTime now;
 cout << now.asString(`\0', RWZone::local()) << endl;
 cout << now.asString("%x %X", RWZone::utc()) << endl;
 return 0;
}

Enumerations

enum DstRule { NoDST, NoAm, WeEu };

Used by the static member function dstRule(), described below, and by constructors for classes derived from RWZone.

enum StdZone { NewZealand = -12, CarolineIslands, MarianaIslands, Japan, China, Java, Kazakh, Pakistan, CaspianSea, Ukraine, Nile, Europe, Greenwich, Azores, Oscar, Greenland, Atlantic, USEastern, USCentral, USMountain, USPacific, Yukon, Hawaii, Bering };

StdZone is provided to name the standard time zones. Its values are intended to be passed to constructors of classes derived from RWZone.

Public Member Functions

virtual int timeZoneOffset() const = 0;

Returns the number of seconds west of UTC for standard time in this zone. The number is negative for zones east of Greenwich, England.

virtual int altZoneOffset() const = 0;

Returns the number of seconds west of UTC for daylight-saving time in this zone.

virtual RWBoolean daylightObserved() const = 0;

Returns TRUE if daylight-saving time is observed for this zone.

virtual RWBoolean isDaylight(const struct tm* tspec) const = 0;

Returns TRUE if the time and date represented in the struct tm argument is in the range of daylight-saving time for this zone. The elements of the tm argument must all be self-consistent; in particular, the tm_wday member must agree with the tm_year, tm_mon, and tm_day members.

virtual void getBeginDaylight(struct tm*) const = 0; virtual void getEndDaylight (struct tm*) const = 0;

Return with the struct tm argument set to the local time that daylight-saving time begins, or ends, for the year indicated by the tm_year member passed in. If daylight-saving time is not observed, the struct tm members are all set to a negative value. Note that in the southern hemisphere, daylight-saving time ends at an earlier date than it begins.

virtual RWCString timeZoneName() const = 0; virtual RWCString altZoneName() const = 0;

Return the name of, respectively, the standard and daylight-saving time zones represented, such as "PST" and "PDT". Note that the current date and time have no effect on the return values of these functions.

Static Public Member Functions

static const RWZone& local();

Returns a reference to an RWZone representing local time. By default this will be an instance of RWZoneSimple created with offsets and zone names from the operating system, with U.S. rules for daylight-saving time if observed. This is used as the default argument value for RWDate and RWTime functions that take an RWZone.

static const RWZone& standard();

Returns a reference to an RWZone representing standard local time, with no daylight-saving time corrections. By default this is an instance of RWZoneSimple with offset and zone name from the operating system.

static const RWZone& utc();

Returns a reference to an RWZone representing UTC (GMT) universal time.

static const RWZone* local(const RWZone*); static const RWZone* standard(const RWZone*);

These functions allow the values returned by the other functions above to be set. Each returns the previous value.

static constRWDaylightRule* dstRule(DstRule rule = NoAm);

Returns one of the built-in daylight-saving time rules according to rule. Function dstRule() is provided for convenience in constructing RWZoneSimple instances for time zones in which common daylight-saving time rules are obeyed. Currently two such rule systems are provided, NoAm for the U.S.A. and Canada, and WeEu for most of Western Europe (excluding the U.K.). See RWZoneSimple for more details. If DstRuleNoDST is given, then 0 is returned. The result of calling dstRule() is normally passed to the RWZoneSimple constructor.

RWZoneSimple

RWZoneSimple ->- RWZone 

Synopsis

#include <time.h>
 
#include <rw/zone.h>
 
RWZoneSimple myZone(USCentral);

Description

RWZoneSimple is an implementation of the abstract interface defined by class RWZone. It implements a simple daylight-saving time rule sufficient to represent all historical U.S. conventions and many European and Asian conventions. It is table-driven and depends on parameters given by the struct RWDaylightRule, which is described below.

Direct use of RWDaylightRule affords the most general interface to RWZoneSimple. However, a much simpler programmatic interface is offered, as illustrated by the examples below.

Three instances of RWZoneSimple are automatically constructed at program startup, to represent UTC, Standard, and local time. They are available via calls to the static member functions RWZone::utc(), RWZone::standard(), and RWZone::local(), respectively.

These member functions are set up according to the time zone facilities provided in the execution environment (typically defined by the environment variable TZ). By default, if DST is observed at all, then the local zone instance will use U.S. (RWZone::NoAm) daylight-saving time rules.

Note for developers outside North America: for some time zones this default will not be correct because these time zones rely on the C standard global variable _daylight. This variable is set whenever any alternate time zone rule is available, whether it represents daylight-saving time or not. Also the periods of history affected by daylight-saving time may be different in your time zone from those in North America, causing the North American rule to be erroneously invoked. The best way to ensure that these default time zones are correct is to construct an RWZoneSimple using an appropriate RWDaylightRule and initialize RWZone::local() and RWZone::std() with this value.

Other instances of RWZoneSimple may be constructed to represent other time zones, and may be installed globally using RWZone static member functions RWZone::local(constRWZone*) and RWZone::standard(const RWZone*).

Persistence

None

Examples

To install US Central time as your global "local" time use:

RWZone::local(new RWZoneSimple(RWZone::USCentral));

To install Hawaiian time (where daylight-saving time is not observed) one would say,

RWZone::local(new RWZoneSimple(RWZone::Hawaii, RWZone::NoDST));

Likewise for Japan:

RWZone::local(new RWZoneSimple(RWZone::Japan, RWZone::NoDST));

For France:

RWZone::local(new RWZoneSimple(RWZone::Europe, RWZone::WeEu));

Here are the rules used internally for the RWZone::NoAm and RWZone::WeEu values of RWZone::DstRule:

// last Sun in Apr to last in Oct:
     const RWDaylightRule  usRuleAuld =
     { 0, 0000, 1, { 3, 4, 0, 120 }, { 9, 4, 0, 120 } };
// first Sun in Apr to last in Oct
     const RWDaylightRule usRule67 =
     { &usRuleAuld, 1967, 1, { 3, 0, 0, 120 }, { 9, 4, 0, 120 } };
// first Sun in Jan to last in Oct:
     const RWDaylightRule usRule74 =
     { &usRule67, 1974, 1, { 0, 0, 0, 120 }, { 9, 4, 0, 120 } };
// last Sun in Feb to last in Oct
     const RWDaylightRule usRule75 =
    { &usRule74, 1975, 1, { 1, 4, 0, 120 }, { 9, 4, 0, 120 } };
// last Sun in Apr to last in Oct
     const RWDaylightRule usRule76 =
     { &usRule75, 1976, 1, { 3, 4, 0, 120 }, { 9, 4, 0, 120 } };
// first Sun in Apr to last in Oct
     const RWDaylightRule usRuleLate =
     { &usRule76, 1987, 1, { 3, 0, 0, 120 }, { 9, 4, 0, 120 } };
 
// last Sun in Mar to last in Sep
     const RWDaylightRule euRuleLate =
     { 0, 0000, 1, { 2, 4, 0, 120 }, { 8, 4, 0, 120 } };

Given these definitions,

RWZone::local(new RWZoneSimple(RWZone::USCentral, &usRuleLate));

is equivalent to the first example given above and repeated here:

RWZone::local(new RWZoneSimple(RWZone::USCentral));

Daylight-saving time systems that cannot be represented with RWDaylightRule and RWZoneSimple must be modeled by deriving from RWZone and implementing its virtual functions.

For example, under Britain's Summer Time rules, alternate timekeeping begins the morning after the third Saturday in April, unless that is Easter (in which case it begins the week before) or unless the Council decides on some other time for that year. In some years Summer Time has been two hours ahead, or has extended through winter without a break. British Summer Time clearly deserves an RWZone class all its own.

Constructors

RWZoneSimple(RWZone::StdZone zone, RWZone::DstRule = RWZone::NoAm);

Constructs an RWZoneSimple instance using internally held RWDaylightRules. This is the simplest interface to RWZoneSimple. The first argument is the time zone for which an RWZoneSimple is to be constructed. The second argument is the daylight-saving time rule which is to be followed.

RWZoneSimple(const RWDaylightRule* rule, long tzoff, const RWCString& tzname, long altoff, const RWCString& altname);

Constructs an RWZoneSimple instance which daylight-saving time is computed according to the rule specified. Variables tzoff and tzname are the offset from UTC (in seconds, positive if west of 0 degrees longitude) and the name of standard time. Arguments altoff and altname are the offset (typically equal to tzoff - 3600) and name when daylight-saving time is in effect. If rule is zero, daylight-saving time is not observed.

RWZoneSimple(long tzoff, const RWCString& tzname);

Constructs an RWZoneSimple instance in which daylight-saving time is not observed. Argument tzoff is the offset from UTC (in seconds, positive if west of 0 degrees longitude) and tzname is the name of the zone.

RWZoneSimple(RWZone::StdZone zone, const RWDaylightRule* rule);

Constructs an RWZoneSimple instance in which offsets and names are specified by the StdZone argument. Daylight-saving time is computed according to the rule argument, if non-zero; otherwise, DST is not observed.

struct RWDaylightRule

The RWDaylightRule struct passed to RWZoneSimple's constructor can be a single rule for all years or can be the head of a chain of rules going backwards in time.

RWDaylightRule is a struct with no constructors. It can be initialized with the syntax used in the Examples section above. The data members of this structure are as follows:

struct RWExport RWDaylightRule {
RWDaylightRule const* next_;
short firstYear_;
char observed_;
RWDaylightBoundary begin_; 
RWDaylightBoundary end_;
}

RWDaylightRule const* next_;

Points to the next rule in a chain which continues backwards in time.

short firstYear_;

Four digit representation of the year in which this rule first goes into effect.

char observed_;

A boolean value that can be used to specify a period of years for which daylight-saving time is not observed.

1 = Daylight-saving time is in effect during this period

0 = Daylight-saving time is not in effect during this period

(Note that these are numeric values as distinguished from '1' and '0'.)

RWDaylightBoundary begin_;

This structure indicates the time of year, to the minute, when DST begins during this period. (See RWDaylightBoundary below.)

RWDaylightBoundary end_;

This structure indicates the time of year, to the minute, when standard time resumes during this period. (See RWDaylightBoundary below.)

struct RWDaylight-Boundary

struct RWExport RWDaylightBoundary {
 
// this struct uses <time.h> struct tm conventions:
int month_;    // [0..11]
int week_;     // [0..4], or -1
int weekday_;  // [0..6], 0=Sunday; or, [1..31] if week_== -1
int minute_;   // [0..1439]  (Usually 2 AM, = 120)
};

int month_;

The month from (0 - 11), where 0 = January.

int week_;

A week of the month from (0 - 4), or -1 if the following field is to represent a day within the month.

int weekday_;

A day of the week from (0 - 6), where 0 = Sunday, or, if the week_ field is -1, a day of the month from (1 - 31).

int minute_;

Minutes after 12:00 AM, from (0 - 1439). For example, 120 = 2 AM.