当前位置: 首页>>代码示例>>C++>>正文


C++ span类代码示例

本文整理汇总了C++中span的典型用法代码示例。如果您正苦于以下问题:C++ span类的具体用法?C++ span怎么用?C++ span使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了span类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: restart_read_timeout

	bool udp_tracker_connection::on_connect_response(span<char const> buf)
	{
		// ignore packets smaller than 16 bytes
		if (buf.size() < 16) return false;

		restart_read_timeout();

		// skip header
		buf = buf.subspan(8);

		// reset transaction
		update_transaction_id();
		std::uint64_t const connection_id = aux::read_int64(buf);

		std::lock_guard<std::mutex> l(m_cache_mutex);
		connection_cache_entry& cce = m_connection_cache[m_target.address()];
		cce.connection_id = connection_id;
		cce.expires = aux::time_now() + seconds(m_man.settings().get_int(settings_pack::udp_tracker_token_expiry));

		if (0 == (tracker_req().kind & tracker_request::scrape_request))
			send_udp_announce();
		else if (0 != (tracker_req().kind & tracker_request::scrape_request))
			send_udp_scrape();
		return true;
	}
开发者ID:michelmno,项目名称:libtorrent,代码行数:25,代码来源:udp_tracker_connection.cpp

示例2: update

		void update(span<char const> data)
		{
			if (CryptHashData(m_hash, reinterpret_cast<BYTE const*>(data.data()), int(data.size()), 0) == false)
			{
				throw_ex<system_error>(error_code(GetLastError(), system_category()));
			}
		}
开发者ID:gubatron,项目名称:libtorrent,代码行数:7,代码来源:win_crypto_provider.hpp

示例3: count_trailing_ones_hw

	int count_trailing_ones_hw(span<std::uint32_t const> buf)
	{
		auto const num = int(buf.size());
		std::uint32_t const* ptr = buf.data();

		TORRENT_ASSERT(num >= 0);
		TORRENT_ASSERT(ptr != nullptr);

		for (int i = num - 1; i >= 0; i--)
		{
			if (ptr[i] == 0xffffffff) continue;

#if TORRENT_HAS_BUILTIN_CTZ
			std::uint32_t const v = ~aux::network_to_host(ptr[i]);
			return (num - i - 1) * 32 + __builtin_ctz(v);
#elif defined _MSC_VER
			std::uint32_t const v = ~aux::network_to_host(ptr[i]);
			DWORD pos;
			_BitScanForward(&pos, v);
			return (num - i - 1) * 32 + pos;
#else
			TORRENT_ASSERT_FAIL();
			return -1;
#endif
		}

		return num * 32;
	}
开发者ID:gubatron,项目名称:libtorrent,代码行数:28,代码来源:ffs.cpp

示例4: random_bytes

		void random_bytes(span<char> buffer)
		{
#ifdef TORRENT_BUILD_SIMULATOR
			// simulator

			for (auto& b : buffer) b = char(random(0xff));

#elif TORRENT_USE_CRYPTOAPI
			// windows

			aux::crypt_gen_random(buffer);

#elif TORRENT_USE_DEV_RANDOM
			// /dev/random

			static dev_random dev;
			dev.read(buffer);

#elif defined TORRENT_USE_LIBCRYPTO
			// openssl

			int r = RAND_bytes(reinterpret_cast<unsigned char*>(buffer.data())
				, int(buffer.size()));
			if (r != 1) aux::throw_ex<system_error>(errors::no_entropy);
#else
			// fallback

			for (auto& b : buffer) b = char(random(0xff));
#endif
		}
开发者ID:ajax16384,项目名称:libtorrent,代码行数:30,代码来源:random.cpp

示例5: DetectImageFormat

	ImageFileInfo DetectImageFormat(span<uint8_t> data) {
		ImageFileInfo info;

		stbi__context ctx;
		stbi__start_mem(&ctx, &data[0], data.size_bytes());

		int comp;
		if (stbi__bmp_info(&ctx, &info.width, &info.height, &comp)) {
			info.hasAlpha = (comp == 4);
			info.format = ImageFileFormat::BMP;
			return info;
		}

		TjDecompressHandle handle;
		if (tjDecompressHeader(handle, &data[0], data.size_bytes(), &info.width, &info.height) == 0) {
			info.hasAlpha = false;
			info.format = ImageFileFormat::JPEG;
			return info;
		}

		if (DetectTga(data, info)) {
			return info;
		}

		// Not a very good heuristic
		if (data.size() == 256 * 256) {
			info.width = 256;
			info.height = 256;
			info.hasAlpha = true;
			info.format = ImageFileFormat::FNTART;
			return info;
		}

		return info;
	}
开发者ID:pakoito,项目名称:TemplePlus,代码行数:35,代码来源:images.cpp

示例6: iterate_every_other_element

	void iterate_every_other_element(span<int, dynamic_range> av)
	{
		// pick every other element

		auto length = av.size() / 2;
#if _MSC_VER > 1800
		auto bounds = strided_bounds<1>({ length }, { 2 });
#else
		auto bounds = strided_bounds<1>(index<1>{ length }, index<1>{ 2 });
#endif
		strided_span<int, 1> strided(&av.data()[1], av.size() - 1, bounds);

		CHECK(strided.size() == length);
		CHECK(strided.bounds().index_bounds()[0] == length);
		for (auto i = 0; i < strided.size(); ++i)
		{
			CHECK(strided[i] == av[2 * i + 1]);
		}

		int idx = 0;
		for (auto num : strided)
		{
			CHECK(num == av[2 * idx + 1]);
			idx++;
		}
	}
开发者ID:hpesoj,项目名称:GSL,代码行数:26,代码来源:span_tests.cpp

示例7: LOGF

bool CommObject::SendFrame(span<const std::uint8_t> frame)
{
    if (frame.size() > CommMaxFrameSize)
    {
        LOGF(LOG_LEVEL_ERROR, "Frame payload is too long. Allowed: %d, Requested: '%d'.", CommMaxFrameSize, frame.size());
        return false;
    }

    uint8_t cmd[ComPrefferedBufferSize];
    cmd[0] = TransmitterSendFrame;
    memcpy(cmd + 1, frame.data(), frame.size());
    uint8_t remainingBufferSize;

    const bool status = (this->_low.WriteRead(CommTransmitter,           //
                             span<const uint8_t>(cmd, 1 + frame.size()), //
                             span<uint8_t>(&remainingBufferSize, 1)      //
                             ) == I2CResult::OK);
    if (!status)
    {
        LOG(LOG_LEVEL_ERROR, "[comm] Failed to send frame");
    }

    if (remainingBufferSize == 0xff)
    {
        LOG(LOG_LEVEL_ERROR, "[comm] Frame was not accepted by the transmitter.");
    }

    return status && remainingBufferSize != 0xff;
}
开发者ID:PW-Sat2,项目名称:PWSat2OBC,代码行数:29,代码来源:comm.cpp

示例8: enumerated_value_range

 explicit
 enumerated_value_range(span<const T> v)
 noexcept
     : _begin(v.data())
     , _end(v.data()+v.size())
 {
     assert(_begin <= _end);
 }
开发者ID:matus-chochlik,项目名称:oglplu2,代码行数:8,代码来源:enum_range.hpp

示例9: crypt_gen_random

	inline void crypt_gen_random(span<char> buffer)
	{
		static HCRYPTPROV provider = crypt_acquire_provider(PROV_RSA_FULL);
		if (!CryptGenRandom(provider, int(buffer.size())
			, reinterpret_cast<BYTE*>(buffer.data())))
		{
			throw_ex<system_error>(error_code(GetLastError(), system_category()));
		}
	}
开发者ID:gubatron,项目名称:libtorrent,代码行数:9,代码来源:win_crypto_provider.hpp

示例10: buffer

	// allocate an uninitialized buffer of the specified size
	// and copy the initialization range into the start of the buffer
	buffer(std::size_t const size, span<char const> initialize)
		: buffer(size)
	{
		TORRENT_ASSERT(initialize.size() <= size);
		if (!initialize.empty())
		{
			std::memcpy(m_begin, initialize.data(), (std::min)(initialize.size(), size));
		}
	}
开发者ID:ajax16384,项目名称:libtorrent,代码行数:11,代码来源:buffer.hpp

示例11: copy_buffer

	allocation_slot stack_allocator::copy_buffer(span<char const> buf)
	{
		int const ret = int(m_storage.size());
		int const size = int(buf.size());
		if (size < 1) return {};
		m_storage.resize(ret + size);
		std::memcpy(&m_storage[ret], buf.data(), numeric_cast<std::size_t>(size));
		return allocation_slot(ret);
	}
开发者ID:ajax16384,项目名称:libtorrent,代码行数:9,代码来源:stack_allocator.cpp

示例12:

	entry::entry(span<char const> v)
		: m_type(undefined_t)
	{
#if TORRENT_USE_ASSERTS
		m_type_queried = true;
#endif
		new(&data) string_type(v.data(), v.size());
		m_type = string_t;
	}
开发者ID:pavel-pimenov,项目名称:flylinkdc-r5xx,代码行数:9,代码来源:entry.cpp

示例13: upload

void GLVertexBuffer::upload(span<const byte> a_data)
{
	assert(GLStateBuffer::isBegun());
	assert(m_initialized);
	if (!a_data.empty())
	{
		glBindBuffer(GLenum(m_bufferType), m_id);
		glBufferData(GLenum(m_bufferType), a_data.length_bytes(), a_data.data(), GLenum(m_drawUsage));
	}
}
开发者ID:ocirne23,项目名称:GLEngine,代码行数:10,代码来源:GLVertexBuffer.cpp

示例14: bdecode

	entry bdecode(span<char const> buffer)
	{
		entry e;
		bool err = false;
		auto it = buffer.begin();
		detail::bdecode_recursive(it, buffer.end(), e, err, 0);
		TORRENT_ASSERT(e.m_type_queried == false);
		if (err) return entry();
		return e;
	}
开发者ID:pavel-pimenov,项目名称:flylinkdc-r5xx,代码行数:10,代码来源:entry.cpp

示例15: assign

void item::assign(entry v, span<char const> salt
	, sequence_number const seq
	, public_key const& pk, signature const& sig)
{

	m_pk = pk;
	m_sig = sig;
	m_salt.assign(salt.data(), salt.size());
	m_seq = seq;
	m_mutable = true;
	m_value = std::move(v);
}
开发者ID:krattai,项目名称:AEBL,代码行数:12,代码来源:item.cpp


注:本文中的span类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。