#include "macros.hpp"
#include "common.hpp"
#include "SmbConfig.hpp"
#include "SmbOption.hpp"
template <>
std::string property_convert<std::string>(CFPropertyListRef val)
{
if (CFGetTypeID(val) != CFStringGetTypeID()) {
throw std::runtime_error("unexpected non-CFString type");
}
return cfstring_convert((CFStringRef)val);
}
template <>
unsigned property_convert<unsigned>(CFPropertyListRef val)
{
int nval;
if (CFGetTypeID(val) != CFNumberGetTypeID()) {
throw std::runtime_error("unexpected non-CFNumber type");
}
if (!CFNumberGetValue((CFNumberRef)val, kCFNumberIntType, &nval)) {
throw std::range_error("unexpected integer representation");
}
if (nval < 0) {
throw std::range_error("unexpected negative integer");
}
return (unsigned)nval;
}
template <>
bool property_convert<bool>(CFPropertyListRef val)
{
if (CFGetTypeID(val) != CFBooleanGetTypeID()) {
throw std::runtime_error("unexpected non-boolean type");
}
return cftype_equal<CFBooleanRef>(kCFBooleanTrue, (CFBooleanRef)val);
}