Rewrite C++ code into Objective C - iphone

I got some C++ Sourcecode that I would like to rewrite into Objective C.
It would help me alot if someone could write me a header file for this Code. When I get the Headerfile I would be able to rewrite the rest of the Sourcecode.
It would be very nice if someone could help me please.
Thanks
I will poste the sourcecode here:
#include <stdlib.h>
#include <iostream.h>
#define STATES 5
int transitionTable[STATES][STATES];
// function declarations:
double randfloat (void);
int chooseNextEventFromTable (int current, int table[STATES][STATES]);
int chooseNextEventFromTransitionTablee (int currentState);
void setTable (int value, int table[STATES][STATES]);
//////////////////////////////////////////////////////////////////////////
int main(void) {
int i;
// for demo purposes:
transitionTable[0][0] = 0;
transitionTable[0][1] = 20;
transitionTable[0][2] = 30;
transitionTable[0][3] = 50;
transitionTable[0][4] = 0;
transitionTable[1][0] = 35;
transitionTable[1][1] = 25;
transitionTable[1][2] = 20;
transitionTable[1][3] = 30;
transitionTable[1][4] = 0;
transitionTable[2][0] = 70;
transitionTable[2][1] = 0;
transitionTable[2][2] = 15;
transitionTable[2][3] = 0;
transitionTable[2][4] = 15;
transitionTable[3][0] = 0;
transitionTable[3][1] = 25;
transitionTable[3][2] = 25;
transitionTable[3][3] = 0;
transitionTable[3][4] = 50;
transitionTable[4][0] = 13;
transitionTable[4][1] = 17;
transitionTable[4][2] = 22;
transitionTable[4][3] = 48;
transitionTable[4][4] = 0;
int currentState = 0;
for (i=0; i<10; i++) {
std::cout << currentState << " ";
currentState = chooseNextEventFromTransitionTablee(currentState);
}
return 0;
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////
//
// chooseNextEventFromTransitionTable -- choose the next note.
//
int chooseNextEventFromTransitionTablee(int currentState) {
int targetSum = 0;
int sum = 0;
int targetNote = 0;
int totalevents = 0;
int i;
currentState = currentState % STATES; // remove any octave value
for (i=0; i<STATES; i++) {
totalevents += transitionTable[currentState][i];
}
targetSum = (int)(randfloat() * totalevents + 0.5);
while (targetNote < STATES &&
sum+transitionTable[currentState][targetNote] < targetSum) {
sum += transitionTable[currentState][targetNote];
targetNote++;
}
return targetNote;
}
//////////////////////////////
//
// randfloat -- returns a random number between 0.0 and 1.0.
//
double randfloat(void) {
return (double)rand()/RAND_MAX;
}
//////////////////////////////
//
// setTable -- set all values in the transition table to the given value.
//
void setTable(int value, int table[STATES][STATES]) {
int i, j;
for (i=0; i<STATES; i++) {
for (j=0; j<STATES; j++) {
table[i][j] = value;
}
}
}
Update
I'm not only compiling the header file there is another file i'm compiling too
SourceCode:
//
// markovThreadsChainsViewController.m
// markovThreadsChains
//
// Created by Philippe Mokrzycki on 15.01.11.
// Copyright 2011 TGM. All rights reserved.
//
#import "markovThreadsChainsViewController.h"
#import "markov.h"
//#import "markovChainOC.h"
#implementation markovThreadsChainsViewController
#synthesize mcValueLabel, threadStartGenerateButton, threadStopGenerateButton;
- (IBAction) startThreadGen:(UIButton *)sender{
threadStopGenerateButton.hidden=NO;
threadStartGenerateButton.hidden=YES;
mcValueLabel.text = #"0";
currentState=0;
// markovChainOC *mCobc = [[markovChainOC alloc]init];
// [mCobc setCurrentState:0];
[NSThread detachNewThreadSelector:#selector(startThreading) toTarget:self withObject:nil];
}
- (IBAction) stopThreadGen:(UIButton *)sender{
threadStopGenerateButton.hidden=YES;
threadStartGenerateButton.hidden=NO;
[NSThread detachNewThreadSelector:#selector(stopThreading) toTarget:self withObject:nil];
}
- (void) startThreading {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[NSThread sleepForTimeInterval:3];
[self performSelectorOnMainThread:#selector(markovGen) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void) stopThreading {
[NSThread cancelPreviousPerformRequestsWithTarget:self];
}
- (void)markovGen{
transitionTable[0][0] = 25;
transitionTable[0][1] = 25;
transitionTable[1][0] = 25;
transitionTable[1][1] = 25;
// int actualValue = [mCobc getCurrentState];
int actualValue = currentState;
mcValueLabel.text = [NSString stringWithFormat:#"%", actualValue];
currentState = chooseNextEventFromTransitionTablee(currentState);
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(markovGen) userInfo:nil repeats:NO];
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[mcValueLabel release];
[threadStartGenerateButton release];
[threadStopGenerateButton release];
// [mCobc release];
[super dealloc];
}
#end

This code has nothing object-oriented in it at all. Just change iostream.h to stdio.h, and cout to printf. Then it's a regular C program.

Just put these lines into a header file, and you should be able to include the header and call the functions from any other Objective-C or C source file.
(To support C++ also, you may need to put extern "C" { ... } around them, unless you are compiling everything as C++ or Objective-C++.)
#pragma once
#define STATES 5
int transitionTable[STATES][STATES];
// function declarations:
double randfloat (void);
int chooseNextEventFromTable (int current, int table[STATES][STATES]);
int chooseNextEventFromTransitionTablee (int currentState);
void setTable (int value, int table[STATES][STATES]);
More detail:
To use these functions from another class, you'll need the following files in your project:
markov.h (or whatever you decide to call it), containing the lines above.
markov.c (or whatever you decide to call it), containing the other stuff from your original source file, except for the main function, which you should remove
Then, your other files that use the functions should have an #include "markov.h" line, and then you should be able to call them.
If you are getting linker errors about missing functions, it means that you are not compiling markov.c as part of the project, or there are some options that are causing the function names to not match properly.

Related

Segmented Controllers

Trying to set an int value using a Segmented Controller. I've seen several tuts on how to change labels, but I need to set an int value.
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
#synthesize caseCost;
#synthesize dilution;
#synthesize returnMsg;
#synthesize opcValue;
//synthesize opc; < -- Tried
//int opc; <--- tried
- (IBAction)opcView:(id)sender {
if (opcValue.selectedSegmentIndex == 0) {
int opc = 320;
}
if (opcValue.selectedSegmentIndex == 1) {
int opc = 128;
}
if (opcValue.selectedSegmentIndex == 2) {
int opc = 135;
}
if (opcValue.selectedSegmentIndex == 3) {
int opc = 88;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//int opc; <--- tried
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)finishBtn:(id)sender {
//int opc = 320;
float case_cost = ([caseCost.text floatValue]);
float dilutionValue = ([dilution.text floatValue]);
float gpc = (opc / dilutionValue);
float gCost = (case_cost / gpc);
float bCost = (gCost / 4);
float bpc = (gpc * 4);
NSNumberFormatter *formatterCur = [[NSNumberFormatter alloc] init];
NSNumberFormatter *formatterInt = [[NSNumberFormatter alloc] init];
[formatterCur setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatterInt setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *bottlesCost = [formatterCur stringFromNumber:[NSNumber numberWithFloat:bCost]];
NSString *gallons = [formatterInt stringFromNumber:[NSNumber numberWithInt:gpc]];
NSString *gallonsCost = [formatterCur stringFromNumber:[NSNumber numberWithFloat:gCost]];
NSString *bottles = [formatterInt stringFromNumber:[NSNumber numberWithInt:bpc]];
returnMsg.text = [NSString stringWithFormat:#"%# gallons per case at %# per gallon and %# - 32 oz bottles at %# per bottle.", gallons, gallonsCost, bottles, bottlesCost];
}
- (IBAction)opcView:(id)sender {
}
#end
in the line "float gpc = (opc / dilutionValue);" is shows as an unknown value of opc, even though I think it should from the segmented controller. I'm using the segmented controller instead of Radio Buttons i've used in Java. I used the "//int opc=320" to make sure the rest of the code worked.
In each of the if blocks in your method - (IBAction)opcView:(id)sender you are creating a local int variable named opc. So when execution leaves the if block, the local variable disappears. Thus, in - (IBAction)finishBtn:(id)sender there is no variable named opc in scope.
You should declare opc to be a property as well. You will set this property when the segment control changes selection. Later, you can read the property's value in your finish button's handler.
#import "SecondViewController.h"
#interface SecondViewController()
#property (nonatomic) int opc;
#end
#implementation SecondViewController
// this method is wired to the segment control's UIControlEventValueChanged event
- (IBAction)opcView:(id)sender
{
if (opcValue.selectedSegmentIndex == 0) {
self.opc = 320;
}
if (opcValue.selectedSegmentIndex == 1) {
self.opc = 128;
}
if (opcValue.selectedSegmentIndex == 2) {
self.opc = 135;
}
if (opcValue.selectedSegmentIndex == 3) {
self.opc = 88;
}
}
- (IBAction)finishBtn:(id)sender
{
float case_cost = ([caseCost.text floatValue]);
float dilutionValue = ([dilution.text floatValue]);
float gpc = (self.opc / dilutionValue);
// lots more code
}

How to extend my method that checking if 2 cards are matched to 3 cards that are matched?

I'm following the Stanford course, and we had to build a method for the app that checks for 2 cards matching, this is how the model that have the logic looks like (the method to look there is flipCardAtIndex):
#import "CardMatchingGame.h"
#import "PlayingCardsDeck.h"
#interface CardMatchingGame()
#property (readwrite, nonatomic) int score;
#property (strong, nonatomic) NSMutableArray *cards;
#property (strong, nonatomic) NSString *notification;
#end
#implementation CardMatchingGame
-(NSMutableArray *) cards {
if (!_cards) _cards = [[NSMutableArray alloc] init];
return _cards;
}
-(id)initWithCardCount:(NSUInteger)count usingDeck:(Deck *)deck {
self = [super init];
if (self) {
for (int i = 0; i < count; i++) {
Card *card = [deck drawRandonCard];
if (!card) {
self = nil;
} else {
self.cards[i] = card;
}
}
}
return self;
}
-(Card *) cardAtIndex:(NSUInteger)index {
return (index < self.cards.count) ? self.cards[index] : nil;
}
#define FLIP_COST 1
#define MISMATCH_PENALTY 2
#define BONUS 4
-(void) flipCardAtIndex:(NSUInteger)index {
Card *card = [self cardAtIndex:index];
if (!card.isUnplayable) {
if (!card.isFaceUp) {
for (Card *otherCard in self.cards) {
if (otherCard.isFaceUp && !otherCard.isUnplayable) {
int matchScore = [card match:#[otherCard]];
if (matchScore) {
otherCard.unplayble = YES;
card.unplayble = YES;
self.notification = [NSString stringWithFormat:#"%# & %# match!", card.contents, otherCard.contents];
self.score += matchScore * BONUS;
} else {
otherCard.faceUp = NO;
self.score -= MISMATCH_PENALTY;
self.notification = [NSString stringWithFormat:#"%# did not matched to %#", card.contents, otherCard.contents];
}
break;
}
}
self.score -= FLIP_COST;
}
card.faceUp = !card.isFaceUp;
}
}
#end
And this is the class model of the whole game, that got the actual matching method:
#import "PlayingCards.h"
#implementation PlayingCards
#synthesize suit = _suit;
//overriding the :match method of cards to give different acore if its only a suit match or a number match
-(int)match:(NSArray *)cardToMatch {
int score = 0;
if (cardToMatch.count == 1) {
PlayingCards *aCard = [cardToMatch lastObject];
if ([aCard.suit isEqualToString: self.suit]) {
score = 1;
} else if (aCard.rank == self.rank) {
score = 4;
}
}
return score;
}
//more stuff...
W already created it with an array so we will be able to extend it for more objects, but now i'm trying to figure out how do I extend it :/
This is my github for the project https://github.com/NirOhayon/Matchismo
i'm new to objective C and would appreciate it munch if you could help me to figure it out.
Thanks a bunch
You can chain these with a loop to check them all. Very basic way of doing it. Just loop through each card and check it against the "self" card that you have and increment the score instead of setting it.
-(int)match:(NSArray *)cardToMatch {
int score = 0;
for(int i = 0; i < cardToMatch.count; i++) {
PlayingCards *aCard = cardToMatch[i];
if ([aCard.suit isEqualToString: self.suit]) {
score += 1;
} else if (aCard.rank == self.rank) {
score += 4;
}
}
return score;
}
For flipCardAtIndex: , I would change it to flipCardsAtIndexes:(NSArray*)indexes, where indexes is an NSArray of NSNumbers. Then I would run a for loop checking and removing any cards that are unplayable or faceup, and pass through the remaining cards at those indexes to check match, and retrieve the match score.
To tell your view controller to add another card depends on how you have your view controller set up. You could do a protocol in a method that your view controller becomes the delegate of, and through a protocol method, tell it to switch. It could also be simpler than that, depending on how it checks your model of cards to decide what to show, if it sees three cards available instead of two, it could switch.
As the point of this exercise is to learn iOS programming, I want to give you a good head start and you should tweak and figure some stuff out on your own. I have a feeling you're a novice at programming, and if you are, you'll be surprised how much programming at your stage is trial and error. Eventually it will become second nature.

Calling methods with specific values

For this code example below, usually I would use [self fall]; instead of the code at *, but I need the value of i to be sent to the fall method as well. How do I do this?
- (void)main {
for (int i=0; i <= 100; i++) {
[image[i] fall]; *
}
}
- (void)fall {
// manipulate image[i]; separately from the for loop
}
EDIT: I will accept the oldest answer as all are correct. Thanks!
You need to do -
- (void)fall:(int)i {
// manipulate image[i]; separately from the for loop
}
and call like -
- (void)main {
for (int i=0; i <= 100; i++) {
[image fall:i];
}
}
EDIT -
If you want to pass index-
- (void)fall:(int)i {
// manipulate image[i]; separately from the for loop
}
and call like -
- (void)main {
for (int i=0; i <= 100; i++) {
[self fall:i]; // Now from here you can either pass index
}
}
If you want to pass some image -
- (void)fall:(UIImage)i {
// manipulate image[i]; separately from the for loop
}
and call like -
- (void)main {
for (int i=0; i <= 100; i++) {
[self fall:imageI]; // Now from here you need to pass image, if that image is stored in array, then fetch from array. Or you need to manipulate in the way in which you are storing.
}
}
Maybe you mean:
- (void)main {
for (int i=0; i <= 100; i++) {
[image[i] fall:i];
}
}
- (void)fall:(int)i {
// manipulate image[i]; separately from the for loop
}
Or, maybe you mean:
- (void)main {
for (int i=0; i <= 100; i++) {
[self fall:image[i]];
}
}
- (void)fall:(NSImage *)image {
// manipulate image[i]; separately from the for loop
}
If not, you need to clarify your question.

How to use CARingBuffer class in an iOS (iPhone, iPad) project?

I'm currently trying to create an iOS audio project and I need to use the CARingBuffer class available in the Extras/CoreAudio/PublicUtility folder of XCode.
The problem is when I include the CARingBuffer.h in the header of my viewController and I declare a CARingBuffer object, I receive 4 compile errors.
To reproduce my problem it's pretty simple. Just create a new view based application and try to #include "CARingBuffer.h" in the header of your viewController.
Here's the content of my testViewController.h :
#import <UIKit/UIKit.h>
#include "CARingBuffer.h"
#interface testViewController : UIViewController {
}
#end
Here's the content of my testViewController.m :
#import "testViewController.h"
#implementation testViewController
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Bellow the 4 compile errors located (strangely) in the CARingBuffer according to XCode 4 :
1) Initializer element is not a constant on line :
const UInt32 kGeneralRingTimeBoundsQueueMask = kGeneralRingTimeBoundsQueueSize - 1;
2) Expected ';' after top level declarator, Expected '='... or 'atribute' before 'CARingBuffer' :
class CARingBuffer {
3) Initializer element is not a constant on line :
const UInt32 kGeneralRingTimeBoundsQueueMask = kGeneralRingTimeBoundsQueueSize - 1;
4) Expected ';' after top level declarator, Expected '='... or 'atribute' before 'CARingBuffer' :
class CARingBuffer {
Thanks in advance for your help.
Also take a look at this alternative
You need to rename the class that you are including the ring buffer in to be a .mm file.
This tells the compiler to use objective c++ .
You need change your testViewController.m to testViewController.mm because CARingBuffer is c++ class.
About how to use it, here is an extend of CARingBuffer : CARingBufferEx
//header file
#include "CARingBuffer.h"
class CARingBufferEx : public CARingBuffer {
public:
CARingBufferEx();
~CARingBufferEx();
CARingBufferError Store(const AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber);
CARingBufferError Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber);
private:
SInt64 firstInputSampleTime;
SInt64 firstOutputSampleTime;
SInt64 offset;
};
//Class
#include "CARingBufferEx.h"
#include "stdio.h"
CARingBufferEx::CARingBufferEx():firstInputSampleTime(-1), firstOutputSampleTime(-1), offset(0) {
}
CARingBufferEx::~CARingBufferEx() {
}
CARingBufferError CARingBufferEx::Store(const AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber) {
if (firstInputSampleTime < 0) {
firstInputSampleTime = frameNumber;
if (firstOutputSampleTime > 0 && offset == 0) {
offset = firstInputSampleTime - firstOutputSampleTime;
}
}
return CARingBuffer::Store(abl, nFrames, frameNumber);
}
CARingBufferError CARingBufferEx::Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber) {
if (firstOutputSampleTime < 0) {
firstOutputSampleTime = frameNumber;
if (firstInputSampleTime > 0 && offset == 0) {
offset = firstInputSampleTime - firstOutputSampleTime;
}
}
return CARingBuffer::Fetch(abl, nFrames, frameNumber + offset);
}
Usage:
CARingBufferEx* _musicMixerRingBuffer;
_musicMixerRingBuffer = new CARingBufferEx();
_musicMixerRingBuffer->Allocate(2, sizeof(AudioUnitSampleType), 1024 * 50);
//1024 is length for one package. and 50 means this buffer contains 50 packages at most.
//store
//ioData is AudioBufferList ,inTimeStamp is AudioTimeStamp
musicMixerRingBuffer->Store(ioData, inNumberFrames, inTimeStamp->mSampleTime);
//Fetch
musicMixerRingBuffer->Fetch(ioData, inNumberFrames, inTimeStamp->mSampleTime);

Problem initializing an object with init in Objective-C

I have an object that i intalize it's propertis with call to an init function, it works fine,
when i tried to add another object and intalize it the first object didn't get the properites, how do i initalize it to more then one object with diffrent or the same properties?
- (void)viewDidLoad {
pic1 = [[peopleAccel alloc] init];
}
Class peopleAccel:
- (id) init
{
self = [super init];
if (self != nil) {
position = CGPointMake(100.0, 100.0);
velocity = CGPointMake(4.0, 4.0);
radius = 40.0;
bounce = -0.1f;
gravity = 0.5f;
dragging = NO;
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
acceleratedGravity = CGPointMake(0.0, gravity);
}
return self;
}
I see a problem with setting the delegate of sharedAccelerometer. Only one object can be a delegate of another object at a time. So you should create only one peopleAccel object.
EDIT:
If you need to send accelerometer events to more than one object, you can create a specific delegate object in charge of receiving accelerometer events and broadcasting them to your several peopleAccel objects via notifications. See this question for some hints: NSNotificationCenter vs delegation?
Create a proxy so multiple objects can receive accelerometer events.
Whether you should do this or use NSNotificationCenter is debatable and there are two camps, but personally I would use this approach. NSNotificationCenter has to check string names to recognise event type; this kind of approach could be ever so slightly faster especially with a bit more optimisation. A bit more typing but I would say also easier for someone else to follow.
Something like this...
/* PLUMBING */
/* in headers */
#protocol MyAccelSubDelegate
-(void)accelerometer:(UIAccelerometer*)accelerometer
didAccelerate:(UIAcceleration*)acceleration;
#end
#interface MyAccelSubDelegateProxy : NSObject <UIAccelerometerDelegate> {
NSMutableArray subDelegates;
}
-(id)init;
-dealloc;
-(void)addSubDelegate:(id<MyAccelSubDelegate>)subDelegate;
-(void)removeSubDelegate:(id<MyAccelSubDelegate>)subDelegate;
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:
(UIAcceleration *)acceleration;
#end
/* in .m file */
#implementation MyAccelSubDelegateProxy
-(id)init { self = [super init];
if (self!=nil) subDelegates = [[NSMutableArray alloc] init]; return self; }
-dealloc { [subDelegates release]; }
-(void)addSubDelegate:(id<MyAccelSubDelegate>)subDelegate {
[subDelegates insertObject:subDelegate atIndex:subDelegates.count]; }
-(void)removeSubDelegate:(id<MyAccelSubDelegate>)subDelegate {
for (int c=0; c < subDelegates.count; c++) {
id<MyAccelSubDelegate> item = [subDelegates objectAtIndex:c];
if (item==subDelegate) { [subDelegates removeObjectAtIndex:c];
c--; continue; }
}
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:
(UIAcceleration *)acceleration {
for (int c=0; c < subDelegates.count; c++)
[((id<MyAccelSubDelegate>)[subDelegates objectAtIndex:c])
accelerometer:accelerometer didAccelerate:acceleration];
}
#end
/* SOMEWHERE IN MAIN APPLICATION FLOW STARTUP */
accelProxy = [[MyAccelSubDelegateProxy alloc] init];
[UIAccelerometer sharedAcclerometer].delegate = accelProxy;
[UIAccelerometer sharedAcclerometer].updateInterval = 0.100; // for example
/* TO ADD A SUBDELEGATE */
[accelProxy addSubDelegate:obj];
/* TO REMOVE A SUBDELEGATE */
[accelProxy removeSubDelegate:obj];
/* SOMEWHERE IN MAIN APPLICATION SHUTDOWN */
[UIAccelerometer sharedAcclerometer].delegate = nil;
[accelProxy release];