// Oldham, Jeffrey D. // 2000Mar13 // CS1321 // Brain-Dead String Editor Class Implementation // uses our dll class (and an iterator) #include "dll.h" #include class buffer { public: buffer(void) { pos = line.end(); } void backCursor(void) { if (pos != line.begin()) pos = pos->prev; // return; } void forwardCursor(void) { if (pos != line.end()) pos = pos->next; // } void deleteChar(void) { if (pos != line.end()) pos = line.erase(pos); } void insertChars(const string & s) { if (s.empty()) return; else { line.insert(pos, s[0]); insertChars(s.substr(1)); return; } } friend ostream& operator<<(ostream& out, const buffer & b) { for (dll::link * p = b.line.begin(); p != b.line.end(); p = p->next) // out << p->itm; return out; } // Print a line showing the cursor's position. friend ostream& printCursor(ostream& out, const buffer & b) { for (dll::link * p = b.line.begin(); p != b.pos; p = p->next) // out << ' '; return out << '^'; } private: dll line; // contents of line dll::link * pos; // points to where characters inserted // and deleted };