Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -33,10 +33,12 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ 4B11005C14329B9A003A45D8 /* OFXMLNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B11005A14329B9A003A45D8 /* OFXMLNode.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B11005D14329B9A003A45D8 /* OFXMLNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B11005B14329B9A003A45D8 /* OFXMLNode.m */; }; + 4B141BA415FCDF74000C21A8 /* OFSortedList.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B141BA215FCDF74000C21A8 /* OFSortedList.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B141BA515FCDF74000C21A8 /* OFSortedList.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B141BA315FCDF74000C21A8 /* OFSortedList.m */; }; 4B17FF73133A2A76003E6DCD /* OFException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF71133A28FC003E6DCD /* OFException.m */; }; 4B17FF74133A2AAB003E6DCD /* OFException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF70133A28FC003E6DCD /* OFException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B17FF77133A2B18003E6DCD /* OFNotImplementedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B17FF78133A2B18003E6DCD /* OFNotImplementedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF76133A2B18003E6DCD /* OFNotImplementedException.m */; }; 4B17FF7B133A2C15003E6DCD /* OFOutOfRangeException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF79133A2C14003E6DCD /* OFOutOfRangeException.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -404,10 +406,12 @@ 4B0108CA10EB8C9300631877 /* OFEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFEnumerator.m; path = src/OFEnumerator.m; sourceTree = ""; }; 4B0D249411DFAA3D00ED6FFC /* OFXMLElementBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLElementBuilder.h; path = src/OFXMLElementBuilder.h; sourceTree = ""; }; 4B0D249511DFAA3D00ED6FFC /* OFXMLElementBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLElementBuilder.m; path = src/OFXMLElementBuilder.m; sourceTree = ""; }; 4B11005A14329B9A003A45D8 /* OFXMLNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLNode.h; path = src/OFXMLNode.h; sourceTree = ""; }; 4B11005B14329B9A003A45D8 /* OFXMLNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLNode.m; path = src/OFXMLNode.m; sourceTree = ""; }; + 4B141BA215FCDF74000C21A8 /* OFSortedList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSortedList.h; path = src/OFSortedList.h; sourceTree = ""; }; + 4B141BA315FCDF74000C21A8 /* OFSortedList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSortedList.m; path = src/OFSortedList.m; sourceTree = ""; }; 4B175C1D116D130B003C99CB /* OFApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFApplication.h; path = src/OFApplication.h; sourceTree = ""; }; 4B175C1E116D130B003C99CB /* OFApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFApplication.m; path = src/OFApplication.m; sourceTree = ""; }; 4B17FF70133A28FC003E6DCD /* OFException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFException.h; path = src/exceptions/OFException.h; sourceTree = ""; }; 4B17FF71133A28FC003E6DCD /* OFException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFException.m; path = src/exceptions/OFException.m; sourceTree = ""; }; 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFNotImplementedException.h; path = src/exceptions/OFNotImplementedException.h; sourceTree = ""; }; @@ -983,10 +987,12 @@ 4B39844113D3A24600E6F825 /* OFSet.m */, 4BA85BC8140ECCE800E91D51 /* OFSet_hashtable.h */, 4BA85BC9140ECCE800E91D51 /* OFSet_hashtable.m */, 4BF1BCC411C9663F0025511F /* OFSHA1Hash.h */, 4BF1BCC511C9663F0025511F /* OFSHA1Hash.m */, + 4B141BA215FCDF74000C21A8 /* OFSortedList.h */, + 4B141BA315FCDF74000C21A8 /* OFSortedList.m */, 4B67997D1099E7C50041064A /* OFStream.h */, 4B67997E1099E7C50041064A /* OFStream.m */, 4BAF5F47123460C900F4E111 /* OFStreamObserver.h */, 4BAF5F48123460C900F4E111 /* OFStreamObserver.m */, 4B83F0F2142FDEFD00E4A821 /* OFStreamObserver_kqueue.h */, @@ -1188,10 +1194,11 @@ 4BB524C1143D1E4E0085FBCC /* OFProcess.h in Headers */, 4B3D23D31337FCB000DD29B8 /* OFSeekableStream.h in Headers */, 4B989C2F13771A3700109A30 /* OFSerialization.h in Headers */, 4B39844213D3A24600E6F825 /* OFSet.h in Headers */, 4B3D23D41337FCB000DD29B8 /* OFSHA1Hash.h in Headers */, + 4B141BA415FCDF74000C21A8 /* OFSortedList.h in Headers */, 4B3D23D51337FCB000DD29B8 /* OFStream.h in Headers */, 4B3D23D61337FCB000DD29B8 /* OFStreamObserver.h in Headers */, 4B3D23D71337FCB000DD29B8 /* OFStreamSocket.h in Headers */, 4B3D23D81337FCB000DD29B8 /* OFString.h in Headers */, 4B3D23D91337FCB000DD29B8 /* OFString+Hashing.h in Headers */, @@ -1482,10 +1489,11 @@ 4BB524C2143D1E4E0085FBCC /* OFProcess.m in Sources */, 4B3D23A11337FC0D00DD29B8 /* OFSeekableStream.m in Sources */, 4B39844313D3A24600E6F825 /* OFSet.m in Sources */, 4BA85BCF140ECCE800E91D51 /* OFSet_hashtable.m in Sources */, 4B3D23A21337FC0D00DD29B8 /* OFSHA1Hash.m in Sources */, + 4B141BA515FCDF74000C21A8 /* OFSortedList.m in Sources */, 4B3D23A31337FC0D00DD29B8 /* OFStream.m in Sources */, 4B3D23A41337FC0D00DD29B8 /* OFStreamObserver.m in Sources */, 4B83F0F5142FDEFD00E4A821 /* OFStreamObserver_kqueue.m in Sources */, 4B64D6F01425381E007BDFB1 /* OFStreamObserver_poll.m in Sources */, 4B64D6F21425381E007BDFB1 /* OFStreamObserver_select.m in Sources */, Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -36,10 +36,11 @@ ${OFPLUGIN_M} \ OFProcess.m \ OFSeekableStream.m \ OFSet.m \ OFSHA1Hash.m \ + OFSortedList.m \ OFStream.m \ OFStreamObserver.m \ OFStreamSocket.m \ OFString.m \ OFString+Hashing.m \ Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -94,12 +94,12 @@ /** * \brief Inserts an object before another list object. * * \param object The object to insert - * \param listObject The of_list_object_t of the object before which it should be - * inserted + * \param listObject The of_list_object_t of the object before which it should + * be inserted * \return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ - (of_list_object_t*)insertObject: (id)object ADDED src/OFSortedList.h Index: src/OFSortedList.h ================================================================== --- src/OFSortedList.h +++ src/OFSortedList.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFList.h" + +/** + * \brief A class which provides easy to use sorted double-linked lists. + * + * \warning Because the list is sorted, all methods inserting an object at a + * specific place are unavailable, even though they exist in OFList! + */ +@interface OFSortedList: OFList +/** + * \brief Adds the object to the list while keeping the list sorted. + * + * \param object The object to add + * \return The list object for the object just added + */ +- (of_list_object_t*)addObject: (id )object; +@end ADDED src/OFSortedList.m Index: src/OFSortedList.m ================================================================== --- src/OFSortedList.m +++ src/OFSortedList.m @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFSortedList.h" + +#import "OFNotImplementedException.h" + +@implementation OFSortedList +- (of_list_object_t*)appendObject: (id)object +{ + @throw [OFNotImplementedException exceptionWithClass: [self class] + selector: _cmd]; +} + +- (of_list_object_t*)prependObject: (id)object +{ + @throw [OFNotImplementedException exceptionWithClass: [self class] + selector: _cmd]; +} + +- (of_list_object_t*)insertObject: (id)object + beforeListObject: (of_list_object_t*)listObject +{ + @throw [OFNotImplementedException exceptionWithClass: [self class] + selector: _cmd]; +} + +- (of_list_object_t*)insertObject: (id)object + afterListObject: (of_list_object_t*)listObject +{ + @throw [OFNotImplementedException exceptionWithClass: [self class] + selector: _cmd]; +} + +- (of_list_object_t*)addObject: (id )object +{ + of_list_object_t *iter; + + for (iter = lastListObject; iter != NULL; iter = iter->previous) { + if ([object compare: iter->object] == OF_ORDERED_DESCENDING) + return [super insertObject: object + afterListObject: iter]; + } + + return [super prependObject: object]; +} +@end Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -24,10 +24,11 @@ #import "OFDataArray.h" #import "OFArray.h" #import "OFList.h" +#import "OFSortedList.h" #import "OFDictionary.h" #import "OFSet.h" #import "OFCountedSet.h"