Re: what #ifdef's should I use?
Re: what #ifdef's should I use?
- Subject: Re: what #ifdef's should I use?
- From: Stéphane Sudre <email@hidden>
- Date: Mon, 6 Jan 2003 18:34:05 +0100
On lundi, janvier 6, 2003, at 06:08 PM, Glenn Howes wrote:
I've a C++ object factory. If I'm compiling a Cocoa application, I want
this factory to return an object which will use an NSTimer to do an
idle routine. If I'm compiling a Carbon application, I want this
factory to return an object which will use a Carbon timer task. If this
code is compiled under windows, it'll return some 3rd object which does
some Windowsy way of handing idle time.
I could have my own defines in a prefix header, but there doesn't seem
to be any reason not to make this self contained.
I'm thinking along the lines of:
MyObject* MyFactory::MakeObject()
{
#if TARGET_API_MAC_CARBON
MyCarbonObject* result = new MyCarbonObject;
#elseif something else
MyCocoaObject* result = new MyCocoaObject;
#elseif windows something
MyWindowsObject* result = new MyWindowsObject
#else
error undefined
#endif
return result;
}
So which #defines should I use in these 3 cases?
And I suppose this isn't a true factory pattern cause the factory
doesn't get installed.
Potential problem:
To use C++ and Objective-C, your file extension may need to be .mm
which is not going to be recognized by the others compilers: Visual
Studio for instance.
Other potential problem:
I don't see how you expect to handle the Cocoa object in your code. You
will need to add additional ifdef in order to handle the Objective-C
mechanism (except if you're using the C API but the problem still
remains). This leads to wondering what the purpose of MakeObject is.
_______________________________________________
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.