#include "CCLArgFunctions.h"
#include <CoreFoundation/CoreFoundation.h>
CFDictionaryRef
GetCFDictionaryFromDict(CFDictionaryRef dict, const CFStringRef key)
{
CFDictionaryRef retVal= (CFDictionaryRef) CFDictionaryGetValue(dict, key);
if((retVal!= NULL) && (CFDictionaryGetTypeID()== CFGetTypeID(retVal)))
{
return retVal;
}
return NULL;
}
bool
GetCFStringFromDict(CFDictionaryRef dict, CFStringRef *s, const CFStringRef key)
{
CFStringRef tempString= (CFStringRef) CFDictionaryGetValue(dict, key);
if (tempString == NULL)
return true;
if (CFStringGetTypeID() == CFGetTypeID(tempString)) {
*s = tempString;
return true;
}
return false;
}
bool
CopyCStringFromDict(CFDictionaryRef dict, char** string, const CFStringRef key)
{
CFStringRef str = NULL;
CFIndex bufSize;
char *buf = NULL;
if (!GetCFStringFromDict(dict, &str, key))
return false;
if (str == NULL)
return true;
bufSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str),
kCFStringEncodingUTF8) + 1;
buf = malloc(bufSize);
if(buf && CFStringGetCString(str, buf, bufSize, kCFStringEncodingUTF8)) {
*string = buf;
return true;
}
if (buf) free(buf);
return false;
}
bool
GetCFNumberFromDict(CFDictionaryRef dict, CFNumberRef *n, const CFStringRef key)
{
CFNumberRef tempNum = (CFNumberRef)CFDictionaryGetValue(dict, key);
if (tempNum == NULL)
return true;
if(CFNumberGetTypeID() == CFGetTypeID(tempNum)) {
*n = tempNum;
return true;
}
return false;
}
bool
GetIntFromDict(CFDictionaryRef dict, int* intRef, const CFStringRef key)
{
CFNumberRef num = NULL;
if (!GetCFNumberFromDict(dict, &num, key))
return false;
if (num == NULL)
return true;
return CFNumberGetValue(num, kCFNumberSInt32Type, intRef);
}