mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-12 00:51:08 +00:00
Add initialization and change comment to reflect name.
This commit is contained in:
parent
41f827fae1
commit
c7d01e0348
2 changed files with 54 additions and 6 deletions
|
@ -35,7 +35,13 @@ extern "C" {
|
||||||
|
|
||||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST)
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST)
|
||||||
|
|
||||||
|
@class NSUnit;
|
||||||
|
|
||||||
@interface NSMeasurement : NSObject <NSCopying, NSCoding>
|
@interface NSMeasurement : NSObject <NSCopying, NSCoding>
|
||||||
|
{
|
||||||
|
NSUnit *_unit;
|
||||||
|
double _doubleValue;
|
||||||
|
}
|
||||||
|
|
||||||
// Creating Measurements
|
// Creating Measurements
|
||||||
- (instancetype)initWithDoubleValue: (double)doubleValue
|
- (instancetype)initWithDoubleValue: (double)doubleValue
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/* Implementation of class NSMeasurement
|
/* Implementation of class NSMeasurement
|
||||||
Copyright (C) 2019 Free Software Foundation, Inc.
|
Copyright (C) 2019 Free Software Foundation, Inc.
|
||||||
|
|
||||||
By: heron
|
By: Gregory John Casamento <greg.casamento@gmail.com>
|
||||||
Date: Mon Sep 30 15:58:21 EDT 2019
|
Date: Mon Sep 30 15:58:21 EDT 2019
|
||||||
|
|
||||||
This file is part of the GNUstep Library.
|
This file is part of the GNUstep Library.
|
||||||
|
@ -24,34 +24,59 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Foundation/NSMeasurement.h>
|
#include <Foundation/NSMeasurement.h>
|
||||||
|
#include <Foundation/NSUnit.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
|
|
||||||
@implementation NSMeasurement
|
@implementation NSMeasurement
|
||||||
// Creating Measurements
|
// Creating Measurements
|
||||||
- (instancetype)initWithDoubleValue: (double)doubleValue
|
- (instancetype)initWithDoubleValue: (double)doubleValue
|
||||||
unit: (NSUnit *)unit
|
unit: (NSUnit *)unit
|
||||||
{
|
{
|
||||||
return nil;
|
self = [super init];
|
||||||
|
if(self != nil)
|
||||||
|
{
|
||||||
|
ASSIGNCOPY(_unit, unit);
|
||||||
|
_doubleValue = doubleValue;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
RELEASE(_unit);
|
||||||
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessing unit and value
|
// Accessing unit and value
|
||||||
- (NSUnit *) unit
|
- (NSUnit *) unit
|
||||||
{
|
{
|
||||||
return nil;
|
return _unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double) doubleValue
|
- (double) doubleValue
|
||||||
{
|
{
|
||||||
|
return _doubleValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conversion
|
// Conversion
|
||||||
- (BOOL) canBeConvertedToUnit: (NSUnit *)unit
|
- (BOOL) canBeConvertedToUnit: (NSUnit *)unit
|
||||||
{
|
{
|
||||||
return NO;
|
return [unit isKindOfClass: [_unit class]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMeasurement *)measurementByConvertingToUnit:(NSUnit *)unit
|
- (NSMeasurement *)measurementByConvertingToUnit:(NSUnit *)unit
|
||||||
{
|
{
|
||||||
return nil;
|
NSMeasurement *result = nil;
|
||||||
|
if([self canBeConvertedToUnit: unit])
|
||||||
|
{
|
||||||
|
// Do conversion...
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[NSException raise: NSInvalidArgumentException
|
||||||
|
format: @"Cannot convert from %@ to %@", _unit, unit];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operating
|
// Operating
|
||||||
|
@ -64,5 +89,22 @@
|
||||||
{
|
{
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NSCopying
|
||||||
|
- (id) copyWithZone: (NSZone *)zone
|
||||||
|
{
|
||||||
|
return [[[self class] allocWithZone: zone] initWithDoubleValue: _doubleValue
|
||||||
|
unit: _unit];
|
||||||
|
}
|
||||||
|
|
||||||
|
// NSCoding
|
||||||
|
- (void) encodeWithCoder: (NSCoder *)coder
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initWithCoder: (NSCoder *)coder
|
||||||
|
{
|
||||||
|
return self;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue