示例#1
0
 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();
 }
示例#2
0
            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();
            }
示例#3
0
                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();
                }
示例#4
0
文件: Read.hpp 项目: RoboBuddie/gubg
 ReturnCode read(char &ch)
 {
     MSS_BEGIN(ReturnCode);
     MSS(it_ != end_, RangeIsEmpty);
     ch = (char)*(it_++);
     MSS_END();
 }
示例#5
0
 ReturnCode Socket::receive(IOBuffer &buffer)
 {
     MSS_BEGIN(ReturnCode);
     MSS(pimpl_);
     MSS(pimpl_->receive(buffer));
     MSS_END();
 }
示例#6
0
 ReturnCode Socket::shutdown()
 {
     MSS_BEGIN(ReturnCode);
     MSS(pimpl_);
     MSS(pimpl_->shutdown());
     MSS_END();
 }
示例#7
0
文件: Read.hpp 项目: RoboBuddie/gubg
 ReturnCode read(Type &type)
 {
     MSS_BEGIN(ReturnCode);
     MSS(it_ != end_, RangeIsEmpty);
     MSS(type.read(*(it_++)));
     MSS_END();
 }
示例#8
0
 ReturnCode Socket::send(IOBuffer &buffer)
 {
     MSS_BEGIN(ReturnCode);
     MSS(pimpl_);
     MSS(pimpl_->send(buffer));
     MSS_END();
 }
示例#9
0
 ReturnCode Socket::listen()
 {
     MSS_BEGIN(ReturnCode);
     MSS(pimpl_);
     MSS(pimpl_->listen());
     MSS_END();
 }
示例#10
0
 //Public API
 ReturnCode Socket::bind(int port)
 {
     MSS_BEGIN(ReturnCode);
     MSS(createSocket_());
     MSS(pimpl_->bind(port));
     MSS_END();
 }
示例#11
0
文件: Read.hpp 项目: RoboBuddie/gubg
 ReturnCode read(unsigned char &b)
 {
     MSS_BEGIN(ReturnCode);
     MSS(it_ != end_, RangeIsEmpty);
     b = (unsigned char)*(it_++);
     MSS_END();
 }
示例#12
0
 ReturnCode Linker::addObject(const gubg::file::File &obj)
 {
     MSS_BEGIN(ReturnCode);
     MSS((bool)itf_);
     itf_->objects.push_back(obj);
     MSS_END();
 }
示例#13
0
 ReturnCode Linker::addLibrary(const std::string &lib)
 {
     MSS_BEGIN(ReturnCode);
     MSS((bool)itf_);
     itf_->libraries.push_back(lib);
     MSS_END();
 }
示例#14
0
 ReturnCode Linker::addOption(const std::string &option)
 {
     MSS_BEGIN(ReturnCode);
     MSS((bool)itf_);
     MSS(itf_->setOption(option), UnknownOption);
     MSS_END();
 }
示例#15
0
 ReturnCode Linker::addLibraryPath(const gubg::file::File &lp)
 {
     MSS_BEGIN(ReturnCode);
     MSS((bool)itf_);
     itf_->libraryPaths.push_back(lp);
     MSS_END();
 }
示例#16
0
 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();
 }
示例#17
0
 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();
 }
示例#18
0
 bool add_data(T v)
 {
     MSS_BEGIN(bool);
     Range range;
     MSS(add(range, 1));
     range.front() = v;
     MSS_END();
 }
示例#19
0
 ReturnCode createConnection(std::shared_ptr<Handler> &handler)
 {
     MSS_BEGIN(ReturnCode);
     Socket socket;
     MSS(socket.connect(ip_, port_));
     handler.reset(new Handler(socket));
     MSS_END();
 }
示例#20
0
文件: State.cpp 项目: lfannes/gubg
	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();
	}
示例#21
0
文件: State.cpp 项目: lfannes/gubg
	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();
	}
示例#22
0
 ReturnCode setWidth(double width)
 {
     MSS_BEGIN(ReturnCode);
     MSS(width > 0.0, IllegalArgument);
     width_ = width;
     invWidth_ = 1.0/width;
     MSS_END();
 }
示例#23
0
 ReturnCode listen()
 {
     MSS_BEGIN(ReturnCode);
     MSS(state == Bound, InvalidState);
     MSS(::listen(fid, MaxNrWaitingConnections) != -1, CouldNotListen);
     changeState(Listening);
     MSS_END();
 }
示例#24
0
 ReturnCode draw(Domain &value) const
 {
     MSS_BEGIN(ReturnCode);
     size_t ix;
     MSS(weightDistribution_.generate(ix));
     value = drawGaussian(data_[ix], width_);
     MSS_END();
 }
示例#25
0
文件: SFML.hpp 项目: gfannes/gubg.ui
 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();
 }
示例#26
0
 ReturnCode decodeNumber(Number &number, IInput &input)
 {
     MSS_BEGIN(ReturnCode);
     unsigned long v;
     MSS(decodeNumber(v, input));
     number = v;
     MSS_END();
 }
示例#27
0
 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();
 }
示例#28
0
 ReturnCode Socket::accept(Socket &socket)
 {
     MSS_BEGIN(ReturnCode);
     MSS(pimpl_);
     int fid;
     MSS(pimpl_->accept(fid));
     socket = Socket(fid);
     MSS_END();
 }
示例#29
0
 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();
 }
示例#30
0
 bool add_data(T a, T b)
 {
     MSS_BEGIN(bool);
     Range range;
     MSS(add(range, 2));
     range[0] = a;
     range[1] = b;
     MSS_END();
 }