Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -701,10 +701,18 @@ 4B3DE12A1F5F4F2F0090AA3E /* OFMutablePair.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3DE1241F5F4F2F0090AA3E /* OFMutablePair.m */; }; 4B3DE12B1F5F4F2F0090AA3E /* OFPair.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3DE1251F5F4F2F0090AA3E /* OFPair.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B3DE12C1F5F4F2F0090AA3E /* OFPair.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3DE1251F5F4F2F0090AA3E /* OFPair.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B3DE12D1F5F4F2F0090AA3E /* OFPair.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3DE1261F5F4F2F0090AA3E /* OFPair.m */; }; 4B3DE12E1F5F4F2F0090AA3E /* OFPair.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3DE1261F5F4F2F0090AA3E /* OFPair.m */; }; + 4B3DE1331F5F553E0090AA3E /* OFMutableTriple.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3DE12F1F5F553E0090AA3E /* OFMutableTriple.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B3DE1341F5F553E0090AA3E /* OFMutableTriple.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3DE12F1F5F553E0090AA3E /* OFMutableTriple.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B3DE1351F5F553E0090AA3E /* OFMutableTriple.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3DE1301F5F553E0090AA3E /* OFMutableTriple.m */; }; + 4B3DE1361F5F553E0090AA3E /* OFMutableTriple.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3DE1301F5F553E0090AA3E /* OFMutableTriple.m */; }; + 4B3DE1371F5F553E0090AA3E /* OFTriple.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3DE1311F5F553E0090AA3E /* OFTriple.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B3DE1381F5F553E0090AA3E /* OFTriple.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3DE1311F5F553E0090AA3E /* OFTriple.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B3DE1391F5F553E0090AA3E /* OFTriple.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3DE1321F5F553E0090AA3E /* OFTriple.m */; }; + 4B3DE13A1F5F553E0090AA3E /* OFTriple.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3DE1321F5F553E0090AA3E /* OFTriple.m */; }; 4B3ED7C21AF62C30004C8FF1 /* OFGetOptionFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3ED7C01AF62C30004C8FF1 /* OFGetOptionFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B3ED7C31AF62C30004C8FF1 /* OFGetOptionFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3ED7C11AF62C30004C8FF1 /* OFGetOptionFailedException.m */; }; 4B40EC1B189FE2650031E19E /* socket.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B40EC1A189FE2650031E19E /* socket.m */; }; 4B4116D01F21654200E78916 /* OFMutableURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B4116CD1F21654200E78916 /* OFMutableURL.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B4116D11F21654200E78916 /* OFMutableURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B4116CD1F21654200E78916 /* OFMutableURL.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -1338,10 +1346,14 @@ 4B3D5693139A617D0010A78F /* OFSerializationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSerializationTests.m; path = tests/OFSerializationTests.m; sourceTree = ""; }; 4B3DE1231F5F4F2F0090AA3E /* OFMutablePair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutablePair.h; path = src/OFMutablePair.h; sourceTree = ""; }; 4B3DE1241F5F4F2F0090AA3E /* OFMutablePair.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutablePair.m; path = src/OFMutablePair.m; sourceTree = ""; }; 4B3DE1251F5F4F2F0090AA3E /* OFPair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFPair.h; path = src/OFPair.h; sourceTree = ""; }; 4B3DE1261F5F4F2F0090AA3E /* OFPair.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFPair.m; path = src/OFPair.m; sourceTree = ""; }; + 4B3DE12F1F5F553E0090AA3E /* OFMutableTriple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutableTriple.h; path = src/OFMutableTriple.h; sourceTree = ""; }; + 4B3DE1301F5F553E0090AA3E /* OFMutableTriple.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutableTriple.m; path = src/OFMutableTriple.m; sourceTree = ""; }; + 4B3DE1311F5F553E0090AA3E /* OFTriple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFTriple.h; path = src/OFTriple.h; sourceTree = ""; }; + 4B3DE1321F5F553E0090AA3E /* OFTriple.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFTriple.m; path = src/OFTriple.m; sourceTree = ""; }; 4B3ED7C01AF62C30004C8FF1 /* OFGetOptionFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFGetOptionFailedException.h; path = src/exceptions/OFGetOptionFailedException.h; sourceTree = ""; }; 4B3ED7C11AF62C30004C8FF1 /* OFGetOptionFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFGetOptionFailedException.m; path = src/exceptions/OFGetOptionFailedException.m; sourceTree = ""; }; 4B40EC1A189FE2650031E19E /* socket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = socket.m; path = src/socket.m; sourceTree = ""; }; 4B4116CD1F21654200E78916 /* OFMutableURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutableURL.h; path = src/OFMutableURL.h; sourceTree = ""; }; 4B4116CE1F21654200E78916 /* OFMutableURL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutableURL.m; path = src/OFMutableURL.m; sourceTree = ""; }; @@ -2141,10 +2153,12 @@ 4B6799741099E7C50041064A /* OFMutableString.m */, 4B55254E147AA5DB0003BF47 /* OFMutableString_UTF8.h */, 4B55254F147AA5DB0003BF47 /* OFMutableString_UTF8.m */, 4BA842E41F35E53800292FC6 /* OFMutableTarArchiveEntry.h */, 4BA842E51F35E53800292FC6 /* OFMutableTarArchiveEntry.m */, + 4B3DE12F1F5F553E0090AA3E /* OFMutableTriple.h */, + 4B3DE1301F5F553E0090AA3E /* OFMutableTriple.m */, 4B4116CD1F21654200E78916 /* OFMutableURL.h */, 4B4116CE1F21654200E78916 /* OFMutableURL.m */, 4B92FDDC1F35DFAC000D541D /* OFMutableZIPArchiveEntry.h */, 4B92FDDD1F35DFAC000D541D /* OFMutableZIPArchiveEntry.m */, 4B6743FA163C395900EB1E59 /* OFMutex.h */, @@ -2246,10 +2260,12 @@ 4B9361A71511000C00DCD16B /* OFThreadPool.m */, 4B325EDB1605F3A0007836CA /* OFTimer.h */, 4B325EDC1605F3A0007836CA /* OFTimer.m */, 4B6C8AD617BD5C2E00B194F2 /* OFTimer+Private.h */, 4BA02BA015041F5900002F84 /* OFTLSSocket.h */, + 4B3DE1311F5F553E0090AA3E /* OFTriple.h */, + 4B3DE1321F5F553E0090AA3E /* OFTriple.m */, 4B7769EF1895ED0C00D12284 /* OFUDPSocket.h */, 4B7769F01895ED0C00D12284 /* OFUDPSocket.m */, 4B4A61F212DF5EA20048F3F2 /* OFURL.h */, 4B4A61F312DF5EA20048F3F2 /* OFURL.m */, 4B4116CF1F21654200E78916 /* OFURL+Private.h */, @@ -2510,10 +2526,11 @@ 4B2C22011DA292BE00735907 /* OFMutableDictionary.h in Headers */, 4B3DE1281F5F4F2F0090AA3E /* OFMutablePair.h in Headers */, 4B2C22021DA292BE00735907 /* OFMutableSet.h in Headers */, 4B2C22031DA292BE00735907 /* OFMutableString.h in Headers */, 4BA842E71F35E53800292FC6 /* OFMutableTarArchiveEntry.h in Headers */, + 4B3DE1341F5F553E0090AA3E /* OFMutableTriple.h in Headers */, 4B4116D11F21654200E78916 /* OFMutableURL.h in Headers */, 4B92FDE01F35DFB5000D541D /* OFMutableZIPArchiveEntry.h in Headers */, 4B2C22041DA292BE00735907 /* OFMutex.h in Headers */, 4B2C22051DA292BE00735907 /* OFNull.h in Headers */, 4B2C22061DA292BE00735907 /* OFNumber.h in Headers */, @@ -2555,10 +2572,11 @@ 4B2C22291DA292BE00735907 /* OFTCPSocket.h in Headers */, 4B2C222A1DA292BE00735907 /* OFThread.h in Headers */, 4B2C222B1DA292BE00735907 /* OFThreadPool.h in Headers */, 4B2C222C1DA292BE00735907 /* OFTimer.h in Headers */, 4B2C222D1DA292BE00735907 /* OFTLSSocket.h in Headers */, + 4B3DE1381F5F553E0090AA3E /* OFTriple.h in Headers */, 4B2C222E1DA292BE00735907 /* OFUDPSocket.h in Headers */, 4B2C222F1DA292BE00735907 /* OFURL.h in Headers */, 4B2C22301DA292BE00735907 /* OFXMLAttribute.h in Headers */, 4B2C22311DA292BE00735907 /* OFXMLCDATA.h in Headers */, 4B2C22321DA292BE00735907 /* OFXMLCharacters.h in Headers */, @@ -2741,10 +2759,11 @@ 4B3D23CE1337FCB000DD29B8 /* OFMutableDictionary.h in Headers */, 4B3DE1271F5F4F2F0090AA3E /* OFMutablePair.h in Headers */, 4B39844713D3AFB400E6F825 /* OFMutableSet.h in Headers */, 4B3D23CF1337FCB000DD29B8 /* OFMutableString.h in Headers */, 4BA842E61F35E53800292FC6 /* OFMutableTarArchiveEntry.h in Headers */, + 4B3DE1331F5F553E0090AA3E /* OFMutableTriple.h in Headers */, 4B4116D01F21654200E78916 /* OFMutableURL.h in Headers */, 4B92FDDF1F35DFB5000D541D /* OFMutableZIPArchiveEntry.h in Headers */, 4B674403163C395900EB1E59 /* OFMutex.h in Headers */, 4B511B7C139C0A34003764A5 /* OFNull.h in Headers */, 4B3D23D01337FCB000DD29B8 /* OFNumber.h in Headers */, @@ -2787,10 +2806,11 @@ 4B3D23DD1337FCB000DD29B8 /* OFTCPSocket.h in Headers */, 4B3D23DE1337FCB000DD29B8 /* OFThread.h in Headers */, 4B9361A81511000C00DCD16B /* OFThreadPool.h in Headers */, 4B325EDF1605F3A0007836CA /* OFTimer.h in Headers */, 4BA02BA215041F5900002F84 /* OFTLSSocket.h in Headers */, + 4B3DE1371F5F553E0090AA3E /* OFTriple.h in Headers */, 4B7769F11895ED0C00D12284 /* OFUDPSocket.h in Headers */, 4B3D23DF1337FCB000DD29B8 /* OFURL.h in Headers */, 4B3D23E01337FCB000DD29B8 /* OFXMLAttribute.h in Headers */, 4B49EA6D143B3A090005BBC6 /* OFXMLCDATA.h in Headers */, 4B49EA6F143B3A090005BBC6 /* OFXMLCharacters.h in Headers */, @@ -3309,10 +3329,11 @@ 4B2C214C1DA292BE00735907 /* OFMutableSet.m in Sources */, 4B2C214D1DA292BE00735907 /* OFMutableSet_hashtable.m in Sources */, 4B2C214E1DA292BE00735907 /* OFMutableString.m in Sources */, 4B2C214F1DA292BE00735907 /* OFMutableString_UTF8.m in Sources */, 4BA842E91F35E53800292FC6 /* OFMutableTarArchiveEntry.m in Sources */, + 4B3DE1361F5F553E0090AA3E /* OFMutableTriple.m in Sources */, 4B4116D31F21654200E78916 /* OFMutableURL.m in Sources */, 4B92FDE21F35DFBC000D541D /* OFMutableZIPArchiveEntry.m in Sources */, 4B2C21501DA292BE00735907 /* OFMutex.m in Sources */, 4B2C21511DA292BE00735907 /* OFNull.m in Sources */, 4B2C21521DA292BE00735907 /* OFNumber.m in Sources */, @@ -3355,10 +3376,11 @@ 4B2C21761DA292BE00735907 /* OFTCPSocket.m in Sources */, 4B2C21771DA292BE00735907 /* OFTCPSocket+SOCKS5.m in Sources */, 4B2C21781DA292BE00735907 /* OFThread.m in Sources */, 4B2C21791DA292BE00735907 /* OFThreadPool.m in Sources */, 4B2C217A1DA292BE00735907 /* OFTimer.m in Sources */, + 4B3DE13A1F5F553E0090AA3E /* OFTriple.m in Sources */, 4B2C217B1DA292BE00735907 /* OFUDPSocket.m in Sources */, 4B2C217C1DA292BE00735907 /* OFURL.m in Sources */, 4B2C217D1DA292BE00735907 /* OFXMLAttribute.m in Sources */, 4B2C217E1DA292BE00735907 /* OFXMLCDATA.m in Sources */, 4B2C217F1DA292BE00735907 /* OFXMLCharacters.m in Sources */, @@ -3513,10 +3535,11 @@ 4B39844813D3AFB400E6F825 /* OFMutableSet.m in Sources */, 4BA85BCD140ECCE800E91D51 /* OFMutableSet_hashtable.m in Sources */, 4B3D239D1337FC0D00DD29B8 /* OFMutableString.m in Sources */, 4B552553147AA5DB0003BF47 /* OFMutableString_UTF8.m in Sources */, 4BA842E81F35E53800292FC6 /* OFMutableTarArchiveEntry.m in Sources */, + 4B3DE1351F5F553E0090AA3E /* OFMutableTriple.m in Sources */, 4B4116D21F21654200E78916 /* OFMutableURL.m in Sources */, 4B92FDE11F35DFBB000D541D /* OFMutableZIPArchiveEntry.m in Sources */, 4B674404163C395900EB1E59 /* OFMutex.m in Sources */, 4B511B7D139C0A34003764A5 /* OFNull.m in Sources */, 4B3D239E1337FC0D00DD29B8 /* OFNumber.m in Sources */, @@ -3560,10 +3583,11 @@ 4B3D23AB1337FC0D00DD29B8 /* OFTCPSocket.m in Sources */, 4BD653C6143B8489006182F0 /* OFTCPSocket+SOCKS5.m in Sources */, 4B3D23AC1337FC0D00DD29B8 /* OFThread.m in Sources */, 4B9361A91511000C00DCD16B /* OFThreadPool.m in Sources */, 4B325EE01605F3A0007836CA /* OFTimer.m in Sources */, + 4B3DE1391F5F553E0090AA3E /* OFTriple.m in Sources */, 4B7769F21895ED0C00D12284 /* OFUDPSocket.m in Sources */, 4B3D23AD1337FC0D00DD29B8 /* OFURL.m in Sources */, 4B3D23AE1337FC0D00DD29B8 /* OFXMLAttribute.m in Sources */, 4B49EA6E143B3A090005BBC6 /* OFXMLCDATA.m in Sources */, 4B49EA70143B3A090005BBC6 /* OFXMLCharacters.m in Sources */, Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -40,10 +40,11 @@ OFMutableDictionary.m \ OFMutablePair.m \ OFMutableSet.m \ OFMutableString.m \ OFMutableTarArchiveEntry.m \ + OFMutableTriple.m \ OFMutableURL.m \ OFMutableZIPArchiveEntry.m \ OFNull.m \ OFNumber.m \ OFObject.m \ @@ -78,10 +79,11 @@ OFSystemInfo.m \ OFTarArchive.m \ OFTarArchiveEntry.m \ OFThread.m \ OFTimer.m \ + OFTriple.m \ OFURL.m \ OFXMLAttribute.m \ OFXMLCDATA.m \ OFXMLCharacters.m \ OFXMLComment.m \ ADDED src/OFMutableTriple.h Index: src/OFMutableTriple.h ================================================================== --- src/OFMutableTriple.h +++ src/OFMutableTriple.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 + * 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 "OFTriple.h" + +OF_ASSUME_NONNULL_BEGIN + +/*! + * @class OFMutableTriple OFMutableTriple.h ObjFW/OFMutableTriple.h + * + * @brief A class for storing a triple of three objects. + */ +@interface OFMutableTriple OF_GENERIC(FirstType, SecondType, ThirdType): + OFTriple OF_GENERIC(FirstType, SecondType, ThirdType) +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# define FirstType id +# define SecondType id +# define ThirdType id +#endif +/*! + * The first object of the triple. + */ +@property (readwrite, nonatomic, retain) FirstType firstObject; + +/*! + * The second object of the triple. + */ +@property (readwrite, nonatomic, retain) SecondType secondObject; + +/*! + * The third object of the triple. + */ +@property (readwrite, nonatomic, retain) ThirdType thirdObject; + +/*! + * @brief Converts the mutable triple to an immutable triple. + */ +- (void)makeImmutable; +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef FirstType +# undef SecondType +# undef ThirdType +#endif +@end + +OF_ASSUME_NONNULL_END ADDED src/OFMutableTriple.m Index: src/OFMutableTriple.m ================================================================== --- src/OFMutableTriple.m +++ src/OFMutableTriple.m @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 + * 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 "OFMutableTriple.h" + +@implementation OFMutableTriple +@dynamic firstObject, secondObject, thirdObject; + +- (void)setFirstObject: (id)firstObject +{ + id old = _firstObject; + _firstObject = [firstObject retain]; + [old release]; +} + +- (void)setSecondObject: (id)secondObject +{ + id old = _secondObject; + _secondObject = [secondObject retain]; + [old release]; +} + +- (void)setThirdObject: (id)thirdObject +{ + id old = _thirdObject; + _thirdObject = [thirdObject retain]; + [old release]; +} + +- copy +{ + OFMutableTriple *copy = [self mutableCopy]; + + [copy makeImmutable]; + + return copy; +} + +- (void)makeImmutable +{ + object_setClass(self, [OFTriple class]); +} +@end ADDED src/OFTriple.h Index: src/OFTriple.h ================================================================== --- src/OFTriple.h +++ src/OFTriple.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 + * 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" + +OF_ASSUME_NONNULL_BEGIN + +/*! + * @class OFTriple OFTriple.h ObjFW/OFTriple.h + * + * @brief A class for storing a triple of three objects. + */ +@interface OFTriple OF_GENERIC(FirstType, SecondType, ThirdType): + OFObject +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# define FirstType id +# define SecondType id +# define ThirdType id +#endif +{ + FirstType _firstObject; + SecondType _secondObject; + ThirdType _thirdObject; +} + +/*! + * The first object of the triple. + */ +@property (readonly, nonatomic, retain) FirstType firstObject; + +/*! + * The second object of the triple. + */ +@property (readonly, nonatomic, retain) SecondType secondObject; + +/*! + * The third object of the triple. + */ +@property (readonly, nonatomic, retain) ThirdType thirdObject; + +/*! + * @brief Creates a new OFTriple with the specified objects. + * + * @param firstObject The first object for the triple + * @param secondObject The second object for the triple + * @param thirdObject The second object for the triple + * @return A new, autoreleased OFTriple + */ ++ (instancetype)tripleWithFirstObject: (FirstType)firstObject + secondObject: (SecondType)secondObject + thirdObject: (ThirdType)thirdObject; + +/*! + * @brief Initializes an already allocated OFTriple with the specified objects. + * + * @param firstObject The first object for the triple + * @param secondObject The second object for the triple + * @param thirdObject The second object for the triple + * @return An initialized OFTriple + */ +- initWithFirstObject: (FirstType)firstObject + secondObject: (SecondType)secondObject + thirdObject: (ThirdType)thirdObject; +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef FirstType +# undef SecondType +# undef ThirdType +#endif +@end + +OF_ASSUME_NONNULL_END + +#import "OFMutableTriple.h" ADDED src/OFTriple.m Index: src/OFTriple.m ================================================================== --- src/OFTriple.m +++ src/OFTriple.m @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 + * 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 "OFTriple.h" +#import "OFString.h" + +@implementation OFTriple ++ (instancetype)tripleWithFirstObject: (id)firstObject + secondObject: (id)secondObject + thirdObject: (id)thirdObject +{ + return [[[self alloc] initWithFirstObject: firstObject + secondObject: secondObject + thirdObject: thirdObject] autorelease]; +} + +- initWithFirstObject: (id)firstObject + secondObject: (id)secondObject + thirdObject: (id)thirdObject +{ + self = [super init]; + + @try { + _firstObject = [firstObject retain]; + _secondObject = [secondObject retain]; + _thirdObject = [thirdObject retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_firstObject release]; + [_secondObject release]; + [_thirdObject release]; + + [super dealloc]; +} + +- (id)firstObject +{ + return _firstObject; +} + +- (id)secondObject +{ + return _secondObject; +} + +- (id)thirdObject +{ + return _thirdObject; +} + +- (bool)isEqual: (id)object +{ + OFTriple *triple; + + if (![object isKindOfClass: [OFTriple class]]) + return false; + + triple = object; + + if (![triple->_firstObject isEqual: _firstObject]) + return false; + + if (![triple->_secondObject isEqual: _secondObject]) + return false; + + if (![triple->_thirdObject isEqual: _thirdObject]) + return false; + + return true; +} + +- (uint32_t)hash +{ + uint32_t hash; + + OF_HASH_INIT(hash); + + OF_HASH_ADD_HASH(hash, [_firstObject hash]); + OF_HASH_ADD_HASH(hash, [_secondObject hash]); + OF_HASH_ADD_HASH(hash, [_thirdObject hash]); + + OF_HASH_FINALIZE(hash); + + return hash; +} + +- copy +{ + return [self retain]; +} + +- mutableCopy +{ + return [OFMutableTriple tripleWithFirstObject: _firstObject + secondObject: _secondObject + thirdObject: _thirdObject]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: @"<<%@, %@, %@>>", + _firstObject, _secondObject, + _thirdObject]; +} +@end