• 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: ObjC++ (and a word about Java, too ;-)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC++ (and a word about Java, too ;-)


  • Subject: Re: ObjC++ (and a word about Java, too ;-)
  • From: Rosyna <email@hidden>
  • Date: Wed, 5 Dec 2001 16:52:39 -0700

Yeah, who needs error checking, we can just let it abort()!

Ahh, the joys of typecasting. I use something similar to the below code, but I always use an FSRef and never a path as the original.

FSCatalogInfo infoRec;
FInfo *finderInfo;
char typestr[5],creatorstr[5];
UInt8 * path;
FSRef* theSuperSexySuperStableSuperNiftyRef;
OSStatus err=noErr;
typestr[4]=0;
creatorstr[4]=0;
path = [[fullPath stringByExpandingTildeInPath] UTF8String];
err = FSPathMakeRef (path, &theSuperSexySuperStableSuperNiftyRef, NULL);
if (err) goto bail;
err=FSGetCatalogInfo(&theSuperSexySuperStableSuperNiftyRef,kFSCatInfoFinderInfo,&infoRec,NULL,NULL,NULL);
if (err) goto bail;
finderInfo=(FInfo*)infoRec.finderInfo;
*(OSType*)typestr=finderInfo->fdType;
*(OSType*)creatorstr=finderInfo->fdCreator;
[type setStringValue:[NSString stringWithCString:typestr]];
[creator setStringValue:[NSString stringWithCString:creatorstr]];
[self resize:size];
bail:
;

I have no clue why you are converting an FSRef into an FSSpec.

And there is little doubt that the cocoa methods don't call the same code above. There should be a MoreFilesPlus ;)

Ack, at 12/5/01, Thomas Lachand-Robert said:

Obviously that's just an opinion, but every time I have to look to the documentation of Carbon, I'm scared. All these strange names FSSpec, FSRef,
kXooopsArgh, etc. I did use it some weeks ago because I needed to acces type/creator information, and I got an headache just for this simple thing.
My code came as follows (probably not the best, but I basically copied somewhere in the doc):
OSStatus status;
FSRef fsRef;
const char* cname;
FSSpec fsSpec;
FInfo fndrInfo;

cname = [[fullPath stringByExpandingTildeInPath] UTF8String];
status = FSPathMakeRef ((UInt8*) cname, &fsRef, NULL);
if (status == 0)
status = FSGetCatalogInfo (&fsRef, 0, NULL, NULL, &fsSpec, NULL);
if (status == 0)
status = FSpGetFInfo (&fsSpec, &fndrInfo);
if (status == 0) {
macType = fndrInfo.fdType;
macCreator = fndrInfo.fdCreator;
}

It is very difficult to understand what happens. Compare with a similar piece in Cocoa:
NSDictionary *fattrs = [file attributes];
NSDate* date = [fattrs objectForKey:NSFileModificationDate];
NSString *group = [fattrs objectForKey:NSFileGroupOwnerAccountName];
NSString *owner = [fattrs objectForKey:NSFileOwnerAccountName];

Exception removes the need of "status", classes and dictionaries don't need strange names, etc.

--



Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug

Unsanity: Unsane Tools for Insane People


  • Follow-Ups:
    • Multiple Inheritance (not Marathon Infinity)
      • From: Rosyna <email@hidden>
References: 
 >Re: ObjC++ (and a word about Java, too ;-) (From: Thomas Lachand-Robert <email@hidden>)

  • Prev by Date: Re: blank plugin icon
  • Next by Date: Re: ObjC++ (and a word about Java, too ;-)
  • Previous by thread: Re: ObjC++ (and a word about Java, too ;-)
  • Next by thread: Multiple Inheritance (not Marathon Infinity)
  • Index(es):
    • Date
    • Thread