/* Copyright (c) 2022 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 __IndexPairSelection_H__ #define __IndexPairSelection_H__ typedef struct IndexPairSelection IndexPairSelection; #define IndexPairSelection_superclass StemObject #include "stemobject/StemObject.h" #include "utilities/ReverseIndexLookup.h" struct IndexPairSelection_pair { unsigned int index0; unsigned int index1; }; #define IndexPairSelection_ivars \ StemObject_ivars \ \ unsigned int pairCount; \ unsigned int private_ivar(pairAllocatedCount); \ struct IndexPairSelection_pair * pairs; \ ReverseIndexLookup * reverseLookup; \ unsigned int selectionDirtyValue; \ unsigned int reverseLookupDirtyValue; \ unsigned int lastReverseLookupDirtyValue; #define IndexPairSelection_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(IndexPairSelection) IndexPairSelection * IndexPairSelection_create(void); bool IndexPairSelection_init(IndexPairSelection * self); void IndexPairSelection_dispose(IndexPairSelection * self); IndexPairSelection * IndexPairSelection_copy(IndexPairSelection * self); void IndexPairSelection_copySelectionFrom(IndexPairSelection * self, IndexPairSelection * selection); // Returns true if a change was made bool IndexPairSelection_selectIndexPair(IndexPairSelection * self, unsigned int index0, unsigned int index1, bool assumeUnique); bool IndexPairSelection_deselectIndexPair(IndexPairSelection * self, unsigned int index0, unsigned int index1); bool IndexPairSelection_deselectAllPairsWithIndex(IndexPairSelection * self, unsigned int index); bool IndexPairSelection_deselectAll(IndexPairSelection * self); // Returns the new selected state of the pair bool IndexPairSelection_toggleIndexPair(IndexPairSelection * self, unsigned int index0, unsigned int index1); // Operates indexes into pairs rather than the contents of pairs. Assumes selectionIndex is in range. void IndexPairSelection_deselectItemAtIndex(IndexPairSelection * self, unsigned int pairIndex); void IndexPairSelection_adjustIndexes(IndexPairSelection * self, unsigned int indexStart, int indexDelta); bool IndexPairSelection_isPairSelected(IndexPairSelection * self, unsigned int index0, unsigned int index1, unsigned int * outSelectionIndex); bool IndexPairSelection_isIndexSelected(IndexPairSelection * self, unsigned int index, unsigned int * outSelectionIndex); bool IndexPairSelection_truncateSelectionToMaxIndexCount(IndexPairSelection * self, unsigned int maxIndexCount); // Removes any duplicate entries in pairs, and returns the number of duplicates removed. This should only be // necessary if pairs was modified directly, or if selectIndexPair() was called with assumeUnique set to false without // checks to ensure uniqueness before inserting. unsigned int IndexPairSelection_removeDuplicates(IndexPairSelection * self); #endif