@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2022 Jonathan Schleifer + * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -13,28 +13,27 @@ * file. */ #include "config.h" -#import "OFCountedMapTableSet.h" +#import "OFConcreteCountedSet.h" #import "OFArray.h" +#import "OFConcreteMutableSet.h" #import "OFMapTable.h" -#import "OFMutableMapTableSet.h" #import "OFString.h" #import "OFXMLAttribute.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFEnumerationMutationException.h" #import "OFOutOfRangeException.h" -@implementation OFCountedMapTableSet +@implementation OFConcreteCountedSet + (void)initialize { - if (self == [OFCountedMapTableSet class]) - [self inheritMethodsFromClass: [OFMutableMapTableSet class]]; + if (self == [OFConcreteCountedSet class]) + [self inheritMethodsFromClass: [OFConcreteMutableSet class]]; } - (instancetype)initWithSet: (OFSet *)set { self = [self init]; @@ -112,56 +111,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [self init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: @"OFCountedSet"] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - for (OFXMLElement *objectElement in - [element elementsForName: @"object" - namespace: OFSerializationNS]) { - void *pool2 = objc_autoreleasePoolPush(); - OFXMLElement *object; - OFXMLAttribute *countAttribute; - unsigned long long count; - - object = [objectElement elementsForNamespace: - OFSerializationNS].firstObject; - countAttribute = - [objectElement attributeForName: @"count"]; - - if (object == nil || countAttribute == nil) - @throw [OFInvalidFormatException exception]; - - count = countAttribute.unsignedLongLongValue; - if (count > SIZE_MAX || count > UINTPTR_MAX) - @throw [OFOutOfRangeException exception]; - - [_mapTable setObject: (void *)(uintptr_t)count - forKey: object.objectByDeserializing]; - - objc_autoreleasePoolPop(pool2); - } - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (size_t)countForObject: (id)object {