_EXAMINING ROGUEWAVE'S TOOLS.H++_ by P.W. Scherer Listing One RWCString wonderTool("Rogue"); wonderTool += "Wave tools.h++"; cout << wonderTool << endl; // Prints "RogueWave tools.h++" // ( '+=' concatenates) RWCString aString = "I am 34.5 years young"; RWCRegexp re1("[0-9]+*[\\.]*[0-9]*"); // Construct regexp object. // Recognizes decimal #s. aString(re1) = "184.9"; cout << aString << endl; // Prints "I am 184.9 years young" Listing Two size_t ind = aString.index ( "young" ); aString(ind,0) = "old"; cout << aString << endl; // Prints "I am 184.9 years old" RWCTokenizer tok ( aString ); // Class RWCTokenizer performs // strtok-like functions. cout << tok() << endl; // Prints "I" cout << tok() << endl; // Prints "am" cout << aString << endl; // Prints "I am 184.9 years old" Listing Three RWDate today; cout << today << endl; // Prints the current date (default constructor) RWDate weekAgo = today-7; // Subtracts 7 days from today. RWDate myBirthDay ( 24, 2, 61); // m,d,y constructor. cout << myBirthDay.weekDayName() << endl; // Prints "Sunday"! cout << today - myBirthDay << endl; // Prints number of days I've been alive. Listing Four // This example alters the date string for French-speaking users. RWLocale& french = *new RWLocaleSnapshot("fe"); cout << myBirthday.asString ( 'x', french ) << endl; Listing Six struct XYPoint { RWDate xDate; // Independent (X) value. float yValue; // Dependent (Y) value. RWCString ptDescription; // Text associated w/point. }; Listing Six class XYPoint { private: RWDate xDate; // Independent (X) value. float yValue; // Dependent (Y) value. RWCString ptDescription;// Text associated w/point public: // Main constructor. XYPoint ( unsigned mo, unsigned day, unsigned year, float val, const char* descrip ) : xDate ( day, mo, year ), yValue(val), ptDescription ( descrip ) { } // Key-only constructor. XYPoint ( unsigned mo, unsigned day, unsigned year ) : xDate ( day, mo, year), yValue(0.0), ptDescription() { } // Default constructor. XYPoint() : xDate(), yValue(-9999.99), ptDescription() { } // Copy constructor. XYPoint ( const XYPoint& xyp ) : xDate(xyp.xDate), yValue(xyp.yValue), ptDescription(xyp.ptDescription ) { } // Assignment operator = XYPoint& operator=(const XYPoint& xyp ) { xDate = xyp.xDate; yValue = xyp.yValue; ptDescription = xyp.ptDescription; } // Equality == operator RWBoolean operator==( const XYPoint& xyp ) const { if ( xDate == xyp.xDate ) return TRUE; else return FALSE; } // Less then < operator. RWBoolean operator<( const XYPoint& xyp ) const { if ( xDate < xyp.xDate ) return TRUE; else return FALSE; } }; Listing Seven RWTValSortedVector myValCurve; // Create a new curve of XYPoints. // Insert 1/1/95, 2/1/95, 3/1/95, 4/1/95 data points into curve. myValCurve.insert ( XYPoint ( 1, 1, 95, 1000.0, "Point 1" ) ); myValCurve.insert ( XYPoint ( 1, 2, 95, 1050.0, "Point 2" ) ); myValCurve.insert ( XYPoint ( 1, 4, 95, 2000.0, "Point 4" ) ); myValCurve.insert ( XYPoint ( 1, 3, 95, 1500.0, "Point 3" ) ); // Value-based collection now has 4 points in correct order. XYPoint locator ( 1, 1, 95 ); // Create a temporary point to be // used for searching. myValCurve.remove ( locator ); // Remove the first point only. cout << myValCurve.entries() << endl; // Prints '3', since 3 pts are left. myValCurve.clear(); // Removes all elements. RWTPtrSortedVector myPtrCurve; // Pointer-based analog of above. myPtrCurve.insert ( new XYPoint ( 1, 1, 95, 1000.0, "Point 1" ) ); myPtrCurve.insert ( new XYPoint ( 1, 2, 95, 1050.0, "Point 2" ) ); ... ... // Pointer-based collection must explicitly free the dynamically // allocated points! This can be the source of huge memory leak! BEWARE! ;-) myPtrCurve.clearAndDestroy(); // Deletes each XYPoint and // removes from collection. Listing Eight RWvostream& operator<< ( RWvostream& s ) const { s << xDate << yValue << ptDescription; return s; } RWvistream& operator>> ( RWvistream& s ) { s >> xDate >> yValue >> ptDescription; return s; } Listing Nine RWFileManager fm("mydb.dat"); // Create file manager class on a disk file. RWBTreeOnDisk bt(fm); // Construct B-Tree for the file manager. RWCString myAddress ( "11915 Merry Lane" ); RWOffset loc = fm.allocate ( myAddress.binaryStoreSize() ); fm.SeekTo ( loc ); fm << myAddress; bt.insertKeyAndValue ( "Perry", loc ); Listing Ten RWOffset foundLoc = bt.findValue ( "Perry" ); fm.SeekTo ( foundLoc ); RWCString foundAddress; fm >> foundAddress; cout << "My address is: " << foundAddress << endl;