Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

str2OSType in utils.cpp in ConvertFile example



I am trying to understand one of the CoreAudio examples and I am
really having a hard time. In the utils.cpp file, there is a method
called str2OSType.

void str2OSType (const char * inString, OSType &outType)
{
	if (inString == NULL) {
		outType = 0;
		return;
	}
	
	size_t len = strlen(inString);
	if (len <= 4) {
		char workingString[5];
		
		workingString[4] = 0;
		workingString[0] = workingString[1] = workingString[2] =
workingString[3] = ' ';
		memcpy (workingString, inString, strlen(inString));
		outType = 	*(workingString + 0) <<	24	|
					*(workingString + 1) <<	16	|
					*(workingString + 2) <<	8	|
					*(workingString + 3);
		return;
	}

	if (len <= 8) {
		if (sscanf (inString, "%lx", &outType) == 0) {
			printf ("* * Bad conversion for OSType\n");
			UsageString(1);
		}
		return;
	}
	printf ("* * Bad conversion for OSType\n");
	UsageString(1);
}


First, I don't understand the need to convert a 4 byte string into a 4 byte OSType. That being said, where is there any documentation on OSTypes. I found a definition in wikipedia that says that it is a 4 byte sequence used as a File/Directory identifier. However, I can't find anything beyond that. For instance, what are the accepted values for the identifiers? Furthermore, is the type definition in CoreFoundation or does it reside deeper than that? I can't find anything to give me any guidance on this.

Beyond my inability to locate documentation on OSType, I am having a
hard time with the assignment of "outType". I generally don't have an
appreciation for bit mathematics. If inString is a 4 character string
and workingString is a 4 character array, what is the function of the
bit shift and the bit Or? I don't understand what this section of code
is trying to do.

Any guidance would be greatly appreciated.

Thanks,
Will DeShazer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/coreaudio-api/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.