#include "sectionstore.h" #include "containers/sectionmap.h" #include "containers/sectionarray.h" #include struct SectionStore { SectionMap map; SectionArray array; }; SECTIONSTOREPTR SectionStoreNew(VOID) { struct SectionStore* result = AllocVec(sizeof(struct SectionStore), MEMF_CLEAR); result->map = SectionMapNew(); result->array = SectionArrayNew(); return result; } VOID SectionStoreFree(SECTIONSTOREPTR abstractSectionStore) { if( abstractSectionStore != NULL ) { struct SectionStore* store = (struct SectionStore*)abstractSectionStore; if( store->map != NULL ) SectionMapFree( store->map ); if( store->array != NULL ) SectionArrayFree( store->array ); FreeVec(store); } } VOID SectionStoreAddSection(SECTIONSTOREPTR abstractSectionStore, SECTIONPTR section) { struct SectionStore* store = (struct SectionStore*)abstractSectionStore; if( store != NULL && section != NULL ) { CONST_STRPTR canonicalName = SectionCanonicalName(section); if( canonicalName != NULL ) { // the array acts as storage as it can free its contents SectionArrayAppend(store->array, section); // the map will copy the string key and free it, but not the section SectionMapSet(store->map, canonicalName, section); //free the canonical name as the map has copied it. FreeVec((STRPTR)canonicalName); } } } SECTIONPTR SectionStoreGetSection(SECTIONSTOREPTR abstractSectionStore, CONST_STRPTR canonicalName) { struct SectionStore* store = (struct SectionStore*)abstractSectionStore; if( store != NULL && canonicalName != NULL ) { return SectionMapGet(store->map, canonicalName); } }