// These two lines and the last line in the file prevent // multiple-inclusion of this file. #ifndef LISTSTRING_H #define LISTSTRING_H // We are writing input and output routines for the ListString // class, so we need to have access to iostream #include using namespace std; // PREDECLARATIONS: These are the things that we are going to declare // in the file. We need to actually have them predeclared so that we // can seet up the friend relation between ListString and it's I/O // operators class ListString; ostream& operator << (ostream&, const ListString&); istream& operator >> (istream&, ListString&); // The ListString class interface class ListString { // These are the I/O operators. They CANNOT be members of // ListString, because that would required the ListString object // to appear on the left-hand side of any I/O statement: // myListString >> cout; // which is horribly non-standard and just a bad idea. Also, // we can't add these operators as members of ostream or istream, // because we don't have the code for those. So we have them // as independent functions, and make them friends so they can // get at private/protected members of ListString friend ostream& operator << (ostream&, const ListString&); friend istream& operator >> (istream&, ListString&); public: // Default constructor: empty string ListString(); // Copy the given C++ string ListString(const string&); // Copy constructor ListString(const ListString&); // Destructor ~ListString(); // This will set the current ListString to have the same // contents as the given ListString, and then return *this; ListString& operator = (const ListString&); ListString& operator = (const string&); // Comparison operators. // If you are smart, you'll only write == and <, the rest you // can build out of those. bool operator == (const ListString&) const; bool operator != (const ListString&) const; bool operator < (const ListString&) const; bool operator > (const ListString&) const; bool operator <= (const ListString&) const; bool operator >= (const ListString&) const; // Concatenation operators. // It is recommended to only write += and use that for + ListString operator + (const ListString&) const; // Remember: return *this; ListString& operator += (const ListString&); // Return a specific character within the string char& operator [] (int ind); // Return the length of the string. unsigned int size() const; // Cast to string: this will allow someone to write: // (string)myListString // and have it work properly operator string() const; // Return a new ListString that is a substring of this one, // including index "start" and going up to BUT NOT INCLUDING // index "end" ListString substr(int start, int end) const; // Modify the current ListString by removing the values between // start and end (including start, but not including end). ListString& erase(int start, int end); private: // You'll want to add things here class ListStringNode { public: string data; ListStringNode* next; }; ListStringNode* head; void cleanUp(); void copy(const ListString& toCopy); }; #endif // LISTSTRING_H