#ifndef _H_CFMUNGE
#define _H_CFMUNGE
#include <security_utilities/cfutilities.h>
#include <CoreFoundation/CoreFoundation.h>
#include <cstdarg>
namespace Security {
class CFMunge {
public:
CFMunge(const char *fmt, va_list arg);
~CFMunge();
protected:
char next();
bool next(char c);
bool parameter();
protected:
const char *format;
va_list args;
CFAllocatorRef allocator;
OSStatus error;
};
class CFMake : public CFMunge {
public:
CFMake(const char *fmt, va_list arg) : CFMunge(fmt, arg) { }
CFTypeRef make();
CFDictionaryRef addto(CFMutableDictionaryRef dict);
protected:
CFTypeRef makedictionary();
CFTypeRef makearray();
CFTypeRef makenumber();
CFTypeRef makestring();
CFTypeRef makeformat();
CFTypeRef makespecial();
CFDictionaryRef add(CFMutableDictionaryRef dict);
};
CFTypeRef cfmake(const char *format, ...);
CFTypeRef vcfmake(const char *format, va_list args);
template <class CFType>
CFType cfmake(const char *format, ...)
{
va_list args;
va_start(args, format);
CFType result = CFType(vcfmake(format, args));
va_end(args);
return result;
}
CFDictionaryRef cfadd(CFMutableDictionaryRef dict, const char *format, ...);
bool cfscan(CFTypeRef source, const char *format, ...);
bool vcfscan(CFTypeRef source, const char *format, va_list args);
CFTypeRef cfget(CFTypeRef source, const char *format, ...);
CFTypeRef vcfget(CFTypeRef source, const char *format, va_list args);
template <class CFType>
CFType cfget(CFTypeRef source, const char *format, ...)
{
va_list args;
va_start(args, format);
CFType result = CFType(vcfget(source, format, args));
va_end(args);
return (result && CFTraits<CFType>::check(result)) ? result : NULL;
}
template <class CFType>
class CFTemp : public CFRef<CFType> {
public:
CFTemp(const char *format, ...)
{
va_list args;
va_start(args, format);
this->take(CFType(vcfmake(format, args)));
va_end(args);
}
};
}
#endif //_H_CFMUNGE