void link::recv_handler(buffer<uint8>& buff, size_t rbytes, const boost::system::error_code& ec) { if (ec) { mih::message pm; _handler(pm, ec); } else { mih::frame* fm = mih::frame::cast(buff.get(), rbytes); if (fm) { mih::message pm(*fm); _handler(pm, ec); } } void* rbuff = buff.get(); size_t rlen = buff.size(); _sock.async_receive(boost::asio::buffer(rbuff, rlen), boost::bind(&link::recv_handler, this, bindrv(buff), boost::asio::placeholders::bytes_transferred, boost::asio::placeholders::error)); }
static name parse_quoted_symbol_or_token(parser & p, buffer<token_entry> & new_tokens, bool & used_default, notation_entry_group grp) { used_default = false; if (p.curr_is_quoted_symbol()) { environment const & env = p.env(); auto pp_tk = p.get_name_val(); auto tks = utf8_trim(pp_tk.to_string()); auto tkcs = tks.c_str(); check_not_forbidden(tkcs); p.next(); if (p.curr_is_token(get_colon_tk())) { p.next(); unsigned prec = parse_precedence(p); new_tokens.push_back(mk_token_entry(tkcs, prec, grp)); } else if (!get_precedence(env, tkcs, grp)) { new_tokens.push_back(mk_token_entry(tkcs, LEAN_DEFAULT_PRECEDENCE, grp)); used_default = true; } return pp_tk; } else if (p.curr_is_keyword()) { auto tk = p.get_token_info().token(); check_not_forbidden(tk.to_string().c_str()); p.next(); return tk; } else { throw parser_error("invalid notation declaration, symbol expected", p.pos()); } }
void scanner::next_utf_core(char c, buffer<char> & cs) { cs.push_back(c); while (m_uskip > 0) { next(); cs.push_back(curr()); } }
bool Get_PTEx(buffer &c) { return c.addStr("PTExˆ\6\0\0", 8) && c.add<u8>(0, 1056) && c.add<u8>(1, 44) && c.addStr("\0\0\0\0\1\0\1\0\0\0\0\0\1\0\1\0\0\0\1\0\0\0\0\1\0\0\0\0\1\1\0\0\0\1\1\0\0\0\0\0\0\0\0\0", 44) && c.add<u8>(1, 528); }
inline void device_buf::out(byte p) { // TODO: If out_buf was resized so that it would be full at the next flush moment, // we only need to do one check here. out_buf.put(p); if(out_buf.size() > out_buffer_size) flush(); // Time to flush }
bool Get_MRGN(buffer &c, u16 width, u16 height) { return c.addStr("MRGN\0\5\0\0", 8) && c.add<u8>(0, 1268) && c.add<u32>(width * 32) // 'Anywhere' x-end && c.add<u32>(height * 32) // 'Anywhere' y-end && c.addStr("\3\0\0\0", 4); // 'Anywhere' string number (3) and elevation (all) }
bool Get_PTEC(buffer &c) { return c.addStr("PTEC\220\3\0\0", 8) && c.add<u8>(0, 576) && c.add<u8>(1, 24) && c.addStr("\0\0\0\0\1\0\1\0\0\0\0\0\1\0\1\0\0\0\1\0\0\0\0", 23) && c.add<u8>(1, 289); }
bool Get_UPGR(buffer &c) { return c.addStr("UPGRÔ\6\0\0", 8) && c.add<u8>(0, 1104) && c.addStr("\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\1\1\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1", 45) && c.add<u8>(0, 47) && c.add<u8>(1, 552); }
friend void copy_limbs(imp * p, buffer<name::imp *> & limbs) { limbs.clear(); while (p != nullptr) { limbs.push_back(p); p = p->m_prefix; } std::reverse(limbs.begin(), limbs.end()); }
/// Enqueues a command to unmap \p buffer from the host memory space. /// /// \see_opencl_ref{clEnqueueUnmapMemObject} event enqueue_unmap_buffer(const buffer &buffer, void *mapped_ptr, const wait_list &events = wait_list()) { BOOST_ASSERT(buffer.get_context() == this->get_context()); return enqueue_unmap_mem_object(buffer.get(), mapped_ptr, events); }
static void append(buffer &json, const char *key, const std::string &value) { json.append("\"" , 1); json.append( key, strlen(key) ); //"key" json.append("\":", 2); append(json, value); }
buffer(buffer const& b) : m_begin(0) , m_size(0) , m_capacity(0) { if (b.size() == 0) return; resize(b.size()); std::memcpy(m_begin, b.begin(), b.size()); }
bool Get_PUPx(buffer &c) { return c.addStr("PUPx\16\t\0\0", 8) && c.add<u8>(0, 1464) && c.add<u8>(3, 16) && c.addStr("\1\1\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\1\0\1\0\1\1\1\1", 39) && c.add<u8>(0, 67) && c.add<u8>(1, 732); }
character A_upper_calltype A_upper_input(bool writeback, character c, buffer& ib) { if (writeback) { ib.push_front(c); return 0; } else { if (ib.size() > 0) return ib.pop_front(); return (character)fgetc(stdin); } }
buffer(buffer const& b) : m_begin(0) , m_end(0) , m_last(0) { if (b.size() == 0) return; resize(b.size()); std::memcpy(m_begin, b.begin(), b.size()); }
unsigned list_cases_on_core(list<A> const & l, buffer<vm_obj> & data) { if (empty(l)) { return 0; } else { data.push_back(to_obj(head(l))); data.push_back(list_to_obj(tail(l))); return 1; } }
void set_level( int log_level ) { destination::instance().level(log_level); trace_logger.enabled(log_level >= 5); debug_logger.enabled(log_level >= 4); info_logger.enabled(log_level >= 3); warn_logger.enabled(log_level >= 2); error_logger.enabled(log_level >= 1); }
JSONPACK_API_BEGIN_NAMESPACE ////============================== MAKE_JSON ============================================== static inline void make_json(buffer &json, const std::string &UNUSED(key) ) { json.erase_last_comma(); json.append("}\0", 2); }
void copy_from(buffer& source) { source.unmap(); source.bind(); GL(glBindTexture(GL_TEXTURE_2D, id_)); GL(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_, FORMAT[stride_], TYPE[stride_], NULL)); GL(glBindTexture(GL_TEXTURE_2D, 0)); source.unbind(); source.map(); // Just map it back since map will orphan buffer. }
void copy_to(buffer& dest) { dest.unmap(); dest.bind(); GL(glBindTexture(GL_TEXTURE_2D, id_)); GL(glReadBuffer(GL_COLOR_ATTACHMENT0)); GL(glReadPixels(0, 0, width_, height_, FORMAT[stride_], TYPE[stride_], NULL)); GL(glBindTexture(GL_TEXTURE_2D, 0)); dest.unbind(); GL(glFlush()); }
static name mk_fresh_name(environment const & env, buffer<name> const & names, name const & s) { unsigned i = 1; name c = s; while (true) { if (!env.find(c) && std::find(names.begin(), names.end(), c) == names.end()) return c; c = s.append_after(i); i++; } }
static void append(buffer &json, const char &value, const bool&, const unsigned&, unsigned&) { if( std::isgraph(value) ) { char c[4] = {'"', value, '"', ','}; json.append(c, 4); } else json.append("null,", 5); }
static void append(buffer &json, const Seq &value) { json.append("[", 1); for(const auto &v : value) { json_traits<type_t>::append(json, v); } json.erase_last_comma(); json.append("],", 2); }
// ni stands for "next int". int ni(buffer& buf) { int i = atoi(buf.front().c_str()); if (i == 0) for(char ch : buf.front()) if (!isdigit(ch)) error("Expected number, found \"" + buf.front() + "\"."); buf.pop_front(); return i; }
void destruct_structure_instance(expr const & e, expr & t, buffer<name> & field_names, buffer<expr> & field_values, buffer<expr> & using_exprs) { lean_assert(is_structure_instance(e)); t = macro_arg(e, 0); list<name> const & fns = static_cast<structure_instance_macro_cell const*>(macro_def(e).raw())->get_field_names(); unsigned num_fileds = length(fns); to_buffer(fns, field_names); for (unsigned i = 1; i < num_fileds+1; i++) field_values.push_back(macro_arg(e, i)); for (unsigned i = num_fileds+1; i < macro_num_args(e); i++) using_exprs.push_back(macro_arg(e, i)); }
/* Return true if there is j s.t. ssinfos[j] is marked as subsingleton, and it dependends of argument i */ static bool has_nonsubsingleton_fwd_dep(unsigned i, buffer<param_info> const & pinfos, buffer<ss_param_info> const & ssinfos) { lean_assert(pinfos.size() == ssinfos.size()); for (unsigned j = i+1; j < pinfos.size(); j++) { if (ssinfos[j].is_subsingleton()) continue; auto const & back_deps = pinfos[j].get_back_deps(); if (std::find(back_deps.begin(), back_deps.end(), i) != back_deps.end()) { return true; } } return false; }
void setup( const string& file_name, bool console_output, int log_level ) { destination::instance().set_file_name(file_name); destination::instance().console_output(console_output); destination::instance().level(log_level); trace_logger.enabled(log_level >= 5); debug_logger.enabled(log_level >= 4); info_logger.enabled(log_level >= 3); warn_logger.enabled(log_level >= 2); error_logger.enabled(log_level >= 1); }
/** * Handle the reception of an asynchronous message. * * @param buff The input message bytes. * @param rbytes The number of bytes of the input message. * @param error The error code. */ void udp_listener::handle_receive(buffer<uint8> &buff, size_t rbytes, const boost::system::error_code &error) { using namespace boost; if (!error) { ODTONE_LOG(1, "(udp) received ", rbytes, " bytes."); ODTONE_LOG(0, "(udp) from ", _rmt_endp.address().to_string(), " : ", _rmt_endp.port()); mih::frame *pud = mih::frame::cast(buff.get(), rbytes); if(pud) { // Decode IP address mih::octet_string ip; uint16 scope = 0; if(_rmt_endp.address().is_v4()) { boost::asio::ip::address_v4 ip_addr = _rmt_endp.address().to_v4(); ip = ip_addr.to_string(); } else if(_rmt_endp.address().is_v6()) { boost::asio::ip::address_v6 ip_addr = _rmt_endp.address().to_v6(); scope = ip_addr.scope_id(); ip_addr.scope_id(0); ip = ip_addr.to_string(); } // Decode port uint16 port = _rmt_endp.port(); meta_message_ptr in(new meta_message(ip, scope, port, *pud)); ODTONE_LOG(4, *pud); // discard messages if multicast messages are not supported if(utils::is_multicast(in) && !_enable_multicast) { ODTONE_LOG(1, "(udp) Discarding message! Reason: ", "multicast messages are not supported"); } else { _dispatch(in); } } } void *rbuff = buff.get(); size_t rlen = buff.size(); _sock.async_receive_from(asio::buffer(rbuff, rlen), _rmt_endp, bind(&udp_listener::handle_receive, this, bind_rv(buff), asio::placeholders::bytes_transferred, asio::placeholders::error)); }
bool xml_document::to_string(buffer& buf, bool pretty_print, bool nul_terminate) const { if (_M_used == 0) { return nul_terminate ? buf.append((char) 0) : true; } if (!to_string(buf, pretty_print, _M_nodes, 0)) { return false; } return nul_terminate ? buf.append((char) 0) : true; }
inline event write_single_value(const T &value, const buffer &buffer, size_t index, command_queue &queue) { BOOST_ASSERT(index < buffer.size() / sizeof(T)); BOOST_ASSERT(buffer.get_context() == queue.get_context()); return queue.enqueue_write_buffer(buffer, index * sizeof(T), sizeof(T), &value); }