Index: ChangeLog ================================================================== --- ChangeLog +++ ChangeLog @@ -1,5 +1,38 @@ +Legend: + * Changes of existing features or bugfixes. + + New features. + +ObjFW 0.1.2 -> 0.2, 01.02.2010 + + Support for ObjC 2 Fast Enumerations on every platform which has + compiler support for fast enumerations. + + Support for ObjC 2 properties on every platform with compiler support. + + Fast Enumeration through arrays and dictionaries. + * OFIterator has been removed. + + OFEnumerator was added to replace OFIterator, which is more general + and works with arrays and dictionaries. + + Portable implementation for atomic operations. + + Portable implementation for spinlocks. They use atomic operations if + available, if not they fall back to pthread spinlocks. If both are + unavailable, mutexes are used as a last fallback. + * -[retain] and -[release] are now atomic. If no atomic operations are + available, spinlocks are used (which can fall back to mutexes, see + above). + * -[readLine] now handles \r\n without having the \r included in the + returned line. + + OFThread now has -[tryLock]. + * Mutation methods have been removed from immutable interfaces, thus + already giving an error at compilation instead of at runtime. + * Dependencies between headers have been reduced, leading to faster + compile times. + * The interfaces of OFSocket and OFStream were cleaned up and some + methods were moved to OFTCPSocket, as they make sense only there. + * File methods unavailable on Windows don't throw an exception at + runtime anymore, but instead are not even in the interface on + Windows. This way, it is a compile time error instead of a runtime + error. + ObjFW 0.1.1 -> 0.1.2, 15.01.2010 * Fix a bug in OFMutableArray's -[removeObject:] and -[removeObjectIdenticalTo:] that could lead to not removing all occurrences of the object from the array and to out of bounds reads. * Change the URL in the framework plist to the homepage. Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -30,5 +30,23 @@ else \ ${DELETE_FAILED}; \ fi \ fi \ done + +tarball: + V=$$(fgrep VERSION= objfw-config.in | sed 's/VERSION="\(.*\)"/\1/'); \ + V2=$$(fgrep AC_INIT configure.ac | \ + sed 's/AC_INIT([^,]*,\([^,]*\),.*/\1/' | sed 's/ //'); \ + if test x"$$V" != x"$$V2"; then \ + echo "objfw-config.h.in and configure.ac version mismatch!"; \ + exit 1; \ + fi; \ + echo "Generating tarball for version $$V..."; \ + rm -f objfw-$$V.tar.gz; \ + rm -fr objfw-$$V; \ + hg archive objfw-$$V; \ + cp configure config.h.in objfw-$$V; \ + cd objfw-$$V && rm -f .hg_archival.txt .hgignore .hgtags && cd ..; \ + tar cf objfw-$$V.tar objfw-$$V; \ + gzip -9 objfw-$$V.tar; \ + rm -fr objfw-$$V Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1,6 +1,6 @@ -AC_INIT(ObjFW, 0.1, js@webkeks.org) +AC_INIT(ObjFW, 0.2, js@webkeks.org) AC_CONFIG_SRCDIR(src) AC_CANONICAL_HOST AC_LANG([Objective C]) Index: generators/TableGenerator.h ================================================================== --- generators/TableGenerator.h +++ generators/TableGenerator.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: generators/TableGenerator.m ================================================================== --- generators/TableGenerator.m +++ generators/TableGenerator.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: generators/copyright.h ================================================================== --- generators/copyright.h +++ generators/copyright.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -11,11 +11,11 @@ #import "OFString.h" #define COPYRIGHT \ @"/*\n" \ - @" * Copyright (c) 2008 - 2009\n" \ + @" * Copyright (c) 2008 - 2010\n" \ @" * Jonathan Schleifer \n" \ @" *\n" \ @" * All rights reserved.\n" \ @" *\n" \ @" * This file is part of ObjFW. It may be distributed under the terms " \ Index: generators/main.m ================================================================== --- generators/main.m +++ generators/main.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: objfw-config.in ================================================================== --- objfw-config.in +++ objfw-config.in @@ -8,11 +8,11 @@ OBJCFLAGS="-fexceptions -fobjc-exceptions -fconstant-string-class=OFConstString" OBJCFLAGS="$OBJCFLAGS @NO_CONST_CFSTRINGS@ @NO_WARN_UNUSED@ @ATOMIC_OBJCFLAGS@" LDFLAGS="" LDFLAGS_RPATH="@LDFLAGS_RPATH@" LIBS="-L${libdir} -lobjfw @LIBS@" -VERSION="0.1" +VERSION="0.2" show_help() { echo "$0: Available arguments are:" echo echo " --all Outputs all flags + libs" Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -29,11 +29,10 @@ OFXMLElement.m \ OFXMLParser.m \ unicode.m INCLUDES := ${SRCS:.m=.h} \ - OFFastEnumeration.h \ OFMacros.h \ ObjFW.h \ asprintf.h \ ${ATOMIC_H} \ objfw-defs.h \ Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -11,17 +11,16 @@ #include #import "OFObject.h" #import "OFEnumerator.h" -#import "OFFastEnumeration.h" @class OFDataArray; @class OFString; /** - * The OFArray class is a class for storing objects in an array. + * \brief A class for storing objects in an array. */ @interface OFArray: OFObject { OFDataArray *array; } @@ -48,11 +47,11 @@ + arrayWithObjects: (OFObject*)first, ...; /** * Creates a new OFArray with the objects from the specified C array. * - * \param objs A C array of objects. + * \param objs A C array of objects, terminated with nil * \return A new autoreleased OFArray */ + arrayWithCArray: (OFObject**)objs; /** @@ -82,11 +81,11 @@ argList: (va_list)args; /** * Initializes an OFArray with the objects from the specified C array. * - * \param objs A C array of objects + * \param objs A C array of objects, terminated with nil * \return An initialized OFArray */ - initWithCArray: (OFObject**)objs; /** @@ -148,10 +147,11 @@ * \return An OFEnumerator to enumarate through the array's objects */ - (OFEnumerator*)enumerator; @end +/// \cond internal @interface OFArrayEnumerator: OFEnumerator { OFDataArray *array; size_t count; unsigned long mutations; @@ -160,7 +160,8 @@ } - initWithDataArray: (OFDataArray*)data mutationsPointer: (unsigned long*)mutations_ptr; @end +/// \endcond #import "OFMutableArray.h" Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -225,10 +225,12 @@ size_t i, count = [array count]; IMP append; if (count == 0) return @""; + if (count == 1) + return [objs[0] retain]; str = [OFMutableString string]; append = [str methodForSelector: @selector(appendString:)]; for (i = 0; i < count - 1; i++) { @@ -321,10 +323,11 @@ [super dealloc]; } @end +/// \cond internal @implementation OFArrayEnumerator - initWithDataArray: (OFDataArray*)array_ mutationsPointer: (unsigned long*)mutations_ptr_; { self = [super init]; @@ -356,5 +359,6 @@ pos = 0; return self; } @end +/// \endcond Index: src/OFAutoreleasePool.h ================================================================== --- src/OFAutoreleasePool.h +++ src/OFAutoreleasePool.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -12,10 +12,12 @@ #import "OFObject.h" @class OFMutableArray; /** + * \brief A pool that keeps track of objects to release. + * * The OFAutoreleasePool class is a class that keeps track of objects that will * be released when the autorelease pool is released. * * Every thread has its own stack of autorelease pools. */ Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFConstString.h ================================================================== --- src/OFConstString.h +++ src/OFConstString.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -14,9 +14,9 @@ #ifdef OF_APPLE_RUNTIME extern void *_OFConstStringClassReference; #endif /** - * A class for storing constant strings using the @"" literal. + * \brief A class for storing constant strings using the \@"" literal. */ @interface OFConstString: OFString {} @end Index: src/OFConstString.m ================================================================== --- src/OFConstString.m +++ src/OFConstString.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFDataArray.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -10,11 +10,11 @@ */ #import "OFObject.h" /** - * The OFDataArray class is a class for storing arbitrary data in an array. + * \brief A class for storing arbitrary data in an array. * * If you plan to store large hunks of data, you should consider using * OFBigDataArray, which allocates the memory in pages rather than in bytes. */ @interface OFDataArray: OFObject @@ -141,14 +141,16 @@ - removeNItems: (size_t)nitems atIndex: (size_t)index; @end /** + * \brief A class for storing arbitrary big data in an array. + * * The OFBigDataArray class is a class for storing arbitrary data in an array * and is designed to store large hunks of data. Therefore, it allocates * memory in pages rather than a chunk of memory for each item. */ @interface OFBigDataArray: OFDataArray { size_t size; } @end Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFDictionary.h ================================================================== --- src/OFDictionary.h +++ src/OFDictionary.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -11,23 +11,24 @@ #include #import "OFObject.h" #import "OFEnumerator.h" -#import "OFFastEnumeration.h" @class OFArray; +/// \cond internal struct of_dictionary_bucket { OFObject *key; OFObject *object; uint32_t hash; }; +/// \endcond /** - * The OFDictionary class is a class for using hash tables. + * \brief A class for storing objects in a hash table. */ @interface OFDictionary: OFObject { struct of_dictionary_bucket *data; @@ -156,10 +157,11 @@ * \return An OFEnumerator to enumerate through the dictionary's keys */ - (OFEnumerator*)keyEnumerator; @end +/// \cond internal @interface OFDictionaryEnumerator: OFEnumerator { struct of_dictionary_bucket *data; size_t size; unsigned long mutations; @@ -175,7 +177,8 @@ @interface OFDictionaryObjectEnumerator: OFDictionaryEnumerator @end @interface OFDictionaryKeyEnumerator: OFDictionaryEnumerator @end +/// \endcond #import "OFMutableDictionary.h" Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -583,10 +583,11 @@ return hash; } @end +/// \cond internal @implementation OFDictionaryEnumerator - initWithData: (struct of_dictionary_bucket*)data_ size: (size_t)size_ mutationsPointer: (unsigned long*)mutations_ptr_ { @@ -638,5 +639,6 @@ return data[pos++].key; else return nil; } @end +/// \endcond Index: src/OFEnumerator.h ================================================================== --- src/OFEnumerator.h +++ src/OFEnumerator.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -10,11 +10,11 @@ */ #import "OFObject.h" /** - * The OFEnumerator class provides methods to enumerate through collections. + * \brief A class which provides methods to enumerate through collections. */ @interface OFEnumerator: OFObject {} /** * \return The next object */ @@ -24,5 +24,40 @@ * Resets the enumerator, so the next call to nextObject returns the first * object again. */ - reset; @end + +/* + * This needs to be exactly like this because it's hardcoded in the compiler. + * + * We need this bad check to see if we already imported Cocoa, which defines + * this as well. + */ +#define of_fast_enumeration_state_t NSFastEnumerationState +#ifndef NSINTEGER_DEFINED +/** + * \brief State information for fast enumerations. + */ +typedef struct __of_fast_enumeration_state { + /// Arbitrary state information for the enumeration + unsigned long state; + /// Pointer to a C array of objects to return + id *itemsPtr; + /// Arbitrary state information to detect mutations + unsigned long *mutationsPtr; + /// Additional arbitrary state information + unsigned long extra[5]; +} of_fast_enumeration_state_t; +#endif + +/** + * \brief A protocol for fast enumeration. + * + * The OFFastEnumeration protocol needs to be implemented by all classes + * supporting fast enumeration. + */ +@protocol OFFastEnumeration +- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state + objects: (id*)objects + count: (int)count; +@end Index: src/OFEnumerator.m ================================================================== --- src/OFEnumerator.m +++ src/OFEnumerator.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -14,11 +14,11 @@ #import "OFObject.h" @class OFString; /** - * An exception indicating an object could not be allocated. + * \brief An exception indicating an object could not be allocated. * * This exception is preallocated, as if there's no memory, no exception can * be allocated of course. That's why you shouldn't and even can't deallocate * it. * @@ -39,11 +39,14 @@ */ - (OFString*)string; @end /** - * The OFException class is the base class for all exceptions in ObjFW. + * \brief The base class for all exceptions in ObjFW + * + * The OFException class is the base class for all exceptions in ObjFW, except + * the OFAllocFailedException. * * IMPORTANT: Exceptions do NOT use OFAutoreleasePools and can't be autoreleased * either! You have to make sure to dealloc the exception in your \@catch block! */ @interface OFException: OFObject @@ -78,11 +81,11 @@ */ - (OFString*)string; @end /** - * An OFException indicating there is not enough memory available. + * \brief An exception indicating there is not enough memory available. */ @interface OFOutOfMemoryException: OFException { size_t req_size; } @@ -110,17 +113,18 @@ */ - (size_t)requestedSize; @end /** - * An OFException indicating that a mutation was detected while enumerating. + * \brief An exception indicating that a mutation was detected while + * enumerating. */ @interface OFEnumerationMutationException: OFException {} @end /** - * An OFException indicating the given memory is not part of the object. + * \brief An exception indicating the given memory is not part of the object. */ @interface OFMemoryNotPartOfObjectException: OFException { void *pointer; } @@ -148,11 +152,12 @@ */ - (void*)pointer; @end /** - * An OFException indicating that a method or part of it is not implemented. + * \brief An exception indicating that a method or part of it is not + * implemented. */ @interface OFNotImplementedException: OFException { SEL selector; } @@ -175,17 +180,17 @@ - initWithClass: (Class)class_ selector: (SEL)selector; @end /** - * An OFException indicating the given value is out of range. + * \brief An exception indicating the given value is out of range. */ @interface OFOutOfRangeException: OFException {} @end /** - * An OFException indicating that the argument is invalid for this method. + * \brief An exception indicating that the argument is invalid for this method. */ @interface OFInvalidArgumentException: OFException { SEL selector; } @@ -208,35 +213,36 @@ - initWithClass: (Class)class_ selector: (SEL)selector; @end /** - * An OFException indicating that the encoding is invalid for this object. + * \brief An exception indicating that the encoding is invalid for this object. */ @interface OFInvalidEncodingException: OFException {} @end /** - * An OFException indicating that the format is invalid. + * \brief An exception indicating that the format is invalid. */ @interface OFInvalidFormatException: OFException {} @end /** - * An OFException indicating that a parser encountered malformed or invalid XML. + * \brief An exception indicating that a parser encountered malformed or + * invalid XML. */ @interface OFMalformedXMLException: OFException {} @end /** - * An OFException indicating that initializing something failed. + * \brief An exception indicating that initializing something failed. */ @interface OFInitializationFailedException: OFException {} @end /** - * An OFException indicating the file couldn't be opened. + * \brief An exception indicating the file couldn't be opened. */ @interface OFOpenFileFailedException: OFException { OFString *path; OFString *mode; @@ -280,11 +286,11 @@ */ - (OFString*)mode; @end /** - * An OFException indicating a read or write to the file failed. + * \brief An exception indicating a read or write to the file failed. */ @interface OFReadOrWriteFailedException: OFException { size_t req_size; int err; @@ -318,23 +324,23 @@ */ - (size_t)requestedSize; @end /** - * An OFException indicating a read on the file failed. + * \brief An exception indicating a read on a file failed. */ @interface OFReadFailedException: OFReadOrWriteFailedException {} @end /** - * An OFException indicating a write to the file failed. + * \brief An exception indicating a write to a file failed. */ @interface OFWriteFailedException: OFReadOrWriteFailedException {} @end /** - * An OFException indicating that changing the mode of the file failed. + * \brief An exception indicating that changing the mode of a file failed. */ @interface OFChangeFileModeFailedException: OFException { OFString *path; mode_t mode; @@ -379,11 +385,11 @@ - (mode_t)mode; @end #ifndef _WIN32 /** - * An OFException indicating that changing the owner of the file failed. + * \brief An exception indicating that changing the owner of a file failed. */ @interface OFChangeFileOwnerFailedException: OFException { OFString *path; uid_t owner; @@ -438,11 +444,11 @@ - (gid_t)group; @end #endif /** - * An OFException indicating that renaming a file failed. + * \brief An exception indicating that renaming a file failed. */ @interface OFRenameFileFailedException: OFException { OFString *from; OFString *to; @@ -486,11 +492,11 @@ */ - (OFString*)to; @end /** - * An OFException indicating that deleting a file failed. + * \brief An exception indicating that deleting a file failed. */ @interface OFDeleteFileFailedException: OFException { OFString *path; int err; @@ -525,11 +531,11 @@ - (OFString*)path; @end #ifndef _WIN32 /** - * An OFException indicating that creating a link failed. + * \brief An exception indicating that creating a link failed. */ @interface OFLinkFailedException: OFException { OFString *src; OFString *dest; @@ -573,11 +579,11 @@ */ - (OFString*)destination; @end /** - * An OFException indicating that creating a symlink failed. + * \brief An exception indicating that creating a symlink failed. */ @interface OFSymlinkFailedException: OFException { OFString *src; OFString *dest; @@ -622,30 +628,30 @@ - (OFString*)destination; @end #endif /** - * An OFException indicating that setting an option failed. + * \brief An exception indicating that setting an option failed. */ @interface OFSetOptionFailedException: OFException {} @end /** - * An OFException indicating a socket is not connected or bound. + * \brief An exception indicating a socket is not connected or bound. */ @interface OFNotConnectedException: OFException {} @end /** - * An OFException indicating an attempt to connect or bind an already connected - * or bound socket. + * \brief An exception indicating an attempt to connect or bind an already + * connected or bound socket. */ @interface OFAlreadyConnectedException: OFException {} @end /** - * An OFException indicating the translation of an address failed. + * \brief An exception indicating the translation of an address failed. */ @interface OFAddressTranslationFailedException: OFException { OFString *node; OFString *service; @@ -689,11 +695,11 @@ */ - (OFString*)service; @end /** - * An OFException indicating that the connection could not be established. + * \brief An exception indicating that the connection could not be established. */ @interface OFConnectionFailedException: OFException { OFString *node; OFString *service; @@ -737,11 +743,11 @@ */ - (OFString*)service; @end /** - * An OFException indicating that binding the socket failed. + * \brief An exception indicating that binding the socket failed. */ @interface OFBindFailedException: OFException { OFString *node; OFString *service; @@ -795,11 +801,11 @@ */ - (int)family; @end /** - * An OFException indicating that listening on the socket failed. + * \brief An exception indicating that listening on the socket failed. */ @interface OFListenFailedException: OFException { int backlog; int err; @@ -833,11 +839,11 @@ */ - (int)backLog; @end /** - * An OFException indicating that accepting a connection failed. + * \brief An exception indicating that accepting a connection failed. */ @interface OFAcceptFailedException: OFException { int err; } @@ -847,27 +853,27 @@ */ - (int)errNo; @end /** - * An OFException indicating that joining the thread failed. + * \brief An exception indicating that joining the thread failed. */ @interface OFThreadJoinFailedException: OFException {} @end /** - * An OFException indicating that locking a mutex failed. + * \brief An exception indicating that locking a mutex failed. */ @interface OFMutexLockFailedException: OFException {} @end /** - * An OFException indicating that unlocking a mutex failed. + * \brief An exception indicating that unlocking a mutex failed. */ @interface OFMutexUnlockFailedException: OFException {} @end /** - * An OFException indicating that the hash has already been calculated. + * \brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException {} @end Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the DELETED src/OFFastEnumeration.h Index: src/OFFastEnumeration.h ================================================================== --- src/OFFastEnumeration.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2008 - 2009 - * 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 "OFObject.h" - -/* - * This needs to be exactly like this because it's hardcoded in the compiler. - * - * We need this bad check to see if we already imported Cocoa, which defines - * this as well. - */ -#define of_fast_enumeration_state_t NSFastEnumerationState -#ifndef NSINTEGER_DEFINED -typedef struct __of_fast_enumeration_state { - unsigned long state; - id *itemsPtr; - unsigned long *mutationsPtr; - unsigned long extra[5]; -} of_fast_enumeration_state_t; -#endif - -/** - * The OFFastEnumeration protocol needs to be implemented by all classes - * supporting fast enumeration. - */ -@protocol OFFastEnumeration -- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state - objects: (id*)objects - count: (int)count; -@end Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -16,11 +16,11 @@ #import "OFStream.h" @class OFString; /** - * The OFFile class provides functions to read, write and manipulate files. + * \brief A class which provides functions to read, write and manipulate files. */ @interface OFFile: OFStream { FILE *fp; BOOL close; @@ -126,14 +126,11 @@ * It is not closed when the OFFile object is deallocated! */ - initWithFilePointer: (FILE*)fp; @end -@interface OFFileSingleton: OFFile -@end - /// An OFFile object for stdin extern OFFile *of_stdin; /// An OFFile object for stdout extern OFFile *of_stdout; /// An OFFile object for stderr extern OFFile *of_stderr; Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -27,10 +27,15 @@ #endif OFFile *of_stdin = nil; OFFile *of_stdout = nil; OFFile *of_stderr = nil; + +/// \cond internal +@interface OFFileSingleton: OFFile +@end +/// \endcond @implementation OFFile + (void)load { if (self != [OFFile class]) @@ -222,10 +227,11 @@ return self; } @end +/// \cond internal @implementation OFFileSingleton - initWithPath: (OFString*)path mode: (OFString*)mode { @throw [OFNotImplementedException newWithClass: isa @@ -256,5 +262,6 @@ @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; [super dealloc]; /* Get rid of stupid warning */ } @end +/// \endcond Index: src/OFHashes.h ================================================================== --- src/OFHashes.h +++ src/OFHashes.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -16,11 +16,11 @@ #define OF_SHA1_DIGEST_SIZE 20 extern int _OFHashing_reference; /** - * The OFMD5Hash class provides functions to create an MD5 hash. + * \brief A class which provides functions to create an MD5 hash. */ @interface OFMD5Hash: OFObject { uint32_t buf[4]; uint32_t bits[2]; @@ -49,11 +49,11 @@ */ - (uint8_t*)digest; @end /** - * The OFSHA1Hash class provides functions to create an SHA1 hash. + * \brief A class which provides functions to create an SHA1 hash. */ @interface OFSHA1Hash: OFObject { uint32_t state[5]; uint64_t count; Index: src/OFHashes.m ================================================================== --- src/OFHashes.m +++ src/OFHashes.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -279,14 +279,16 @@ w = OF_ROL(w, 30); #define R4(v, w, x, y, z, i) \ z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + OF_ROL(v, 5); \ w = OF_ROL(w, 30); +/// \cond internal typedef union { char c[64]; uint32_t l[16]; } sha1_c64l16_t; +/// \endcond static inline void sha1_transform(uint32_t state[5], const char buffer[64]) { uint32_t a, b, c, d, e; Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -10,25 +10,26 @@ */ #import "OFObject.h" /** + * \brief A list object. + * * A struct that contains a pointer to the next list object, the previous list * object and the object. */ -typedef struct __of_list_object -{ +typedef struct __of_list_object { /// A pointer to the next list object in the list struct __of_list_object *next; /// A pointer to the previous list object in the list struct __of_list_object *prev; /// The object for the list object id object; } of_list_object_t; /** - * The OFList class provides easy to use double-linked lists. + * \brief A class which provides easy to use double-linked lists. */ @interface OFList: OFObject { of_list_object_t *first; of_list_object_t *last; Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFMacros.h ================================================================== --- src/OFMacros.h +++ src/OFMacros.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -10,12 +10,11 @@ */ #import "OFArray.h" /** - * The OFMutableArray class is a class for storing, adding and removing objects - * in an array. + * \brief A class for storing, adding and removing objects in an array. */ @interface OFMutableArray: OFArray { unsigned long mutations; } Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFMutableDictionary.h ================================================================== --- src/OFMutableDictionary.h +++ src/OFMutableDictionary.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -10,11 +10,11 @@ */ #import "OFDictionary.h" /** - * The OFMutableDictionary class is a class for using mutable hash tables. + * \brief A class for using mutable hash tables. */ @interface OFMutableDictionary: OFDictionary { unsigned long mutations; } Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFMutableString.h ================================================================== --- src/OFMutableString.h +++ src/OFMutableString.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -13,11 +13,11 @@ #include #import "OFString.h" /** - * A class for storing and modifying strings. + * \brief A class for storing and modifying strings. */ @interface OFMutableString: OFString {} /** * Sets the OFString to the specified UTF-8 encoded C string. * Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -43,14 +43,15 @@ if (!is_utf8) { assert(table_size >= 1); uint8_t *p = (uint8_t*)*string + *length; + uint8_t t; while (--p >= (uint8_t*)*string) - if (table[0][*p]) - *p = table[0][*p]; + if ((t = table[0][*p]) != 0) + *p = t; return; } ulen = [self length]; Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -39,12 +39,11 @@ OF_NUMBER_FLOAT, OF_NUMBER_DOUBLE, }; /** - * The OFNumber class provides a way to store a number in an object and to - * manipulate it. + * \brief provides a way to store a number in an object and to manipulate it. */ @interface OFNumber: OFObject { union { char char_; @@ -536,42 +535,38 @@ * \return The OFNumber as a double */ - (double)asDouble; /** - * Adds the specified OFNumber to the OFNumber. - * * \param num The OFNumber to add + * \return The OFNumber added with the specified OFNumber */ - add: (OFNumber*)num; /** - * Subtracts the specified OFNumber from the OFNumber. - * * \param num The OFNumber to substract + * \return The OFNumber subtracted by the specified OFNumber */ - subtract: (OFNumber*)num; /** - * Multiplies the OFNumber with the specified OFNumber. - * * \param num The OFNumber to multiply with + * \return The OFNumber multiplied with the specified OFNumber */ - multiplyWith: (OFNumber*)num; /** - * Divides the OFNumber by the specified OFNumber. - * * \param num The OFNumber to divide by + * \return The OFNumber devided by the specified OFNumber */ - divideBy: (OFNumber*)num; /** - * Increases the OFNumber by 1. + * \return The OFNumber increased by one. */ - increase; /** - * Decreases the OFNumber by 1. + * \return The OFNumber decreased by one. */ - decrease; @end Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -11,10 +11,11 @@ #include "config.h" #import "OFNumber.h" #import "OFExceptions.h" +#import "OFMacros.h" #define RETURN_AS(t) \ switch (type) { \ case OF_NUMBER_CHAR: \ return (t)value.char_; \ @@ -65,161 +66,137 @@ case OF_NUMBER_DOUBLE: \ return (t)value.double_; \ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } -#define CALCULATE(o) \ - switch (type) { \ +#define CALCULATE(o, n) \ + switch (type) { \ case OF_NUMBER_CHAR: \ - value.char_ o; \ - break; \ + return [OFNumber numberWithChar: \ + value.char_ o [n asChar]]; \ case OF_NUMBER_SHORT: \ - value.short_ o; \ - break; \ + return [OFNumber numberWithShort: \ + value.short_ o [n asShort]]; \ case OF_NUMBER_INT: \ - value.int_ o; \ - break; \ + return [OFNumber numberWithInt: \ + value.int_ o [n asInt]]; \ case OF_NUMBER_LONG: \ - value.long_ o; \ - break; \ + return [OFNumber numberWithLong: \ + value.long_ o [n asLong]]; \ case OF_NUMBER_UCHAR: \ - value.uchar o; \ - break; \ + return [OFNumber numberWithUChar: \ + value.uchar o [n asUChar]]; \ case OF_NUMBER_USHORT: \ - value.ushort o; \ - break; \ + return [OFNumber numberWithUShort: \ + value.ushort o [n asUShort]]; \ case OF_NUMBER_UINT: \ - value.uint o; \ - break; \ + return [OFNumber numberWithUInt: \ + value.uint o [n asUInt]]; \ case OF_NUMBER_ULONG: \ - value.ulong o; \ - break; \ + return [OFNumber numberWithULong: \ + value.ulong o [n asULong]]; \ case OF_NUMBER_INT8: \ - value.int8 o; \ - break; \ + return [OFNumber numberWithInt8: \ + value.int8 o [n asInt8]]; \ case OF_NUMBER_INT16: \ - value.int16 o; \ - break; \ + return [OFNumber numberWithInt16: \ + value.int16 o [n asInt16]]; \ case OF_NUMBER_INT32: \ - value.int32 o; \ - break; \ + return [OFNumber numberWithInt32: \ + value.int32 o [n asInt32]]; \ case OF_NUMBER_INT64: \ - value.int64 o; \ - break; \ + return [OFNumber numberWithInt64: \ + value.int64 o [n asInt64]]; \ case OF_NUMBER_UINT8: \ - value.uint8 o; \ - break; \ + return [OFNumber numberWithUInt8: \ + value.uint8 o [n asUInt8]]; \ case OF_NUMBER_UINT16: \ - value.uint16 o; \ - break; \ + return [OFNumber numberWithUInt16: \ + value.uint16 o [n asUInt16]]; \ case OF_NUMBER_UINT32: \ - value.uint32 o; \ - break; \ + return [OFNumber numberWithUInt32: \ + value.uint32 o [n asUInt32]]; \ case OF_NUMBER_UINT64: \ - value.uint64 o; \ - break; \ + return [OFNumber numberWithUInt64: \ + value.uint64 o [n asUInt64]]; \ case OF_NUMBER_SIZE: \ - value.size o; \ - break; \ + return [OFNumber numberWithSize: \ + value.size o [n asSize]]; \ case OF_NUMBER_SSIZE: \ - value.ssize o; \ - break; \ + return [OFNumber numberWithSSize: \ + value.ssize o [n asSSize]]; \ case OF_NUMBER_INTMAX: \ - value.intmax o; \ - break; \ + return [OFNumber numberWithIntMax: \ + value.intmax o [n asIntMax]]; \ case OF_NUMBER_UINTMAX: \ - value.uintmax o; \ - break; \ + return [OFNumber numberWithUIntMax: \ + value.uintmax o [n asUIntMax]]; \ case OF_NUMBER_PTRDIFF: \ - value.ptrdiff o; \ - break; \ + return [OFNumber numberWithPtrDiff: \ + value.ptrdiff o [n asPtrDiff]]; \ case OF_NUMBER_INTPTR: \ - value.intptr o; \ - break; \ + return [OFNumber numberWithIntPtr: \ + value.intptr o [n asIntPtr]]; \ case OF_NUMBER_FLOAT: \ - value.float_ o; \ - break; \ + return [OFNumber numberWithFloat: \ + value.float_ o [n asFloat]]; \ case OF_NUMBER_DOUBLE: \ - value.double_ o; \ - break; \ + return [OFNumber numberWithDouble: \ + value.double_ o [n asDouble]]; \ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } -#define CALCULATE2(o, n) \ - switch ([n type]) { \ +#define CALCULATE2(o) \ + switch (type) { \ case OF_NUMBER_CHAR: \ - value.char_ o [n asChar]; \ - break; \ + return [OFNumber numberWithChar: value.char_ o]; \ case OF_NUMBER_SHORT: \ - value.short_ o [n asShort]; \ - break; \ + return [OFNumber numberWithShort: value.short_ o]; \ case OF_NUMBER_INT: \ - value.int_ o [n asInt]; \ - break; \ + return [OFNumber numberWithInt: value.int_ o]; \ case OF_NUMBER_LONG: \ - value.long_ o [n asLong]; \ - break; \ + return [OFNumber numberWithLong: value.long_ o]; \ case OF_NUMBER_UCHAR: \ - value.uchar o [n asUChar]; \ - break; \ + return [OFNumber numberWithUChar: value.uchar o]; \ case OF_NUMBER_USHORT: \ - value.ushort o [n asUShort]; \ - break; \ + return [OFNumber numberWithUShort: value.ushort o]; \ case OF_NUMBER_UINT: \ - value.uint o [n asUInt]; \ - break; \ + return [OFNumber numberWithUInt: value.uint o]; \ case OF_NUMBER_ULONG: \ - value.ulong o [n asULong]; \ - break; \ + return [OFNumber numberWithULong: value.ulong o]; \ case OF_NUMBER_INT8: \ - value.int8 o [n asInt8]; \ - break; \ + return [OFNumber numberWithInt8: value.int8 o]; \ case OF_NUMBER_INT16: \ - value.int16 o [n asInt16]; \ - break; \ + return [OFNumber numberWithInt16: value.int16 o]; \ case OF_NUMBER_INT32: \ - value.int32 o [n asInt32]; \ - break; \ + return [OFNumber numberWithInt32: value.int32 o]; \ case OF_NUMBER_INT64: \ - value.int64 o [n asInt64]; \ - break; \ + return [OFNumber numberWithInt64: value.int64 o]; \ case OF_NUMBER_UINT8: \ - value.uint8 o [n asUInt8]; \ - break; \ + return [OFNumber numberWithUInt8: value.uint8 o]; \ case OF_NUMBER_UINT16: \ - value.uint16 o [n asUInt16]; \ - break; \ + return [OFNumber numberWithUInt16: value.uint16 o]; \ case OF_NUMBER_UINT32: \ - value.uint32 o [n asUInt32]; \ - break; \ + return [OFNumber numberWithUInt32: value.uint32 o]; \ case OF_NUMBER_UINT64: \ - value.uint64 o [n asUInt64]; \ - break; \ + return [OFNumber numberWithUInt64: value.uint64 o]; \ case OF_NUMBER_SIZE: \ - value.size o [n asSize]; \ - break; \ + return [OFNumber numberWithSize: value.size o]; \ case OF_NUMBER_SSIZE: \ - value.ssize o [n asSSize]; \ - break; \ + return [OFNumber numberWithSSize: value.ssize o]; \ case OF_NUMBER_INTMAX: \ - value.intmax o [n asIntMax]; \ - break; \ + return [OFNumber numberWithIntMax: value.intmax o]; \ case OF_NUMBER_UINTMAX: \ - value.uintmax o [n asUIntMax]; \ - break; \ + return [OFNumber numberWithUIntMax: value.uintmax o]; \ case OF_NUMBER_PTRDIFF: \ - value.ptrdiff o [n asPtrDiff]; \ - break; \ + return [OFNumber numberWithPtrDiff: value.ptrdiff o]; \ case OF_NUMBER_INTPTR: \ - value.intptr o [n asIntPtr]; \ - break; \ + return [OFNumber numberWithIntPtr: value.intptr o]; \ case OF_NUMBER_FLOAT: \ - value.float_ o [n asFloat]; \ - break; \ + return [OFNumber numberWithFloat: value.float_ o]; \ case OF_NUMBER_DOUBLE: \ - value.double_ o [n asDouble]; \ - break; \ + return [OFNumber numberWithDouble: value.double_ o]; \ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } @implementation OFNumber @@ -756,44 +733,58 @@ } } - (uint32_t)hash { - return [self asUInt32]; + uint32_t hash; + size_t i; + + switch (type) { + case OF_NUMBER_FLOAT: + OF_HASH_INIT(hash); + for (i = 0; i < sizeof(float); i++) + OF_HASH_ADD(hash, ((char*)&value.float_)[i]); + OF_HASH_FINALIZE(hash); + + return hash; + case OF_NUMBER_DOUBLE: + OF_HASH_INIT(hash); + for (i = 0; i < sizeof(double); i++) + OF_HASH_ADD(hash, ((char*)&value.double_)[i]); + OF_HASH_FINALIZE(hash); + + return hash; + default: + return [self asUInt32]; + } } - add: (OFNumber*)num { - CALCULATE2(+=, num) - return self; + CALCULATE(+, num) } - subtract: (OFNumber*)num { - CALCULATE2(-=, num) - return self; + CALCULATE(-, num) } - multiplyWith: (OFNumber*)num { - CALCULATE2(*=, num) - return self; + CALCULATE(*, num) } - divideBy: (OFNumber*)num { - CALCULATE2(/=, num) - return self; + CALCULATE(/, num) } - increase { - CALCULATE(++) - return self; + CALCULATE2(+ 1) } - decrease { - CALCULATE(--) - return self; + CALCULATE2(- 1) } @end Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -15,11 +15,11 @@ #include #import /** - * A result of a comparison. + * \brief A result of a comparison. */ typedef enum { /// The left object is smaller than the right OF_ORDERED_ASCENDING = -1, /// Both objects are equal @@ -27,11 +27,11 @@ /// The left object is bigger than the right OF_ORDERED_DESCENDING = 1 } of_comparison_result_t; /** - * The OFObject class is the base class for all other classes inside ObjFW. + * \brief The root class for all other classes inside ObjFW. */ @interface OFObject { /// The class of the object Class isa; @@ -289,24 +289,26 @@ */ - (void)dealloc; @end /** - * Objects implementing this protocol can be copied. + * \brief A protocol for creation of copies. */ @protocol OFCopying /** * \return A copy of the object */ - (id)copy; @end /** + * \brief A protocol for creation of mutable copies. + * * This protocol is implemented by objects that can be mutable and immutable * and allows returning a mutable copy. */ @protocol OFMutableCopying /** * \return A copy of the object */ - (id)mutableCopy; @end Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -29,23 +29,25 @@ #ifdef OF_GNU_RUNTIME # import #endif #ifdef OF_ATOMIC_OPS -#import "atomic.h" +# import "atomic.h" #else -#import "threading.h" +# import "threading.h" #endif +/// \cond internal struct pre_ivar { void **memchunks; size_t memchunks_size; int32_t retain_count; /* int32_t because atomic ops use int32_t */ #ifndef OF_ATOMIC_OPS of_spinlock_t retain_spinlock; #endif }; +/// \endcond /* Hopefully no arch needs more than 16 bytes padding */ #define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + 15) & ~15) #define PRE_IVAR ((struct pre_ivar*)((char*)self - PRE_IVAR_ALIGN)) Index: src/OFPlugin.h ================================================================== --- src/OFPlugin.h +++ src/OFPlugin.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -14,16 +14,16 @@ @class OFString; #ifndef _WIN32 typedef void* of_plugin_handle_t; #else -#include +# include typedef HMODULE of_plugin_handle_t; #endif /** - * The OFPlugin class provides a system for loading plugins at runtime. + * \brief Provides a system for loading plugins at runtime. */ @interface OFPlugin: OFObject { of_plugin_handle_t handle; } Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFSocket.h ================================================================== --- src/OFSocket.h +++ src/OFSocket.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -15,11 +15,11 @@ # define _WIN32_WINNT 0x0501 # include #endif /** - * The OFTCPSocket class provides functions to create and use sockets. + * \brief A class which provides functions to create and use sockets. */ @interface OFSocket: OFStream { #ifndef _WIN32 int sock; Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -12,11 +12,11 @@ #import "OFObject.h" @class OFString; /** - * The OFStream class provides a base class for different types of streams. + * \brief A base class for different types of streams. */ @interface OFStream: OFObject { char *cache; size_t cache_len; Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -30,11 +30,11 @@ extern size_t of_string_index_to_position(const char*, size_t, size_t); @class OFArray; /** - * A class for managing strings. + * \brief A class for handling strings. */ @interface OFString: OFObject { char *string; unsigned int length; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -22,11 +22,11 @@ #endif @class OFString; /** - * The OFTCPSocket class provides functions to create and use sockets. + * \brief A class which provides functions to create and use TCP sockets. */ @interface OFTCPSocket: OFSocket { struct sockaddr *saddr; socklen_t saddr_len; Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -13,11 +13,11 @@ #import "OFList.h" #import "threading.h" /** - * A Thread Local Storage key. + * \brief A class for Thread Local Storage keys. */ @interface OFTLSKey: OFObject { @public of_tlskey_t key; @@ -50,21 +50,20 @@ */ - initWithDestructor: (void(*)(id))destructor; @end /** - * The OFThread class provides portable threads. + * \brief A class which provides portable threads. * * To use it, you should create a new class derived from it and reimplement * main. */ @interface OFThread: OFObject { id object; of_thread_t thread; BOOL running; - @public id retval; } /** @@ -116,11 +115,11 @@ */ - join; @end /** - * A class for creating mutual exclusions. + * \brief A class for creating mutual exclusions. */ @interface OFMutex: OFObject { of_mutex_t mutex; } Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -67,11 +67,11 @@ } - initWithObject: (OFObject *)obj { self = [super init]; - object = [obj copy]; + object = [obj retain]; if (!of_thread_new(&thread, call_main, self)) { Class c = isa; [object release]; [super dealloc]; Index: src/OFURLEncoding.h ================================================================== --- src/OFURLEncoding.h +++ src/OFURLEncoding.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -12,12 +12,11 @@ #import "OFString.h" extern int _OFURLEncoding_reference; /** - * The OFString (OFURLEncoding) category provides an easy way to encode and - * decode strings for URLs. + * \brief A category which provides URL encoding and decoding. */ @interface OFString (OFURLEncoding) /** * Encodes a string for use in a URL. * Index: src/OFURLEncoding.m ================================================================== --- src/OFURLEncoding.m +++ src/OFURLEncoding.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -1,162 +1,22 @@ /* - * Copyright (c) 2008 - 2009 + * 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 "OFObject.h" #import "OFString.h" -@class OFDictionary; -@class OFMutableArray; - extern int _OFXMLElement_reference; /** - * The OFXMLAttribute represents an attribute of an XML element as an object. - */ -@interface OFXMLAttribute: OFObject -{ - OFString *prefix; - OFString *name; - OFString *ns; - OFString *value; -} - -/** - * \param name The name of the attribute - * \param prefix The prefix of the attribute - * \param ns The namespace of the attribute - * \param value The string value of the attribute - * \return A new autoreleased OFXMLAttribute with the specified parameters - */ -+ attributeWithName: (OFString*)name - prefix: (OFString*)prefix - namespace: (OFString*)ns - stringValue: (OFString*)value; - -/** - * Initializes an already allocated OFXMLAttribute. - * - * \param name The name of the attribute - * \param prefix The prefix of the attribute - * \param ns The namespace of the attribute - * \param value The string value of the attribute - * \return An initialized OFXMLAttribute with the specified parameters - */ -- initWithName: (OFString*)name - prefix: (OFString*)prefix - namespace: (OFString*)ns - stringValue: (OFString*)value; - -/** - * \return The name of the attribute as an autoreleased OFString - */ -- (OFString*)name; - -/** - * \return The prefix of the attribute as an autoreleased OFString - */ -- (OFString*)prefix; - -/** - * \return The namespace of the attribute as an autoreleased OFString - */ -- (OFString*)namespace; - -/** - * \return The string value of the attribute as an autoreleased OFString - */ -- (OFString*)stringValue; -@end - -/** - * The OFXMLElement represents an XML element as an object which can be - * modified and converted back to XML again. - */ -@interface OFXMLElement: OFObject -{ - OFString *name; - OFMutableArray *attrs; - OFString *stringval; - OFMutableArray *children; -} - -/** - * \param name The name for the element - * \return A new autorelease OFXMLElement with the specified element name - */ -+ elementWithName: (OFString*)name; - -/** - * \param name The name for the element - * \param stringval The value for the element - * \return A new autorelease OFXMLElement with the specified element name and - * value - */ -+ elementWithName: (OFString*)name - stringValue: (OFString*)stringval; - -/** - * Initializes an already allocated OFXMLElement with the specified name. - * - * \param name The name for the element - * \return An initialized OFXMLElement with the specified element name - */ -- initWithName: (OFString*)name; - -/** - * Initializes an already allocated OFXMLElement with the specified name and - * value. - * - * \param name The name for the element - * \param stringval The value for the element - * \return An initialized OFXMLElement with the specified element name and - * value - */ -- initWithName: (OFString*)name - stringValue: (OFString*)stringval; - -/** - * \return A new autoreleased OFString representing the OFXMLElement as an - * XML string - */ -- (OFString*)string; - -/** - * Adds the specified attribute. - * - * \param attr The attribute to add - */ -- addAttribute: (OFXMLAttribute*)attr; - -/** - * Adds the specified attribute with the specified value. - * - * \param name The name of the attribute - * \param value The value of the attribute - */ -- addAttributeWithName: (OFString*)name - stringValue: (OFString*)value; - -/** - * Adds a child to the OFXMLElement. - * - * \param child Another OFXMLElement which is added as a child - */ -- addChild: (OFXMLElement*)child; -@end - -/** - * The OFString (OFXMLEscaping) category provides an easy way to escape strings - * for use in an XML document. + * \brief A category to escape strings for use in an XML document. */ @interface OFString (OFXMLEscaping) /** * Escapes a string for use in an XML document. * Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -15,265 +15,14 @@ #include #include #import "OFXMLElement.h" #import "OFString.h" -#import "OFArray.h" -#import "OFAutoreleasePool.h" #import "OFExceptions.h" int _OFXMLElement_reference; -@implementation OFXMLAttribute -+ attributeWithName: (OFString*)name_ - prefix: (OFString*)prefix_ - namespace: (OFString*)ns_ - stringValue: (OFString*)value_ -{ - return [[[self alloc] initWithName: name_ - prefix: prefix_ - namespace: ns_ - stringValue: value_] autorelease]; -} - -- initWithName: (OFString*)name_ - prefix: (OFString*)prefix_ - namespace: (OFString*)ns_ - stringValue: (OFString*)value_ -{ - self = [super init]; - - name = [name_ copy]; - prefix = [prefix_ copy]; - ns = [ns_ copy]; - value = [value_ copy]; - - return self; -} - -- (void)dealloc -{ - [name release]; - [prefix release]; - [ns release]; - [value release]; - - [super dealloc]; -} - -- (OFString*)name -{ - return [[name copy] autorelease]; -} - -- (OFString*)prefix -{ - return [[prefix copy] autorelease]; -} - -- (OFString*)namespace -{ - return [[ns copy] autorelease]; -} - -- (OFString*)stringValue -{ - return [[value copy] autorelease]; -} -@end - -@implementation OFXMLElement -+ elementWithName: (OFString*)name_ -{ - return [[[self alloc] initWithName: name_] autorelease]; -} - -+ elementWithName: (OFString*)name_ - stringValue: (OFString*)stringval_ -{ - return [[[self alloc] initWithName: name_ - stringValue: stringval_] autorelease]; -} - -- init -{ - @throw [OFNotImplementedException newWithClass: isa - selector: _cmd]; -} - -- initWithName: (OFString*)name_ -{ - self = [super init]; - - name = [name_ copy]; - - return self; -} - -- initWithName: (OFString*)name_ - stringValue: (OFString*)stringval_ -{ - self = [super init]; - - name = [name_ copy]; - stringval = [stringval_ copy]; - - return self; -} - -- (OFString*)string -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - char *str_c; - size_t len, i, j, attrs_count; - OFXMLAttribute **attrs_carray; - OFString *ret, *tmp; - - len = [name cStringLength] + 3; - str_c = [self allocMemoryWithSize: len]; - - /* Start of tag */ - *str_c = '<'; - memcpy(str_c + 1, [name cString], [name cStringLength]); - i = [name cStringLength] + 1; - - /* Attributes */ - attrs_carray = [attrs cArray]; - attrs_count = [attrs count]; - - for (j = 0; j < attrs_count; j++) { - /* FIXME: Add namespace support */ - OFString *attr_name = [attrs_carray[j] name]; - tmp = [[attrs_carray[j] stringValue] stringByXMLEscaping]; - - len += [attr_name cStringLength] + [tmp cStringLength] + 4; - @try { - str_c = [self resizeMemory: str_c - toSize: len]; - } @catch (OFException *e) { - [self freeMemory: str_c]; - @throw e; - } - - str_c[i++] = ' '; - memcpy(str_c + i, [attr_name cString], - [attr_name cStringLength]); - i += [attr_name cStringLength]; - str_c[i++] = '='; - str_c[i++] = '\''; - memcpy(str_c + i, [tmp cString], [tmp cStringLength]); - i += [tmp cStringLength]; - str_c[i++] = '\''; - - [pool releaseObjects]; - } - - /* Childen */ - if (stringval != nil || children != nil) { - if (stringval != nil) - tmp = [stringval stringByXMLEscaping]; - else if (children != nil) { - OFXMLElement **children_carray = [children cArray]; - size_t children_count = [children count]; - IMP append; - - tmp = [OFMutableString string]; - append = [tmp methodForSelector: - @selector(appendCStringWithoutUTF8Checking:)]; - - for (j = 0; j < children_count; j++) - append(tmp, @selector( - appendCStringWithoutUTF8Checking:), - [[children_carray[j] string] cString]); - } - - len += [tmp cStringLength] + [name cStringLength] + 2; - @try { - str_c = [self resizeMemory: str_c - toSize: len]; - } @catch (OFException *e) { - [self freeMemory: str_c]; - @throw e; - } - - str_c[i++] = '>'; - memcpy(str_c + i, [tmp cString], [tmp cStringLength]); - i += [tmp cStringLength]; - str_c[i++] = '<'; - str_c[i++] = '/'; - memcpy(str_c + i, [name cString], [name cStringLength]); - i += [name cStringLength]; - } else - str_c[i++] = '/'; - - str_c[i++] = '>'; - assert(i == len); - - [pool release]; - - @try { - ret = [OFString stringWithCString: str_c - length: len]; - } @finally { - [self freeMemory: str_c]; - } - return ret; -} - -- addAttribute: (OFXMLAttribute*)attr -{ - if (attrs == nil) - attrs = [[OFMutableArray alloc] init]; - - /* FIXME: Prevent having it twice! */ - - [attrs addObject: attr]; - - return self; -} - -- addAttributeWithName: (OFString*)name_ - stringValue: (OFString*)value -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - [self addAttribute: [OFXMLAttribute attributeWithName: name_ - prefix: nil - namespace: nil - stringValue: value]]; - [pool release]; - - return self; -} - -/* TODO: Replace attribute */ -/* TODO: Remove attribute */ - -- addChild: (OFXMLElement*)child -{ - if (stringval != nil) - @throw [OFInvalidArgumentException newWithClass: isa - selector: _cmd]; - - if (children == nil) - children = [[OFMutableArray alloc] init]; - - [children addObject: child]; - - return self; -} - -- (void)dealloc -{ - [name release]; - [attrs release]; - [stringval release]; - [children release]; - - [super dealloc]; -} -@end - @implementation OFString (OFXMLEscaping) - stringByXMLEscaping { char *str_c, *append, *tmp; size_t len, append_len; Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -1,92 +1,23 @@ /* - * Copyright (c) 2008 - 2009 + * 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 "OFObject.h" #import "OFString.h" extern int _OFXMLParser_reference; -@class OFXMLParser; -@class OFArray; -@class OFMutableArray; - -/** - * A protocol that needs to be implemented by delegates for OFXMLParser. - */ -@protocol OFXMLParserDelegate -/** - * This callback is called when the XML parser found the start of a new tag. - * - * \param parser The parser which found a new tag - * \param name The name of the tag which just started - * \param prefix The prefix of the tag which just started or nil - * \param ns The namespace of the tag which just started or nil - * \param attrs The attributes included in the tag which just started or nil - */ -- (void)xmlParser: (OFXMLParser*)parser - didStartTagWithName: (OFString*)name - prefix: (OFString*)prefix - namespace: (OFString*)ns - attributes: (OFArray*)attrs; - -/** - * This callback is called when the XML parser found the end of a tag. - * - * \param parser The parser which found the end of a tag - * \param name The name of the tag which just ended - * \param prefix The prefix of the tag which just ended or nil - * \param ns The namespace of the tag which just ended or nil - */ -- (void)xmlParser: (OFXMLParser*)parser - didEndTagWithName: (OFString*)name - prefix: (OFString*)prefix - namespace: (OFString*)ns; - -/** - * This callback is called when the XML parser found a string. - * - * \param parser The parser which found a string - * \param string The string the XML parser found - */ -- (void)xmlParser: (OFXMLParser*)parser - foundString: (OFString*)string; - -/** - * This callback is called when the XML parser found a comment. - * - * \param parser The parser which found a comment - * \param comment The comment the XML parser found - */ -- (void)xmlParser: (OFXMLParser*)parser - foundComment: (OFString*)comment; - -/** - * This callback is called when the XML parser found an entity it doesn't know. - * The callback is supposed to return a substitution for the entity or nil if - * it is not known to the callback as well, in which case an exception will be - * risen. - * - * \param parser The parser which found an unknown entity - * \param entity The name of the entity the XML parser didn't know - * \return A substitution for the entity or nil - */ -- (OFString*)xmlParser: (OFXMLParser*)parser - foundUnknownEntityNamed: (OFString*)entity; -@end - -/** - * A protocol that needs to be implemented by delegates for - * stringByXMLUnescapingWithHandler:. +/** + * \brief A protocol that needs to be implemented by delegates for + * stringByXMLUnescapingWithHandler:. */ @protocol OFXMLUnescapingDelegate /** * This callback is called when an unknown entity was found while trying to * unescape XML. The callback is supposed to return a substitution for the @@ -98,73 +29,11 @@ */ - (OFString*)foundUnknownEntityNamed: (OFString*)entity; @end /** - * An event-based XML parser which calls the delegate's callbacks as soon as - * it finds something, thus suitable for streams as well. - */ -@interface OFXMLParser: OFObject -{ - OFObject *delegate; - enum { - OF_XMLPARSER_OUTSIDE_TAG, - OF_XMLPARSER_TAG_OPENED, - OF_XMLPARSER_IN_TAG_NAME, - OF_XMLPARSER_IN_CLOSE_TAG_NAME, - OF_XMLPARSER_IN_TAG, - OF_XMLPARSER_IN_ATTR_NAME, - OF_XMLPARSER_EXPECT_DELIM, - OF_XMLPARSER_IN_ATTR_VALUE, - OF_XMLPARSER_EXPECT_CLOSE, - OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE, - OF_XMLPARSER_IN_COMMENT_1, - OF_XMLPARSER_IN_COMMENT_2, - OF_XMLPARSER_IN_COMMENT_3, - OF_XMLPARSER_IN_COMMENT_4 - } state; - OFMutableString *cache; - OFString *name; - OFString *prefix; - OFString *ns; - OFMutableArray *attrs; - OFString *attr_name; - OFString *attr_prefix; - char delim; - OFMutableArray *previous; -} - -/** - * \return A new, autoreleased OFXMLParser - */ -+ xmlParser; - -/** - * \return The delegate that is used by the XML parser - */ -- (id)delegate; - -/** - * Sets the delegate the OFXMLParser should use. - * - * \param delegate The delegate to use - */ -- setDelegate: (OFObject *)delegate; - -/** - * Parses a buffer with the specified size. - * - * \param buf The buffer to parse - * \param size The size of the buffer - */ -- parseBuffer: (const char*)buf - withSize: (size_t)size; -@end - -/** - * The OFString (OFXMLUnescaping) category provides methods to unescape XML in - * strings. + * \brief A category for unescaping XML in strings. */ @interface OFString (OFXMLUnescaping) /** * Unescapes XML in the string. */ @@ -176,8 +45,5 @@ * * \param h An OFXMLUnescapingDelegate as a handler for unknown entities */ - stringByXMLUnescapingWithHandler: (OFObject *)h; @end - -@interface OFObject (OFXMLParserDelegate) -@end Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -13,27 +13,16 @@ #include #import "OFXMLParser.h" #import "OFString.h" -#import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "OFMacros.h" int _OFXMLParser_reference; -static OF_INLINE OFString* -transform_string(OFMutableString *cache, - OFObject *handler) -{ - /* TODO: Support for xml:space */ - - [cache removeLeadingAndTrailingWhitespaces]; - return [cache stringByXMLUnescapingWithHandler: handler]; -} - static OF_INLINE OFString* parse_numeric_entity(const char *entity, size_t length) { of_unichar_t c; size_t i; @@ -78,430 +67,10 @@ return [OFString stringWithCString: buf length: i]; } -@implementation OFXMLParser -+ xmlParser -{ - return [[[self alloc] init] autorelease]; -} - -- init -{ - self = [super init]; - - @try { - cache = [[OFMutableString alloc] init]; - previous = [[OFMutableArray alloc] init]; - } @catch (OFException *e) { - /* We can't use [super dealloc] on OS X here. Compiler bug? */ - [self dealloc]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [delegate release]; - - [cache release]; - [name release]; - [prefix release]; - [ns release]; - [attrs release]; - [attr_name release]; - [attr_prefix release]; - [previous release]; - - [super dealloc]; -} - -- (id)delegate -{ - return [[delegate retain] autorelease]; -} - -- setDelegate: (OFObject *)delegate_ -{ - [delegate_ retain]; - [delegate release]; - delegate = delegate_; - - return self; -} - -- parseBuffer: (const char*)buf - withSize: (size_t)size -{ - OFAutoreleasePool *pool; - size_t i, last, len; - - last = 0; - - for (i = 0; i < size; i++) { - switch (state) { - /* Not in a tag */ - case OF_XMLPARSER_OUTSIDE_TAG: - if (buf[i] == '<') { - len = i - last; - - if (len > 0) - [cache appendCString: buf + last - withLength: len]; - - if ([cache cStringLength] > 0) { - OFString *str; - - pool = [[OFAutoreleasePool alloc] init]; - str = transform_string(cache, self); - [delegate xmlParser: self - foundString: str]; - [pool release]; - } - - [cache setToCString: ""]; - - last = i + 1; - state = OF_XMLPARSER_TAG_OPENED; - } - break; - - /* Tag was just opened */ - case OF_XMLPARSER_TAG_OPENED: - if (buf[i] == '/') { - last = i + 1; - state = OF_XMLPARSER_IN_CLOSE_TAG_NAME; - } else if(buf[i] == '!') { - last = i + 1; - state = OF_XMLPARSER_IN_COMMENT_1; - } else { - state = OF_XMLPARSER_IN_TAG_NAME; - i--; - } - break; - - /* Inside a tag, no name yet */ - case OF_XMLPARSER_IN_TAG_NAME: - if (buf[i] == ' ' || buf[i] == '>' || buf[i] == '/') { - const char *cache_c, *tmp; - size_t cache_len; - - len = i - last; - if (len > 0) - [cache appendCString: buf + last - withLength: len]; - cache_c = [cache cString]; - cache_len = [cache cStringLength]; - - if ((tmp = memchr(cache_c, ':', - cache_len)) != NULL) { - name = [[OFString alloc] - initWithCString: tmp + 1 - length: cache_len - (tmp - - cache_c) - 1]; - prefix = [[OFString alloc] - initWithCString: cache_c - length: tmp - cache_c]; - } else { - name = [cache copy]; - prefix = nil; - } - - if (buf[i] == '>' || buf[i] == '/') { - pool = [[OFAutoreleasePool alloc] init]; - - [delegate xmlParser: self - didStartTagWithName: name - prefix: prefix - namespace: ns - attributes: nil]; - - if (buf[i] == '/') - [delegate xmlParser: self - didEndTagWithName: name - prefix: prefix - namespace: ns]; - else - [previous addObject: - [[cache copy] autorelease]]; - - [pool release]; - - [name release]; - [prefix release]; - [ns release]; - name = prefix = ns = nil; - - state = (buf[i] == '/' - ? OF_XMLPARSER_EXPECT_CLOSE - : OF_XMLPARSER_OUTSIDE_TAG); - } else - state = OF_XMLPARSER_IN_TAG; - - [cache setToCString: ""]; - last = i + 1; - } - break; - - /* Inside a close tag, no name yet */ - case OF_XMLPARSER_IN_CLOSE_TAG_NAME: - if (buf[i] == ' ' || buf[i] == '>') { - const char *cache_c, *tmp; - size_t cache_len; - - len = i - last; - if (len > 0) - [cache appendCString: buf + last - withLength: len]; - cache_c = [cache cString]; - cache_len = [cache cStringLength]; - - if ((tmp = memchr(cache_c, ':', - cache_len)) != NULL) { - name = [[OFString alloc] - initWithCString: tmp + 1 - length: cache_len - (tmp - - cache_c) - 1]; - prefix = [[OFString alloc] - initWithCString: cache_c - length: tmp - cache_c]; - } else { - name = [cache copy]; - prefix = nil; - } - - if (![[previous lastObject] isEqual: cache]) - @throw [OFMalformedXMLException - newWithClass: isa]; - [previous removeNObjects: 1]; - - [cache setToCString: ""]; - - pool = [[OFAutoreleasePool alloc] init]; - - [delegate xmlParser: self - didEndTagWithName: name - prefix: prefix - namespace: ns]; - - [pool release]; - - [name release]; - [prefix release]; - [ns release]; - name = prefix = ns = nil; - - last = i + 1; - state = (buf[i] == ' ' - ? OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE - : OF_XMLPARSER_OUTSIDE_TAG); - } - break; - - /* Inside a tag, name found */ - case OF_XMLPARSER_IN_TAG: - if (buf[i] == '>' || buf[i] == '/') { - pool = [[OFAutoreleasePool alloc] init]; - - [delegate xmlParser: self - didStartTagWithName: name - prefix: prefix - namespace: ns - attributes: attrs]; - - if (buf[i] == '/') - [delegate xmlParser: self - didEndTagWithName: name - prefix: prefix - namespace: ns]; - else if (prefix != nil) { - OFString *str = [OFString - stringWithFormat: @"%s:%s", - [prefix cString], - [name cString]]; - [previous addObject: str]; - } else - [previous addObject: name]; - - [pool release]; - - [name release]; - [prefix release]; - [ns release]; - [attrs release]; - name = prefix = ns = nil; - attrs = nil; - - last = i + 1; - state = (buf[i] == '/' - ? OF_XMLPARSER_EXPECT_CLOSE - : OF_XMLPARSER_OUTSIDE_TAG); - } else if (buf[i] != ' ') { - last = i; - state = OF_XMLPARSER_IN_ATTR_NAME; - i--; - } - break; - - /* Looking for attribute name */ - case OF_XMLPARSER_IN_ATTR_NAME: - if (buf[i] == '=') { - const char *cache_c, *tmp; - size_t cache_len; - - len = i - last; - if (len > 0) - [cache appendCString: buf + last - withLength: len]; - - cache_c = [cache cString]; - cache_len = [cache cStringLength]; - - if ((tmp = memchr(cache_c, ':', - cache_len)) != NULL ) { - attr_name = [[OFString alloc] - initWithCString: tmp + 1 - length: cache_len - (tmp - - cache_c) - 1]; - attr_prefix = [[OFString alloc] - initWithCString: cache_c - length: tmp - cache_c]; - } else { - attr_name = [cache copy]; - attr_prefix = nil; - } - - [cache setToCString: ""]; - - last = i + 1; - state = OF_XMLPARSER_EXPECT_DELIM; - } - break; - - /* Expecting delimiter */ - case OF_XMLPARSER_EXPECT_DELIM: - if (buf[i] != '\'' && buf[i] != '"') - @throw [OFMalformedXMLException - newWithClass: isa]; - - delim = buf[i]; - last = i + 1; - state = OF_XMLPARSER_IN_ATTR_VALUE; - break; - - /* Looking for attribute value */ - case OF_XMLPARSER_IN_ATTR_VALUE: - if (buf[i] == delim) { - OFString *attr_val; - - len = i - last; - if (len > 0) - [cache appendCString: buf + last - withLength: len]; - - if (attrs == nil) - attrs = [[OFMutableArray alloc] init]; - - pool = [[OFAutoreleasePool alloc] init]; - attr_val = [cache - stringByXMLUnescapingWithHandler: self]; - [attrs addObject: [OFXMLAttribute - attributeWithName: attr_name - prefix: attr_prefix - namespace: nil - stringValue: attr_val]]; - [pool release]; - - [cache setToCString: ""]; - [attr_name release]; - [attr_prefix release]; - attr_name = attr_prefix = nil; - - last = i + 1; - state = OF_XMLPARSER_IN_TAG; - } - break; - - /* Expecting closing '>' */ - case OF_XMLPARSER_EXPECT_CLOSE: - if (buf[i] == '>') { - last = i + 1; - state = OF_XMLPARSER_OUTSIDE_TAG; - } else - @throw [OFMalformedXMLException - newWithClass: isa]; - break; - - /* Expecting closing '>' or space */ - case OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE: - if (buf[i] == '>') { - last = i + 1; - state = OF_XMLPARSER_OUTSIDE_TAG; - } else if (buf[i] != ' ') - @throw [OFMalformedXMLException - newWithClass: isa]; - break; - - /* Comment */ - case OF_XMLPARSER_IN_COMMENT_1: - case OF_XMLPARSER_IN_COMMENT_2: - if (buf[i] != '-') - @throw [OFMalformedXMLException - newWithClass: isa]; - last = i + 1; - state++; - break; - case OF_XMLPARSER_IN_COMMENT_3: - if (buf[i] == '-') - state = OF_XMLPARSER_IN_COMMENT_4; - break; - case OF_XMLPARSER_IN_COMMENT_4: - if (buf[i] == '-') { - size_t cache_len; - - [cache appendCString: buf + last - withLength: i - last]; - cache_len = [cache length]; - - pool = [[OFAutoreleasePool alloc] init]; - [cache removeCharactersFromIndex: cache_len - 1 - toIndex: cache_len]; - [cache removeLeadingAndTrailingWhitespaces]; - [delegate xmlParser: self - foundComment: cache]; - [pool release]; - - [cache setToCString: ""]; - - last = i + 1; - state = OF_XMLPARSER_EXPECT_CLOSE; - } else - state = OF_XMLPARSER_IN_COMMENT_3; - - break; - } - } - - len = size - last; - /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ - if (len > 0 && state != OF_XMLPARSER_IN_TAG) - [cache appendCString: buf + last - withLength: len]; - - return self; -} - -- (OFString*)foundUnknownEntityNamed: (OFString*)entity -{ - return [delegate xmlParser: self - foundUnknownEntityNamed: entity]; -} -@end - @implementation OFString (OFXMLUnescaping) - stringByXMLUnescaping { return [self stringByXMLUnescapingWithHandler: nil]; } @@ -587,39 +156,6 @@ [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; return ret; } -@end - -@implementation OFObject (OFXMLParserDelegate) -- (void)xmlParser: (OFXMLParser*)parser - didStartTagWithName: (OFString*)name - prefix: (OFString*)prefix - namespace: (OFString*)ns - attributes: (OFArray*)attrs -{ -} - -- (void)xmlParser: (OFXMLParser*)parser - didEndTagWithName: (OFString*)name - prefix: (OFString*)prefix - namespace: (OFString*)ns -{ -} - -- (void)xmlParser: (OFXMLParser*)parser - foundString: (OFString*)string -{ -} - -- (void)xmlParser: (OFXMLParser*)parser - foundComment: (OFString*)comment -{ -} - -- (OFString*)xmlParser: (OFXMLParser*)parser - foundUnknownEntityNamed: (OFString*)entity -{ - return nil; -} @end Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -1,8 +1,8 @@ /* - * Copyright (c) 2008 - 2009 - * Jonathan Schleifer "js@webkeks.org" + * 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 Index: src/asprintf.h ================================================================== --- src/asprintf.h +++ src/asprintf.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -10,10 +10,10 @@ */ #import "objfw-defs.h" #ifndef OF_HAVE_ASPRINTF -#include +# include extern int asprintf(char**, const char*, ...); extern int vasprintf(char**, const char*, va_list); #endif Index: src/asprintf.m ================================================================== --- src/asprintf.m +++ src/asprintf.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/atomic.h ================================================================== --- src/atomic.h +++ src/atomic.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/iso_8859_15.m ================================================================== --- src/iso_8859_15.m +++ src/iso_8859_15.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/objc_properties.m ================================================================== --- src/objc_properties.m +++ src/objc_properties.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/objc_sync.m ================================================================== --- src/objc_sync.m +++ src/objc_sync.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -17,17 +17,19 @@ #import #import "threading.h" +/// \cond internal struct locks_s { id obj; size_t count; size_t recursion; of_thread_t thread; of_mutex_t mutex; }; +/// \endcond static of_mutex_t mutex; static struct locks_s *locks = NULL; static size_t num_locks = 0; Index: src/threading.h ================================================================== --- src/threading.h +++ src/threading.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -14,23 +14,23 @@ #if !defined(OF_THREADS) || (!defined(OF_HAVE_PTHREADS) && !defined(_WIN32)) # error No threads available! #endif #if defined(OF_HAVE_PTHREADS) -#include +# include typedef pthread_t of_thread_t; typedef pthread_mutex_t of_mutex_t; typedef pthread_key_t of_tlskey_t; #elif defined(_WIN32) -#include +# include typedef HANDLE of_thread_t; typedef CRITICAL_SECTION of_mutex_t; typedef DWORD of_tlskey_t; #endif #if defined(OF_ATOMIC_OPS) -#import "atomic.h" +# import "atomic.h" typedef int32_t of_spinlock_t; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) typedef pthread_spinlock_t of_spinlock_t; #else typedef pthread_mutex_t of_spinlock_t; @@ -240,11 +240,11 @@ static OF_INLINE BOOL of_spinlock_unlock(of_spinlock_t *s) { #if defined(OF_ATOMIC_OPS) - *s = 0; + of_atomic_and32((uint32_t*)s, 0); return YES; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return (pthread_spin_unlock(s) ? NO : YES); #else return of_mutex_unlock(s); Index: src/unicode.h ================================================================== --- src/unicode.h +++ src/unicode.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/unicode.m ================================================================== --- src/unicode.m +++ src/unicode.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: src/windows_1252.m ================================================================== --- src/windows_1252.m +++ src/windows_1252.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -6,17 +6,16 @@ SRCS = OFArray.m \ OFDataArray.m \ OFDictionary.m \ OFHashes.m \ OFList.m \ + OFNumber.m \ OFObject.m \ ${OFPLUGIN_M} \ OFString.m \ OFTCPSocket.m \ ${OFTHREAD_M} \ - OFXMLElement.m \ - OFXMLParser.m \ main.m \ ${PROPERTIES_M} IPHONE_USER = mobile IPHONE_TMP = /tmp/objfw-test Index: tests/OFArray.m ================================================================== --- tests/OFArray.m +++ tests/OFArray.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -116,13 +116,15 @@ OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]]) EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]", OFOutOfRangeException, [m[0] removeNObjects: [m[0] count] + 1]) - a[1] = [OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil]; TEST(@"-[componentsJoinedByString:]", - [[a[1] componentsJoinedByString: @" "] isEqual: @"foo bar baz"]) + (a[1] = [OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil]) && + [[a[1] componentsJoinedByString: @" "] isEqual: @"foo bar baz"] && + (a[1] = [OFArray arrayWithObject: @"foo"]) && + [[a[1] componentsJoinedByString: @" "] isEqual: @"foo"]) m[0] = [[a[0] mutableCopy] autorelease]; ok = YES; i = 0; Index: tests/OFDataArray.m ================================================================== --- tests/OFDataArray.m +++ tests/OFDataArray.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/OFDictionary.m ================================================================== --- tests/OFDictionary.m +++ tests/OFDictionary.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/OFHashes.m ================================================================== --- tests/OFHashes.m +++ tests/OFHashes.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/OFList.m ================================================================== --- tests/OFList.m +++ tests/OFList.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the ADDED tests/OFNumber.m Index: tests/OFNumber.m ================================================================== --- /dev/null +++ tests/OFNumber.m @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#include "config.h" + +#import "OFNumber.h" +#import "OFAutoreleasePool.h" + +#import "main.h" + +static OFString *module = @"OFNumber"; + +void +number_tests() +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFNumber *num; + + TEST(@"+[numberWithIntMax:]", + (num = [OFNumber numberWithIntMax: 123456789])) + + TEST(@"-[isEqual:]", + [num isEqual: [OFNumber numberWithUInt32: 123456789]]) + + TEST(@"-[hash]", [num hash] == 123456789) + + TEST(@"-[asDouble]", [num asDouble] == 123456789.L) + + TEST(@"-[decrease]", + [[num decrease] isEqual: [OFNumber numberWithInt32: 123456788]]) + + TEST(@"-[divideBy:]", + [[num divideBy: [OFNumber numberWithInt: 2]] asInt] == 61728394) + + [pool drain]; +} Index: tests/OFObject.m ================================================================== --- tests/OFObject.m +++ tests/OFObject.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/OFPlugin.m ================================================================== --- tests/OFPlugin.m +++ tests/OFPlugin.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/OFString.m ================================================================== --- tests/OFString.m +++ tests/OFString.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/OFTCPSocket.m ================================================================== --- tests/OFTCPSocket.m +++ tests/OFTCPSocket.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/OFThread.m ================================================================== --- tests/OFThread.m +++ tests/OFThread.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the DELETED tests/OFXMLElement.m Index: tests/OFXMLElement.m ================================================================== --- tests/OFXMLElement.m +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2008 - 2009 - * 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. - */ - -#include "config.h" - -#import "OFXMLElement.h" -#import "OFString.h" -#import "OFArray.h" -#import "OFAutoreleasePool.h" -#import "OFString.h" -#import "OFExceptions.h" - -#import "main.h" - -static OFString *module = @"OFXMLElement"; - -void -xmlelement_tests() -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFXMLElement *elem[2]; - - TEST(@"+[elementWithName:]", - (elem[0] = [OFXMLElement elementWithName: @"foo"]) && - [[elem[0] string] isEqual: @""]) - - TEST(@"+[elementWithName:stringValue:]", - (elem[1] = [OFXMLElement elementWithName: @"foo" - stringValue: @"b&ar"]) && - [[elem[1] string] isEqual: @"b&ar"]) - - TEST(@"-[addAttributeWithName:stringValue:]", - [elem[0] addAttributeWithName: @"foo" - stringValue: @"b&ar"] && - [[elem[0] string] isEqual: @""] && - [elem[1] addAttributeWithName: @"foo" - stringValue: @"b&ar"] && - [[elem[1] string] isEqual: @"b&ar"]) - - TEST(@"-[addChild:]", - [elem[0] addChild: [OFXMLElement elementWithName: @"bar"]] && - [[elem[0] string] isEqual: @""]) - - [pool drain]; -} DELETED tests/OFXMLParser.m Index: tests/OFXMLParser.m ================================================================== --- tests/OFXMLParser.m +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2008 - 2009 - * 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. - */ - -#include "config.h" - -#include - -#import "OFXMLParser.h" -#import "OFString.h" -#import "OFArray.h" -#import "OFAutoreleasePool.h" -#import "OFString.h" -#import "OFExceptions.h" - -#import "main.h" - -static OFString *module = @"OFXMLParser"; -static int i = 0; - -enum event_type { - TAG_START, - TAG_END, - STRING, - COMMENT -}; - -static void -callback(enum event_type et, OFString *name, OFString *prefix, OFString *ns, - OFArray *attrs, OFString *string, OFString *comment) -{ - OFString *msg; - id *carray; - size_t count; - - i++; - msg = [OFString stringWithFormat: @"Parsing part #%d", i]; - - switch (i) { - case 1: - case 5: - TEST(msg, et == STRING && [string isEqual: @"bar"]) - break; - case 2: - /* FIXME: Namespace */ - carray = [attrs cArray]; - count = [attrs count]; - - TEST(msg, et == TAG_START && [name isEqual: @"bar"] && - [prefix isEqual: @"foo"] && ns == nil && - attrs != nil && count == 2 && - /* Attribute 1 */ - [[carray[0] name] isEqual: @"bar"] && - [carray[0] prefix] == nil && - [[carray[0] stringValue] isEqual: @"b&az"] && - [carray[0] namespace] == nil && - /* Attribute 2 */ - [[carray[1] name] isEqual: @"qux"] && - [[carray[1] prefix] isEqual: @"qux"] && - [[carray[1] stringValue] isEqual: @" quux "] && - [carray[1] namespace] == nil) - break; - case 3: - TEST(msg, et == STRING && [string isEqual: @"foo\r\n" - "foo<barbar quxbar\r\n" - ""; - size_t j, len; - - TEST(@"+[xmlParser]", (parser = [OFXMLParser xmlParser])) - - TEST(@"-[setDelegate:]", - [parser setDelegate: [[[ParserDelegate alloc] init] autorelease]]) - - /* Simulate a stream where we only get chunks */ - len = strlen(str); - - for (j = 0; j < len; j+= 2) { - if (j + 2 > len) - [parser parseBuffer: str + j - withSize: 1]; - else - [parser parseBuffer: str + j - withSize: 2]; - } - - TEST(@"Checking if everything was parsed", i == 11) - - [pool drain]; -} Index: tests/main.h ================================================================== --- tests/main.h +++ tests/main.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the Index: tests/main.m ================================================================== --- tests/main.m +++ tests/main.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the @@ -22,10 +22,11 @@ extern void array_tests(); extern void dataarray_tests(); extern void dictionary_tests(); extern void hashes_tests(); extern void list_tests(); +extern void number_tests(); extern void object_tests(); #ifdef OF_PLUGINS extern void plugin_tests(); #endif #ifdef OF_HAVE_PROPERTIES @@ -34,12 +35,10 @@ extern void string_tests(); extern void tcpsocket_tests(); #ifdef OF_THREADS extern void thread_tests(); #endif -extern void xmlelement_tests(); -extern void xmlparser_tests(); static int fails = 0; static void output(OFString *str, int color) @@ -107,20 +106,19 @@ string_tests(); dataarray_tests(); array_tests(); dictionary_tests(); list_tests(); + number_tests(); tcpsocket_tests(); #ifdef OF_THREADS thread_tests(); #endif - xmlelement_tests(); - xmlparser_tests(); #ifdef OF_PLUGINS plugin_tests(); #endif #ifdef OF_HAVE_PROPERTIES properties_tests(); #endif return fails; } Index: tests/properties.m ================================================================== --- tests/properties.m +++ tests/properties.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2008 - 2009 + * Copyright (c) 2008 - 2010 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the