bool write(Writer &w) const { MSS_BEGIN(bool); auto fix = 0u; //Copy of field is intentional for (Range field: fields) { auto write_field = [&](Writer &w1){ MSS_BEGIN(bool); if (!field.empty()) { w.text(field.front()); field.pop_front(); while (!field.empty()) { w.text(' '); w.text(field.front()); field.pop_front(); } } MSS_END(); }; MSS(w(fix, write_field)); ++fix; } MSS_END(); }
ReturnCode computeMeanSigma(Result &mean, Result &sigma, const Values &values, const Weights &weights) { MSS_BEGIN(ReturnCode); MSS(!values.empty()); MSS(values.size() == weights.size()); //Compute mean and the sum of the weights mean = 0.0; Result sumW = 0.0; typename Values::const_iterator value = values.begin(); for (auto weight: weights) { mean += *(value++)*weight; sumW += weight; } mean /= sumW; //Compute sigma sigma = 0.0; typename Weights::const_iterator weight = weights.begin(); for (auto value: values) sigma += *(weight++)*(value-mean)*(value-mean); sigma = ::sqrt(sigma/sumW); MSS_END(); }
ReturnCode process_() { MSS_BEGIN(ReturnCode, logns); Name name; switch (const auto rc = pop_name_(name)) { case ReturnCode::OK: break; case ReturnCode::NotFound: MSS_RETURN_OK(); break; default: MSS(rc); break; } Attributes attrs; MSS(pop_attrs_(attrs)); receiver_().parser_open(name, attrs); pop_whitespace_(); if (content_.pop_if('{')) { pop_whitespace_(); while (!content_.pop_if('}')) { MSS(process_()); } } receiver_().parser_close(); MSS_END(); }
ReturnCode read(char &ch) { MSS_BEGIN(ReturnCode); MSS(it_ != end_, RangeIsEmpty); ch = (char)*(it_++); MSS_END(); }
ReturnCode Socket::receive(IOBuffer &buffer) { MSS_BEGIN(ReturnCode); MSS(pimpl_); MSS(pimpl_->receive(buffer)); MSS_END(); }
ReturnCode Socket::shutdown() { MSS_BEGIN(ReturnCode); MSS(pimpl_); MSS(pimpl_->shutdown()); MSS_END(); }
ReturnCode read(Type &type) { MSS_BEGIN(ReturnCode); MSS(it_ != end_, RangeIsEmpty); MSS(type.read(*(it_++))); MSS_END(); }
ReturnCode Socket::send(IOBuffer &buffer) { MSS_BEGIN(ReturnCode); MSS(pimpl_); MSS(pimpl_->send(buffer)); MSS_END(); }
ReturnCode Socket::listen() { MSS_BEGIN(ReturnCode); MSS(pimpl_); MSS(pimpl_->listen()); MSS_END(); }
//Public API ReturnCode Socket::bind(int port) { MSS_BEGIN(ReturnCode); MSS(createSocket_()); MSS(pimpl_->bind(port)); MSS_END(); }
ReturnCode read(unsigned char &b) { MSS_BEGIN(ReturnCode); MSS(it_ != end_, RangeIsEmpty); b = (unsigned char)*(it_++); MSS_END(); }
ReturnCode Linker::addObject(const gubg::file::File &obj) { MSS_BEGIN(ReturnCode); MSS((bool)itf_); itf_->objects.push_back(obj); MSS_END(); }
ReturnCode Linker::addLibrary(const std::string &lib) { MSS_BEGIN(ReturnCode); MSS((bool)itf_); itf_->libraries.push_back(lib); MSS_END(); }
ReturnCode Linker::addOption(const std::string &option) { MSS_BEGIN(ReturnCode); MSS((bool)itf_); MSS(itf_->setOption(option), UnknownOption); MSS_END(); }
ReturnCode Linker::addLibraryPath(const gubg::file::File &lp) { MSS_BEGIN(ReturnCode); MSS((bool)itf_); itf_->libraryPaths.push_back(lp); MSS_END(); }
bool Planner::add_absence(const std::string &worker, const std::string &span) { MSS_BEGIN(bool); gubg::Strange strange(span); int year, month, day; MSS(strange.pop_decimal(year)); MSS(strange.pop_if('/')); MSS(strange.pop_decimal(month)); MSS(strange.pop_if('/')); MSS(strange.pop_decimal(day)); if (strange.pop_if('-')) { int year2, month2, day2; MSS(strange.pop_decimal(year2)); MSS(strange.pop_if('/')); MSS(strange.pop_decimal(month2)); MSS(strange.pop_if('/')); MSS(strange.pop_decimal(day2)); absence_per_worker[worker].push_back(Day(year, month, day)); for (auto d: dayRange(Day(year, month, day), Day(year2, month2, day2))) absence_per_worker[worker].push_back(d); } else { absence_per_worker[worker].push_back(Day(year, month, day)); } MSS_END(); }
bool has_dim(size_t fix, unsigned int wanted_dim) const { MSS_BEGIN(bool); MSS(fix < fields.size()); MSS_Q(fields[fix].size() == wanted_dim); MSS_END(); }
bool add_data(T v) { MSS_BEGIN(bool); Range range; MSS(add(range, 1)); range.front() = v; MSS_END(); }
ReturnCode createConnection(std::shared_ptr<Handler> &handler) { MSS_BEGIN(ReturnCode); Socket socket; MSS(socket.connect(ip_, port_)); handler.reset(new Handler(socket)); MSS_END(); }
ReturnCode State::registerFunction(Function function, const std::string &name) { MSS_BEGIN(ReturnCode); CHECK_AND_LOCK(pimpl_); lua_pushcfunction(s, (lua_CFunction)function); lua_setglobal(s, name.c_str()); MSS_END(); }
ReturnCode State::execute(const std::string &code) { MSS_BEGIN(ReturnCode); CHECK_AND_LOCK(pimpl_); MSS(luaL_loadstring(s, code.c_str()) == 0, CompileError); MSS(lua_pcall(s, 0, 0, 0) == 0, RuntimeError); MSS_END(); }
ReturnCode setWidth(double width) { MSS_BEGIN(ReturnCode); MSS(width > 0.0, IllegalArgument); width_ = width; invWidth_ = 1.0/width; MSS_END(); }
ReturnCode listen() { MSS_BEGIN(ReturnCode); MSS(state == Bound, InvalidState); MSS(::listen(fid, MaxNrWaitingConnections) != -1, CouldNotListen); changeState(Listening); MSS_END(); }
ReturnCode draw(Domain &value) const { MSS_BEGIN(ReturnCode); size_t ix; MSS(weightDistribution_.generate(ix)); value = drawGaussian(data_[ix], width_); MSS_END(); }
bool get_mouse_position(MousePosition &pos) { MSS_BEGIN(bool); const auto p = sf::Mouse::getPosition(rw_); pos[0] = p.x; pos[1] = p.y; MSS_END(); }
ReturnCode decodeNumber(Number &number, IInput &input) { MSS_BEGIN(ReturnCode); unsigned long v; MSS(decodeNumber(v, input)); number = v; MSS_END(); }
ReturnCode send(IOBuffer &buffer) { MSS_BEGIN(ReturnCode); MSS(state == Connected, InvalidState); auto nrSent = ::send(fid, buffer.data(), buffer.size(), 0); MSS(nrSent != -1, CouldNotSend); buffer.scrollBegin(nrSent); MSS_END(); }
ReturnCode Socket::accept(Socket &socket) { MSS_BEGIN(ReturnCode); MSS(pimpl_); int fid; MSS(pimpl_->accept(fid)); socket = Socket(fid); MSS_END(); }
ReturnCode Socket::createSocket_() { MSS_BEGIN(ReturnCode); MSS(!pimpl_, SocketAlreadyPresent); int fid = ::socket(PF_INET, SOCK_STREAM, 0); MSS(fid != InvalidFID, CouldNotGetSocketDescriptor); pimpl_.reset(new Pimpl(fid)); MSS_END(); }
bool add_data(T a, T b) { MSS_BEGIN(bool); Range range; MSS(add(range, 2)); range[0] = a; range[1] = b; MSS_END(); }