Index: src/OFValue.h ================================================================== --- src/OFValue.h +++ src/OFValue.h @@ -62,16 +62,30 @@ * @throw OFOutOfRangeException The value is not OFSize-sized */ @property (readonly, nonatomic) OFSize sizeValue; /** - * @brief The value as a OFRect. + * @brief The value as an OFRect. * * @throw OFOutOfRangeException The value is not OFRect-sized */ @property (readonly, nonatomic) OFRect rectValue; +/** + * @brief The value as an OFVector3D. + * + * @throw OFOutOfRangeException The value is not OFVector3D-sized + */ +@property (readonly, nonatomic) OFVector3D vector3DValue; + +/** + * @brief The value as an OFVector4D. + * + * @throw OFOutOfRangeException The value is not OFVector4D-sized + */ +@property (readonly, nonatomic) OFVector4D vector4DValue; + /** * @brief Creates a new, autorelease OFValue with the specified bytes of the * specified type. * * @param bytes The bytes containing the value @@ -134,10 +148,28 @@ * @param rect The rectangle the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithRect: (OFRect)rect; +/** + * @brief Creates a new, autoreleased OFValue containing the specified + * 3D vector. + * + * @param vector3D The 3D vector the OFValue should contain + * @return A new, autoreleased OFValue + */ ++ (instancetype)valueWithVector3D: (OFVector3D)vector3D; + +/** + * @brief Creates a new, autoreleased OFValue containing the specified + * 4D vector. + * + * @param vector4D The 4D vector the OFValue should contain + * @return A new, autoreleased OFValue + */ ++ (instancetype)valueWithVector4D: (OFVector4D)vector4D; + /** * @brief Initializes an already allocated OFValue with the specified bytes of * the specified type. * * @param bytes The bytes containing the value Index: src/OFValue.m ================================================================== --- src/OFValue.m +++ src/OFValue.m @@ -105,10 +105,24 @@ + (instancetype)valueWithRect: (OFRect)rect { return [[[OFValue alloc] initWithBytes: &rect objCType: @encode(OFRect)] autorelease]; } + ++ (instancetype)valueWithVector3D: (OFVector3D)vector3D +{ + return [[[OFValue alloc] + initWithBytes: &vector3D + objCType: @encode(OFVector3D)] autorelease]; +} + ++ (instancetype)valueWithVector4D: (OFVector4D)vector4D +{ + return [[[OFValue alloc] + initWithBytes: &vector4D + objCType: @encode(OFVector4D)] autorelease]; +} - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { if ([self isMemberOfClass: [OFValue class]]) { @@ -247,10 +261,24 @@ { OFRect ret; [self getValue: &ret size: sizeof(ret)]; return ret; } + +- (OFVector3D)vector3DValue +{ + OFVector3D ret; + [self getValue: &ret size: sizeof(ret)]; + return ret; +} + +- (OFVector4D)vector4DValue +{ + OFVector4D ret; + [self getValue: &ret size: sizeof(ret)]; + return ret; +} - (OFString *)description { const char *objCType = self.objCType; OFMutableString *ret; @@ -284,10 +312,25 @@ [self getValue: &rectValue size: sizeof(rectValue)]; return [OFString stringWithFormat: @"", rectValue.origin.x, rectValue.origin.y, rectValue.size.width, rectValue.size.height]; + } else if (strcmp(objCType, @encode(OFVector3D)) == 0 || + strcmp(objCType, @encode(const OFVector3D)) == 0) { + OFVector3D vector3DValue; + [self getValue: &vector3DValue size: sizeof(vector3DValue)]; + return [OFString stringWithFormat: + @"", + vector3DValue.x, vector3DValue.y, vector3DValue.z]; + } else if (strcmp(objCType, @encode(OFVector4D)) == 0 || + strcmp(objCType, @encode(const OFVector4D)) == 0) { + OFVector4D vector4DValue; + [self getValue: &vector4DValue size: sizeof(vector4DValue)]; + return [OFString stringWithFormat: + @"", + vector4DValue.x, vector4DValue.y, vector4DValue.z, + vector4DValue.w]; } ret = [OFMutableString stringWithString: @"