/* 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 __IndexSubindexSelection_H__ #define __IndexSubindexSelection_H__ typedef struct IndexSubindexSelection IndexSubindexSelection; #define IndexSubindexSelection_superclass StemObject #include "stemobject/StemObject.h" #include "utilities/ReverseIndexLookup.h" struct IndexSubindexSelection_pair { unsigned int index; unsigned int subindex; }; #define IndexSubindexSelection_ivars \ StemObject_ivars \ \ unsigned int pairCount; \ unsigned int private_ivar(pairAllocatedCount); \ struct IndexSubindexSelection_pair * pairs; \ ReverseIndexLookup * reverseLookup; \ unsigned int selectionDirtyValue; \ unsigned int reverseLookupDirtyValue; \ unsigned int lastReverseLookupDirtyValue; #define IndexSubindexSelection_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(IndexSubindexSelection) IndexSubindexSelection * IndexSubindexSelection_create(void); bool IndexSubindexSelection_init(IndexSubindexSelection * self); void IndexSubindexSelection_dispose(IndexSubindexSelection * self); IndexSubindexSelection * IndexSubindexSelection_copy(IndexSubindexSelection * self); void IndexSubindexSelection_copySelectionFrom(IndexSubindexSelection * self, IndexSubindexSelection * selection); // Returns true if a change was made bool IndexSubindexSelection_selectIndexPair(IndexSubindexSelection * self, unsigned int index, unsigned int subindex, bool assumeUnique); bool IndexSubindexSelection_deselectIndexPair(IndexSubindexSelection * self, unsigned int index, unsigned int subindex); bool IndexSubindexSelection_deselectAll(IndexSubindexSelection * self); // Returns the new selected state of the pair bool IndexSubindexSelection_toggleIndexPair(IndexSubindexSelection * self, unsigned int index, unsigned int subindex); // Operates indexes into indexes rather than the contents of indexes. Assumes selectionIndex is in range. void IndexSubindexSelection_deselectItemAtIndex(IndexSubindexSelection * self, unsigned int pairIndex); bool IndexSubindexSelection_isPairSelected(IndexSubindexSelection * self, unsigned int index, unsigned int subindex, unsigned int * outSelectionIndex); void IndexSubindexSelection_adjustIndexes(IndexSubindexSelection * self, unsigned int indexStart, int indexDelta); void IndexSubindexSelection_adjustSubindexes(IndexSubindexSelection * self, unsigned int index, unsigned int subindexStart, int subindexDelta); bool IndexSubindexSelection_truncateSelectionToMaxIndexCount(IndexSubindexSelection * 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 IndexSubindexSelection_removeDuplicates(IndexSubindexSelection * self); #endif