/* Copyright (c) 2021 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __UndoTree_H__ #define __UndoTree_H__ #ifdef __cplusplus extern "C" { #endif typedef struct UndoTree UndoTree; #define UndoTree_superclass StemObject #include "stemobject/StemObject.h" #include "utilities/UndoStateDelta.h" typedef struct UndoTree_node { unsigned int uniqueID; unsigned int parentID; unsigned int lastTraversedChildID; unsigned int depth; UndoStateDelta * stateDelta; } UndoTree_node; #define UndoTree_ivars \ StemObject_ivars \ \ void * target; \ unsigned int nodeCount; \ unsigned int nodeAllocatedCount; \ UndoTree_node * nodes; \ unsigned int currentNodeID; \ unsigned int nextNodeID; \ unsigned int lastTraversedRootNodeID; \ unsigned int currentDepth; #define UndoTree_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(UndoTree) // target is an arbitrary pointer that will be passed to UndoStateDelta's revert and apply functions UndoTree * UndoTree_create(void * target); bool UndoTree_init(UndoTree * self, void * target); void UndoTree_dispose(UndoTree * self); UndoTree * UndoTree_copy(UndoTree * self); // Takes ownership of stateDelta. If pruneSiblings is true, all existing redo history beyond the current position is erased. void UndoTree_appendNode(UndoTree * self, compat_type(UndoStateDelta *) stateDelta, bool pruneSiblings); bool UndoTree_canUndo(UndoTree * self); bool UndoTree_canRedo(UndoTree * self); unsigned int UndoTree_getRedoTimelineCountFromCurrentNode(UndoTree * self); UndoStateDelta * UndoTree_getStateDeltaForUndo(UndoTree * self); UndoStateDelta * UndoTree_getStateDeltaForRedo(UndoTree * self); UndoStateDelta * UndoTree_getStateDeltaForRedoWithTimeline(UndoTree * self, unsigned int timelineIndex); bool UndoTree_undo(UndoTree * self); bool UndoTree_redo(UndoTree * self); // Uses last traversed timeline bool UndoTree_redoWithTimeline(UndoTree * self, unsigned int timelineIndex); bool UndoTree_traverseToNode(UndoTree * self, unsigned int nodeID); void UndoTree_removeAllNodes(UndoTree * self); #ifdef __cplusplus } #endif #endif