Overview
Comment: | OFValue: Add -[description] |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
854435fa915ee06bebc8e2cc3c325109 |
User & Date: | js on 2018-01-21 03:12:25 |
Other Links: | manifest | tags |
Context
2018-01-21
| ||
03:28 | OFValue: Add support for ranges check-in: cb1891cca1 user: js tags: trunk | |
03:12 | OFValue: Add -[description] check-in: 854435fa91 user: js tags: trunk | |
03:02 | OFValue: Conform to OFCopying check-in: 6ca5d172b9 user: js tags: trunk | |
Changes
Modified src/OFValue.m from [939e955648] to [4262daaa9f].
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 | * 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 "OFValue.h" #import "OFValue_bytes.h" #import "OFValue_nonretainedObject.h" #import "OFValue_pointer.h" | > > < | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * 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 "OFValue.h" #import "OFMethodSignature.h" #import "OFString.h" #import "OFValue_bytes.h" #import "OFValue_nonretainedObject.h" #import "OFValue_pointer.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" static struct { Class isa; } placeholder; |
︙ | ︙ | |||
99 100 101 102 103 104 105 | OF_INVALID_INIT_METHOD } - (bool)isEqual: (id)object { const char *objCType; size_t size; | | | | > | > | | | | | < | | | < | > | | < | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | OF_INVALID_INIT_METHOD } - (bool)isEqual: (id)object { const char *objCType; size_t size; void *value, *otherValue; if (![object isKindOfClass: [OFValue class]]) return false; objCType = [self objCType]; if (strcmp([object objCType], objCType) != 0) return false; size = of_sizeof_type_encoding(objCType); if ((value = malloc(size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; if ((otherValue = malloc(size)) == NULL) { free(value); @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; } @try { [self getValue: value size: size]; [object getValue: otherValue size: size]; return (memcmp(value, otherValue, size) == 0); } @finally { free(value); free(otherValue); } } - (uint32_t)hash { size_t size = of_sizeof_type_encoding([self objCType]); unsigned char *value; uint32_t hash; if ((value = malloc(size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; @try { [self getValue: value size: size]; OF_HASH_INIT(hash); for (size_t i = 0; i < size; i++) OF_HASH_ADD(hash, value[i]); OF_HASH_FINALIZE(hash); } @finally { free(value); } return hash; } - (id)copy { |
︙ | ︙ | |||
196 197 198 199 200 201 202 203 | id ret; [self getValue: &ret size: sizeof(ret)]; return ret; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | id ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFString *)description { OFMutableString *ret = [OFMutableString stringWithString: @"<OFValue: "]; size_t size = of_sizeof_type_encoding([self objCType]); unsigned char *value; if ((value = malloc(size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; @try { [self getValue: value size: size]; for (size_t i = 0; i < size; i++) { if (i > 0) [ret appendString: @" "]; [ret appendFormat: @"%02x", value[i]]; } } @finally { free(value); } [ret appendString: @">"]; [ret makeImmutable]; return ret; } @end |