Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -40,10 +40,11 @@ OFXMLElementBuilder.m \ OFXMLParser.m \ unicode.m INCLUDES := ${SRCS:.m=.h} \ + OFCollection.h \ ObjFW.h \ asprintf.h \ ${ATOMIC_H} \ macros.h \ objfw-defs.h \ Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -10,10 +10,11 @@ */ #include #import "OFObject.h" +#import "OFCollection.h" #import "OFEnumerator.h" @class OFDataArray; @class OFString; @@ -22,11 +23,12 @@ #endif /** * \brief A class for storing objects in an array. */ -@interface OFArray: OFObject +@interface OFArray: OFObject { OFDataArray *array; } /** @@ -112,15 +114,10 @@ * \return An initialized OFArray */ - initWithCArray: (id*)objs length: (size_t)len; -/** - * \return The number of objects in the array - */ -- (size_t)count; - /** * \return The objects of the array as a C array */ - (id*)cArray; @@ -180,15 +177,10 @@ * \param separator The string with which the objects should be joined * \return A string containing all objects joined by the separator */ - (OFString*)componentsJoinedByString: (OFString*)separator; -/** - * \return An OFEnumerator to enumarate through the array's objects - */ -- (OFEnumerator*)objectEnumerator; - #ifdef OF_HAVE_BLOCKS /** * Executes a block for each object. * * \param block The block to execute for each object ADDED src/OFCollection.h Index: src/OFCollection.h ================================================================== --- src/OFCollection.h +++ src/OFCollection.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008 - 2010 + * 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 included in + * the packaging of this file. + */ + +#import "OFEnumerator.h" + +/** + * \brief A protocol with methods common for all collections. + */ +@protocol OFCollection +#ifdef OF_HAVE_PROPERTIES +@property (readonly) size_t count; +#endif + +/** + * \return The number of objects in the collection + */ +- (size_t)count; + +/** + * \returns An OFEnumerator to enumerate through all objects of the collection + */ +- (OFEnumerator*)objectEnumerator; +@end Index: src/OFDictionary.h ================================================================== --- src/OFDictionary.h +++ src/OFDictionary.h @@ -10,10 +10,11 @@ */ #include #import "OFObject.h" +#import "OFCollection.h" #import "OFEnumerator.h" @class OFArray; #ifdef OF_HAVE_BLOCKS @@ -30,22 +31,18 @@ /// \endcond /** * \brief A class for storing objects in a hash table. */ -@interface OFDictionary: OFObject { struct of_dictionary_bucket **data; uint32_t size; size_t count; } -#ifdef OF_HAVE_PROPERTIES -@property (readonly) size_t count; -#endif - /** * Creates a new OFDictionary. * * \return A new autoreleased OFDictionary */ @@ -154,20 +151,10 @@ * \param key The key whose object should be returned * \return The object for the given key or nil if the key was not found */ - (id)objectForKey: (id)key; -/** - * \return The number of objects in the dictionary - */ -- (size_t)count; - -/** - * \returns An OFEnumerator to enumerate through the dictionary's objects - */ -- (OFEnumerator*)objectEnumerator; - /** * \return An OFEnumerator to enumerate through the dictionary's keys */ - (OFEnumerator*)keyEnumerator;