[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
integer wrappers for Swarm Maps: did I miss something?
From: |
Paul Johnson |
Subject: |
integer wrappers for Swarm Maps: did I miss something? |
Date: |
Wed, 15 Sep 1999 11:39:08 -0500 |
Ok, so I'm writing more swarm user guide and I come to Maps. It seems
to me that if you use an Integer wrapper class to put things into a Map,
you also need to maintain an Array of the Integer objects so you can
retrieve things from the Map when you want them. Not so?
Here is the example code:
An Integer wrapper class (ripped off from Marcus's test program
comparing Set and List):
//Integer.h
#import <defobj/Create.h>
@interface Integer: CreateDrop
{
int value;
member_t link;
}
- setValue: (int)value;
- (int)getValue;
@end
//Integer.m
@implementation Integer
- setValue: (int)theValue
{
value = theValue;
return self;
}
- (int)getValue
{
return value;
}
@end
And suppose we use that class to wrap integers, as in this code snippet:
#include Integer.h
#include Preference
//Suppose this is in the middle of a buildObjects method ...
id <Array> arrayOfIntegers;
id <Map> mapOfPreferences;
//This will contain the integer wrapper objects
arrayOfIntegers=[Array create: [self getZone] setCount: 50];
for(i=0; i < 50; i++)
{
id aPreference;
aPreference = [Preference createBegin: [self getZone]];
aPreference = [aPreference createEnd];
anInteger = [[Integer createBegin: [self getZone] setValue: i]
createEnd];
[arrayOfIntegers atOffset: i put: anInteger];
[mapOfPreferences at: anInteger insert: aPreference];
}
// When you want the item from the map with integer value 15, you have
to do:
anInteger = [arrayOfIntegers atOffset: 15];
objectYouWanted = [mapOfPreferences at: anInteger];
Is there a simpler way to do this?
--
Paul E. Johnson email: address@hidden
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
- integer wrappers for Swarm Maps: did I miss something?,
Paul Johnson <=