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.Value
property: 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::stack
for undo/redo history - Strings:
std::string
for 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.h
in your project. - Create a simple
main.cpp
and compile:g++ main.cpp -o run ./run