/*************************************************************************** editablestreamhistory.h - description ------------------- begin : Sun Jul 9 2000 copyright : (C) 2000 by Artur Rataj email : art@zeus.polsl.gliwice.pl ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef EDITABLESTREAMHISTORY_H #define EDITABLESTREAMHISTORY_H /** A template class adding undo/redo history for EDITABLE_STREAM paste and cut * methods * @author Artur Rataj */ template class EditableStreamHistory { public: /** Constructs the class with stream as an EDITABLE_STREAM and * a given number of undo levels */ EditableStreamHistory(EDITABLE_STREAM* stream, const int undoLevels); ~EditableStreamHistory(); /** Cuts a stream at index, of length length. * Uses undo/redo history. * @return A stream that has been cut out */ EDITABLE_STREAM cut(const int index, const int length); /** Pastes a stream at index. Uses undo/redo history */ void paste(const int index, EDITABLE_STREAM& pasteStream); /** Replaces a stream at index. Uses undo/redo history */ void replace(const int index, EDITABLE_STREAM& replaceStream); /** @return Whether undo possible */ bool undoPossible(); /** @return Whether redo possible */ bool redoPossible(); /** Undoes if possible */ void undo(); /** Redoes if possible */ void redo(); /** @return A pointer to editableStream */ EDITABLE_STREAM* editableStream(); protected: /** An editable stream */ EDITABLE_STREAM* m_editableStream; /** A number of undo levels */ int m_undoLevels; }; template EditableStreamHistory:: EditableStreamHistory(EDITABLE_STREAM* stream, const int undoLevels) { m_editableStream = stream; m_undoLevels = undoLevels; } template EditableStreamHistory::~EditableStreamHistory() { } template EDITABLE_STREAM EditableStreamHistory::cut(const int index, const int length) { EDITABLE_STREAM cut_stream = m_editableStream->cut(index, length); return cut_stream; } template void EditableStreamHistory::paste(const int index, EDITABLE_STREAM& pasteStream) { m_editableStream->paste(index, pasteStream); } template void EditableStreamHistory::replace(const int index, EDITABLE_STREAM& replaceStream) { m_editableStream->cut(index, replaceStream.length()); m_editableStream->paste(index, replaceStream); } template bool EditableStreamHistory::undoPossible() { return false; } template bool EditableStreamHistory::redoPossible() { return false; } template void EditableStreamHistory::undo() { } template void EditableStreamHistory::redo() { } template EDITABLE_STREAM* EditableStreamHistory::editableStream() { return m_editableStream; } #endif