/* Copyright (c) 2023 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 __DocumentDirtyState_H__ #define __DocumentDirtyState_H__ typedef struct DocumentDirtyState DocumentDirtyState; #define DocumentDirtyState_superclass StemObject #include "stemobject/StemObject.h" typedef unsigned int DocumentDirtyStateBits; #define DocumentDirtyState_ivars \ StemObject_ivars \ \ unsigned int fieldCount; \ unsigned int * fields; \ unsigned int masterValue; #define DocumentDirtyState_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(DocumentDirtyState) DocumentDirtyState * DocumentDirtyState_create(unsigned int fieldCount); bool DocumentDirtyState_init(DocumentDirtyState * self, unsigned int fieldCount); void DocumentDirtyState_dispose(DocumentDirtyState * self); DocumentDirtyState * DocumentDirtyState_copy(DocumentDirtyState * self); // fieldCount must be equal for all functions that operate on two DocumentDirtyStates void DocumentDirtyState_copyStateFrom(DocumentDirtyState * to, DocumentDirtyState * from); // Returns false if any fields differ between self and compare, including masterValue bool DocumentDirtyState_isEqual(DocumentDirtyState * self, DocumentDirtyState * compare); // Returns a bitfield with a bit set for each index that differs between self and compare, not including masterValue DocumentDirtyStateBits DocumentDirtyState_getChangedBits(DocumentDirtyState * self, DocumentDirtyState * compare); // Sets all fields and masterValue to UINT_MAX void DocumentDirtyState_invalidate(DocumentDirtyState * self); // Increments each field with an index matching a set bit from fieldBits by 1, and also increments masterValue by 1 void DocumentDirtyState_advance(DocumentDirtyState * self, DocumentDirtyStateBits fieldBits); #endif