Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -31,10 +31,12 @@ productName = configure; }; /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 4B11005C14329B9A003A45D8 /* OFXMLNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B11005A14329B9A003A45D8 /* OFXMLNode.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B11005D14329B9A003A45D8 /* OFXMLNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B11005B14329B9A003A45D8 /* OFXMLNode.m */; }; 4B17FF73133A2A76003E6DCD /* OFException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF71133A28FC003E6DCD /* OFException.m */; }; 4B17FF74133A2AAB003E6DCD /* OFException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF70133A28FC003E6DCD /* OFException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B17FF77133A2B18003E6DCD /* OFNotImplementedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B17FF78133A2B18003E6DCD /* OFNotImplementedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF76133A2B18003E6DCD /* OFNotImplementedException.m */; }; 4B17FF7B133A2C15003E6DCD /* OFOutOfRangeException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF79133A2C14003E6DCD /* OFOutOfRangeException.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -379,10 +381,12 @@ /* Begin PBXFileReference section */ 4B0108C910EB8C9300631877 /* OFEnumerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFEnumerator.h; path = src/OFEnumerator.h; sourceTree = ""; }; 4B0108CA10EB8C9300631877 /* OFEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFEnumerator.m; path = src/OFEnumerator.m; sourceTree = ""; }; 4B0D249411DFAA3D00ED6FFC /* OFXMLElementBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLElementBuilder.h; path = src/OFXMLElementBuilder.h; sourceTree = ""; }; 4B0D249511DFAA3D00ED6FFC /* OFXMLElementBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLElementBuilder.m; path = src/OFXMLElementBuilder.m; sourceTree = ""; }; + 4B11005A14329B9A003A45D8 /* OFXMLNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLNode.h; path = src/OFXMLNode.h; sourceTree = ""; }; + 4B11005B14329B9A003A45D8 /* OFXMLNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLNode.m; path = src/OFXMLNode.m; sourceTree = ""; }; 4B175C1D116D130B003C99CB /* OFApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFApplication.h; path = src/OFApplication.h; sourceTree = ""; }; 4B175C1E116D130B003C99CB /* OFApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFApplication.m; path = src/OFApplication.m; sourceTree = ""; }; 4B17FF70133A28FC003E6DCD /* OFException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFException.h; path = src/exceptions/OFException.h; sourceTree = ""; }; 4B17FF71133A28FC003E6DCD /* OFException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFException.m; path = src/exceptions/OFException.m; sourceTree = ""; }; 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFNotImplementedException.h; path = src/exceptions/OFNotImplementedException.h; sourceTree = ""; }; @@ -976,10 +980,12 @@ 4B6799881099E7C50041064A /* OFXMLElement.m */, 4BB25E86139C388A00F574EA /* OFXMLElement+Serialization.h */, 4BB25E87139C388A00F574EA /* OFXMLElement+Serialization.m */, 4B0D249411DFAA3D00ED6FFC /* OFXMLElementBuilder.h */, 4B0D249511DFAA3D00ED6FFC /* OFXMLElementBuilder.m */, + 4B11005A14329B9A003A45D8 /* OFXMLNode.h */, + 4B11005B14329B9A003A45D8 /* OFXMLNode.m */, 4B6799891099E7C50041064A /* OFXMLParser.h */, 4B67998A1099E7C50041064A /* OFXMLParser.m */, 4B6AF97310A8D4450003FB0A /* ObjFW.h */, 4B6799561099E7C50041064A /* asprintf.h */, 4B6AF96C10A8D3E40003FB0A /* asprintf.m */, @@ -1137,10 +1143,11 @@ 4B3D23DF1337FCB000DD29B8 /* OFURL.h in Headers */, 4B3D23E01337FCB000DD29B8 /* OFXMLAttribute.h in Headers */, 4B3D23E11337FCB000DD29B8 /* OFXMLElement.h in Headers */, 4BB25E8C139C388A00F574EA /* OFXMLElement+Serialization.h in Headers */, 4B3D23E21337FCB000DD29B8 /* OFXMLElementBuilder.h in Headers */, + 4B11005C14329B9A003A45D8 /* OFXMLNode.h in Headers */, 4B3D23E31337FCB000DD29B8 /* OFXMLParser.h in Headers */, 4B3D23E41337FCB000DD29B8 /* ObjFW.h in Headers */, 4B3D23E51337FCB000DD29B8 /* asprintf.h in Headers */, 4B3D23E61337FCB000DD29B8 /* atomic.h in Headers */, 4B3D23E71337FCB000DD29B8 /* base64.h in Headers */, @@ -1423,10 +1430,11 @@ 4B3D23AD1337FC0D00DD29B8 /* OFURL.m in Sources */, 4B3D23AE1337FC0D00DD29B8 /* OFXMLAttribute.m in Sources */, 4B3D23AF1337FC0D00DD29B8 /* OFXMLElement.m in Sources */, 4BB25E8D139C388A00F574EA /* OFXMLElement+Serialization.m in Sources */, 4B3D23B01337FC0D00DD29B8 /* OFXMLElementBuilder.m in Sources */, + 4B11005D14329B9A003A45D8 /* OFXMLNode.m in Sources */, 4B3D23B11337FC0D00DD29B8 /* OFXMLParser.m in Sources */, 4B3D23B31337FC0D00DD29B8 /* base64.m in Sources */, 4B3D23B41337FC0D00DD29B8 /* iso_8859_15.m in Sources */, 4B3D23B51337FC0D00DD29B8 /* foundation-compat.m in Sources */, 4B3D23EE1337FFD000DD29B8 /* of_asprintf.m in Sources */, Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -55,10 +55,11 @@ OFURL.m \ OFXMLAttribute.m \ OFXMLElement.m \ OFXMLElement+Serialization.m \ OFXMLElementBuilder.m \ + OFXMLNode.m \ OFXMLParser.m \ base64.m \ of_asprintf.m \ unicode.m Index: src/OFXMLAttribute.h ================================================================== --- src/OFXMLAttribute.h +++ src/OFXMLAttribute.h @@ -12,19 +12,18 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "OFObject.h" -#import "OFSerialization.h" +#import "OFXMLNode.h" @class OFString; /** * \brief A representation of an attribute of an XML element as an object. */ -@interface OFXMLAttribute: OFObject +@interface OFXMLAttribute: OFXMLNode { @public OFString *name; OFString *ns; OFString *stringValue; @@ -71,41 +70,6 @@ * \brief Returns the namespace of the attribute as an autoreleased OFString. * * \return The namespace of the attribute as an autoreleased OFString */ - (OFString*)namespace; - -/** - * \brief Returns the string value of the attribute as an autoreleased OFString. - * - * \return The string value of the attribute as an autoreleased OFString - */ -- (OFString*)stringValue; - -/** - * \brief Returns an integer with the decimal value of the attribute. - * - * \return An integer with the decimal value of the attribute - */ -- (intmax_t)decimalValue; - -/** - * \brief Returns an integer with the hexadecimal value of the attribute. - * - * \return An integer with the hexadecimal value of the attribute - */ -- (uintmax_t)hexadecimalValue; - -/** - * \brief Returns a float with the float value of the attribute. - * - * \return A float with the float value of the attribute - */ -- (float)floatValue; - -/** - * \brief Returns a double with the double value of the attribute. - * - * \return A double with the double value of the attribute - */ -- (double)doubleValue; @end Index: src/OFXMLAttribute.m ================================================================== --- src/OFXMLAttribute.m +++ src/OFXMLAttribute.m @@ -105,30 +105,10 @@ - (OFString*)stringValue { return [[stringValue copy] autorelease]; } -- (intmax_t)decimalValue -{ - return [stringValue decimalValue]; -} - -- (uintmax_t)hexadecimalValue -{ - return [stringValue hexadecimalValue]; -} - -- (float)floatValue -{ - return [stringValue floatValue]; -} - -- (double)doubleValue -{ - return [stringValue doubleValue]; -} - - (BOOL)isEqual: (id)object { OFXMLAttribute *otherAttribute; if (![object isKindOfClass: [OFXMLAttribute class]]) Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -12,24 +12,23 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "OFObject.h" -#import "OFSerialization.h" -#import "OFXMLAttribute.h" +#import "OFXMLNode.h" @class OFString; @class OFArray; @class OFMutableString; @class OFMutableArray; @class OFMutableDictionary; +@class OFXMLAttribute; /** * \brief A class which stores an XML element. */ -@interface OFXMLElement: OFObject +@interface OFXMLElement: OFXMLNode { OFString *name; OFString *ns; OFString *defaultNamespace; OFMutableArray *attributes; @@ -299,64 +298,10 @@ * * \param stringValue The new string value for the element */ - (void)setStringValue: (OFString*)stringValue; -/** - * \brief Returns a string with the string value of all children concatenated. - * - * \return A string with the string value of all children concatenated - */ -- (OFString*)stringValue; - -/** - * \brief Returns an integer with the decimal value of all children - * concatenated. - * - * \return An integer with the decimal value of all children concatenated - */ -- (intmax_t)decimalValue; - -/** - * \brief Returns an integer with the hexadecimal value of all children - * concatenated. - * - * \return An integer with the hexadecimal value of all children concatenated - */ -- (uintmax_t)hexadecimalValue; - -/** - * \brief Returns a float with the float value of all children concatenated. - * - * \return A float with the float value of all children concatenated - */ -- (float)floatValue; - -/** - * \brief Returns a double with the double value of all children concatenated. - * - * \return A double with the double value of all children concatenated - */ -- (double)doubleValue; - -/** - * \brief Returns an OFString representing the OFXMLElement as an XML string. - * - * \return An OFString representing the OFXMLElement as an XML string - */ -- (OFString*)XMLString; - -/** - * \brief Returns an OFString representing the OFXMLElement as an XML string - * with indentation. - * - * \param indentation The indentation for the XML string - * \return An OFString representing the OFXMLElement as an XML string with - * indentation - */ -- (OFString*)XMLStringWithIndentation: (unsigned int)indentation; - /** * \brief Adds the specified attribute. * * If an attribute with the same name and namespace already exists, it is not * added. Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -497,30 +497,10 @@ [pool release]; return ret; } -- (intmax_t)decimalValue -{ - return [[self stringValue] decimalValue]; -} - -- (uintmax_t)hexadecimalValue -{ - return [[self stringValue] hexadecimalValue]; -} - -- (float)floatValue -{ - return [[self stringValue] floatValue]; -} - -- (double)doubleValue -{ - return [[self stringValue] doubleValue]; -} - - (OFString*)_XMLStringWithParent: (OFXMLElement*)parent namespaces: (OFDictionary*)allNamespaces indentation: (unsigned int)indentation level: (size_t)level { @@ -800,15 +780,10 @@ namespaces: nil indentation: indentation level: 0]; } -- (OFString*)description -{ - return [self XMLStringWithIndentation: 2]; -} - - (OFXMLElement*)XMLElementBySerializing { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; ADDED src/OFXMLNode.h Index: src/OFXMLNode.h ================================================================== --- src/OFXMLNode.h +++ src/OFXMLNode.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFObject.h" +#import "OFSerialization.h" + +/** + * \brief A class which stores an XML element. + */ +@interface OFXMLNode: OFObject +/** + * \brief Returns the contents of the receiver as a string value. + * + * \return A string with the string value + */ +- (OFString*)stringValue; + +/** + * \brief Returns the contents of the receiver as a decimal value. + * + * \return An integer with the decimal value + */ +- (intmax_t)decimalValue; + +/** + * \brief Returns the contents of the receiver as a hexadecimal value. + * + * \return An integer with the hexadecimal value + */ +- (uintmax_t)hexadecimalValue; + +/** + * \brief Returns the contents of the receiver as a float value. + * + * \return A float with the float value + */ +- (float)floatValue; + +/** + * \brief Returns the contents of the receiver as a double value. + * + * \return A double with the double value + */ +- (double)doubleValue; + +/** + * \brief Returns an OFString representing the OFXMLNode as an XML string. + * + * \return An OFString representing the OFXMLNode as an XML string + */ +- (OFString*)XMLString; + +/** + * \brief Returns an OFString representing the OFXMLNode as an XML string with + * indentation. + * + * \param indentation The indentation for the XML string + * \return An OFString representing the OFXMLNode as an XML string with + * indentation + */ +- (OFString*)XMLStringWithIndentation: (unsigned int)indentation; +@end ADDED src/OFXMLNode.m Index: src/OFXMLNode.m ================================================================== --- src/OFXMLNode.m +++ src/OFXMLNode.m @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFXMLNode.h" + +#import "OFNotImplementedException.h" + +@implementation OFXMLNode +- initWithSerialization: (OFXMLElement*)element +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException exceptionWithClass: c + selector: _cmd]; +} + +- (OFString*)stringValue +{ + @throw [OFNotImplementedException exceptionWithClass: isa + selector: _cmd]; +} + +- (intmax_t)decimalValue +{ + return [[self stringValue] decimalValue]; +} + +- (uintmax_t)hexadecimalValue +{ + return [[self stringValue] hexadecimalValue]; +} + +- (float)floatValue +{ + return [[self stringValue] floatValue]; +} + +- (double)doubleValue +{ + return [[self stringValue] doubleValue]; +} + +- (OFString*)XMLString +{ + return [self XMLStringWithIndentation: 0]; +} + +- (OFString*)XMLStringWithIndentation: (unsigned int)indentation +{ + @throw [OFNotImplementedException exceptionWithClass: isa + selector: _cmd]; +} + +- (OFString*)description +{ + return [self XMLStringWithIndentation: 2]; +} + +- (OFXMLElement*)XMLElementBySerializing +{ + @throw [OFNotImplementedException exceptionWithClass: isa + selector: _cmd]; +} + +- copy +{ + @throw [OFNotImplementedException exceptionWithClass: isa + selector: _cmd]; +} +@end