Re: Accessor method for array of floats
Re: Accessor method for array of floats
- Subject: Re: Accessor method for array of floats
- From: Johan Kool <email@hidden>
- Date: Tue, 22 Jul 2003 00:15:57 +0200
I am very grateful to the help I got so far, but I am still a little
stuck on my problem. I get this error "JKDataModel.m:63: error:
incompatible types in assignment" for the line where I say "time =
inArray;". I've tried every combination with asterisks and ampersands I
could think of, but I must say I don't completely get what the problem
is.
What am I doing wrong?
Johan
Here are the relevant snippets of my code:
JKDataModel.m contains:
// -------------------
@class JKMainDocument;
@interface JKDataModel : NSObject {
@private
int count;
float *time[1];
// -------------------
JKDataModel.h contains:
// -------------------
-(int)count {
return count;
}
-(void)setTime:(float *)inArray withCount:(int)inValue {
count = inValue;
realloc(&time, count*sizeof(float));
time = inArray;
}
-(float *)time {
return *time;
}
// -------------------
JKMainWindowController.m contains:
// -------------------
- (void)getData
{
float x[1];
int num_pts;
realloc(&x, num_pts*sizeof(float));
// code assigning values to x[]
[[[self document] dataModel] setTime:x withCount:num_pts];
// -------------------
JKSomeOtherModel.m contains:
// -------------------
-(void)someFunction {
float *x[1];
int maxScan;
maxScan = [[[self document] dataModel] count];
realloc(&x, maxScan*sizeof(float));
x = [[[self document] dataModel] time];
// -------------------
On zondag, jul 20, 2003, at 02:48 Europe/Amsterdam,
email@hidden wrote:
Message: 8
Date: Sat, 19 Jul 2003 23:28:00 +0200
Subject: Re: Accessor method for array of floats
Cc: email@hidden
To: jim kitchen <email@hidden>, Dylan Adams <email@hidden>
From: Johan Kool <email@hidden>
Thanks Dylan and Jim for your replies.
The type of array I was looking for to store in my accessor is a plain
C array of floats.
If I understand you and this matter correctly, this is what I need to
put in my model:
-(void)setArrayOfFloats:(float)inArray withCount:(int)intValue {
numberOfPoints = intValue;
arrayOfFloats = realloc([intValue*sizeof(float));
arrayOfFloats = inArray;
}
-(float)arrayOfFloats {
return arrayOfFloats;
}
-(int)numberOfPoints {
return numberOfPoints;
}
and in the init of this model:
arrayOfFloats = malloc(1*sizeof(float)) // just so I can use realloc()
all the other times
Then when I want to store the data in my models accessors I call:
[myModel setArrayOfFloats:myArray withCount:count];
and to get it back I call:
float *localArray;
localArray = malloc([myModel numberOfPoints]*sizeof(float))
localArray = [myModel arrayOfFloats];
NSLog(@"LocalArray value at index 0: %e", localArray[0]);
I do indeed want my entire array back and not asking for it from my
model for each value separately, as I need to do quite some
calculations on it and localArray[n] is much easier to use and read
then [[myModel arrayOfFloats] objectAtIndex:n]; is. I likely need all
values anyway.
Thanks for the sample code for the NSMutableArray and NSTableView as
well, I needed some help on that too, how did you know!? ;-)
Johan
PS All typed in Mail (I don't have access to PB right now) so there
might be some typos here.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.