#ifndef _SOSPERSIST_H_
#define _SOSPERSIST_H_
__BEGIN_DECLS
#include <utilities/SecCFRelease.h>
#include <utilities/SecCFWrappers.h>
#include <CoreFoundation/CoreFoundation.h>
#include <stdlib.h>
#include <AssertMacros.h>
static inline bool SOSPeerGetPersistedBoolean(CFDictionaryRef persisted, CFStringRef key) {
CFBooleanRef boolean = CFDictionaryGetValue(persisted, key);
return boolean && CFBooleanGetValue(boolean);
}
static inline CFDataRef SOSPeerGetPersistedData(CFDictionaryRef persisted, CFStringRef key) {
return asData(CFDictionaryGetValue(persisted, key), NULL);
}
static inline int64_t SOSPeerGetPersistedInt64(CFDictionaryRef persisted, CFStringRef key) {
int64_t integer = 0;
CFNumberRef number = CFDictionaryGetValue(persisted, key);
if (number) {
CFNumberGetValue(number, kCFNumberSInt64Type, &integer);
}
return integer;
}
static inline bool SOSPeerGetOptionalPersistedCFIndex(CFDictionaryRef persisted, CFStringRef key, CFIndex *value) {
bool exists = false;
CFNumberRef number = CFDictionaryGetValue(persisted, key);
if (number) {
exists = true;
CFNumberGetValue(number, kCFNumberCFIndexType, value);
}
return exists;
}
static inline void SOSPersistBool(CFMutableDictionaryRef persist, CFStringRef key, bool value) {
CFDictionarySetValue(persist, key, value ? kCFBooleanTrue : kCFBooleanFalse);
}
static inline void SOSPersistInt64(CFMutableDictionaryRef persist, CFStringRef key, int64_t value) {
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value);
CFDictionarySetValue(persist, key, number);
CFReleaseSafe(number);
}
static inline void SOSPersistCFIndex(CFMutableDictionaryRef persist, CFStringRef key, CFIndex value) {
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &value);
CFDictionarySetValue(persist, key, number);
CFReleaseSafe(number);
}
static inline void SOSPersistOptionalValue(CFMutableDictionaryRef persist, CFStringRef key, CFTypeRef value) {
if (value)
CFDictionarySetValue(persist, key, value);
}
__END_DECLS
#endif