A C++ class for managing strings with built-in undo/redo functionality using stacks. π
The clsMyString class provides a powerful string management system with the ability to undo and redo changes. It uses two internal stacks to track modifications, allowing users to revert or reapply changes efficientlyβperfect for command-based interfaces, mini text editors, and learning projects.
- βοΈ Set and Get String Values
- βͺ Undo Last Change
- β© Redo Last Undone Change
This class makes it easy to maintain a history of string changes while offering a clean interface using property-style accessors in C++.
- SetValue(string): Updates the string and saves the old value for undo.
- GetValue(): Retrieves the current string value.
- Valueproperty: Provides clean access using- __declspec(property).
- Undo(): Restores the previous string state.
- Redo(): Reapplies the last undone change.
- When SetValue()is called, the current value is pushed onto the undo stack.
- Undo()pushes the current value to the redo stack and restores the top of the undo stack.
- Redo()pushes the current value to the undo stack and restores the top of the redo stack.
- Stack-based operations are fast and efficient.
- Only necessary values are stored, avoiding memory bloat.
- π History Limit: Add a configurable limit to undo/redo history.
- π Change Tracking: Store diffs instead of full strings.
- π Persistence: Save and load history from files.
- π Thread Safety: Add support for multithreaded environments.
- Language: C++
- Stacks: std::stackfor undo/redo history
- Strings: std::stringfor value storage
- Property Access: __declspec(property)for clean getter/setter usage
This project demonstrates:
β
 Stack-based undo/redo implementation
β
 Property-style encapsulation in C++
β
 Efficient and reversible state management
β
 Clean, modular class design
This project is open-source. Feel free to modify and enhance it! π
Pull requests and improvements are welcome. If you have ideas, feel free to fork the repo and submit a PR!
- Clone or download the repository.
- Include clsMyString.hin your project.
- Create a simple main.cppand compile:g++ main.cpp -o run ./run