#include "hairpoll.h" #include #include #include #include extern "C" { struct error { std::string message; }; const char* error_message(error_t error) { return error->message.c_str(); } void error_destruct(error_t error) { delete error; } } /// Returns true if fn executed without throwing an error, false otherwise. /// If calling fn threw an error, capture it in *out_error. template bool translateExceptions(error_t* out_error, Fn&& fn) { try { fn(); } catch (const std::exception& e) { *out_error = new error{e.what()}; return false; } catch (...) { *out_error = new error{"Unknown internal error"}; return false; } return true; } /// /// hairpoll-related bits /// class Poll { public: Poll(std::string person) : person(person) { } struct option { option(std::string name, std::string url) : name(name) , url(url) , votes(0) { } std::string name; std::string url; int votes; }; std::string person; std::vector