//************** // // cdata.h // defines and implements the concordance // data class. the concordance tree (ctree.h) // is derived from a BST of cdata elements // BST // // this is the class that is stored in the // BST's Tree_Node (the "Element") // // DL Frey 10/21/98 //************************* #ifndef __CDATA_H_ #define __CDATA_H_ #include #include // define a class for the // concordance data -- a string and a count #include "String.h" class CData { private: String text; int count; public: // constructor -- take a 'C' string // and defaults the count to 1 CData (const char *s, int c = 1) : text(s), count (c) {} // do-nothing destructor // will cause the String destructor to be invoked ~CData () {} // accessors int getCount () const { return count; } void Increment () { ++count; } const char * getText () const {return (const char *)text;} // relational operators <, >, == // just compare the text part // these comparisons cause the corresponding // operator for the String class to be invoked friend int operator < (const CData& d1, const CData& d2) { return (d1.text < d2.text); } friend int operator > (const CData& d1, const CData& d2) { return (d1.text > d2.text); } friend int operator== (const CData& d1, const CData& d2) { return (d1.text == d2.text); } // output operator -- so we can print ourselves out // when the tree does it's traversal friend ostream& operator<< (ostream& out, const CData& data) { out << setw(20) << data.text << setw(6) << data.count; return out; } // assignment operator CData& operator= (const CData& rhs) { // this invokes the String class operator= text = rhs.text; count = rhs.count; return *this; } }; #endif