• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: what #ifdef's should I use?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: what #ifdef's should I use?
      • From: Glenn Howes <email@hidden>
References: 
 >what #ifdef's should I use? (From: Glenn Howes <email@hidden>)

  • Prev by Date: Re: porting apps from NextStep to Cocoa
  • Next by Date: Re: Why? (Icons in 'Sketch' & 'SimpleToolbar' examples)
  • Previous by thread: what #ifdef's should I use?
  • Next by thread: Re: what #ifdef's should I use?
  • Index(es):
    • Date
    • Thread