本文整理汇总了C++中span类的典型用法代码示例。如果您正苦于以下问题:C++ span类的具体用法?C++ span怎么用?C++ span使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了span类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: error_code
// this has to be thread safe and atomic. i.e. on posix systems it has to be
// turned into a series of pread() calls
std::int64_t file::readv(std::int64_t file_offset, span<iovec_t const> bufs
, error_code& ec, open_mode_t flags)
{
if (m_file_handle == INVALID_HANDLE_VALUE)
{
#ifdef TORRENT_WINDOWS
ec = error_code(ERROR_INVALID_HANDLE, system_category());
#else
ec = error_code(boost::system::errc::bad_file_descriptor, generic_category());
#endif
return -1;
}
TORRENT_ASSERT((m_open_mode & open_mode::rw_mask) == open_mode::read_only
|| (m_open_mode & open_mode::rw_mask) == open_mode::read_write);
TORRENT_ASSERT(!bufs.empty());
TORRENT_ASSERT(is_open());
#if TORRENT_USE_PREADV
TORRENT_UNUSED(flags);
std::int64_t ret = iov(&::preadv, native_handle(), file_offset, bufs, ec);
#else
// there's no point in coalescing single buffer writes
if (bufs.size() == 1)
{
flags &= ~open_mode::coalesce_buffers;
}
iovec_t tmp;
span<iovec_t const> tmp_bufs = bufs;
if (flags & open_mode::coalesce_buffers)
{
if (!coalesce_read_buffers(tmp_bufs, tmp))
// ok, that failed, don't coalesce this read
flags &= ~open_mode::coalesce_buffers;
}
#if TORRENT_USE_PREAD
std::int64_t ret = iov(&::pread, native_handle(), file_offset, tmp_bufs, ec);
#else
std::int64_t ret = iov(&::read, native_handle(), file_offset, tmp_bufs, ec);
#endif
if (flags & open_mode::coalesce_buffers)
coalesce_read_buffers_end(bufs
, tmp.data(), !ec);
#endif
return ret;
}
开发者ID:pavel-pimenov,项目名称:flylinkdc-r5xx,代码行数:52,代码来源:file.cpp
示例17: DecodeJpeg
std::unique_ptr<uint8_t[]> DecodeJpeg(const span<uint8_t> data) {
TjDecompressHandle handle;
int w, h;
tjDecompressHeader(handle, &data[0], data.size_bytes(), &w, &h);
std::unique_ptr<uint8_t[]> result(new uint8_t[w * h * 4]);
auto status = tjDecompress2(handle, &data[0], data.size_bytes(), &result[0], w, w * 4, h, TJPF_BGRX, 0);
if (status != 0) {
throw TempleException("Unable to decompress jpeg image: {}",
tjGetErrorStr());
}
return result;
}
开发者ID:pakoito,项目名称:TemplePlus,代码行数:14,代码来源:images.cpp
示例18: bencode
void item::assign(entry v, span<char const> salt
, sequence_number const seq, public_key const& pk, secret_key const& sk)
{
char buffer[1000];
int bsize = bencode(buffer, v);
TORRENT_ASSERT(bsize <= 1000);
m_sig = sign_mutable_item(span<char const>(buffer, bsize)
, salt, seq, pk, sk);
m_salt.assign(salt.data(), salt.size());
m_pk = pk;
m_seq = seq;
m_mutable = true;
m_value = std::move(v);
}
开发者ID:krattai,项目名称:AEBL,代码行数:14,代码来源:item.cpp
示例19: on_scrape_response
bool udp_tracker_connection::on_scrape_response(span<char const> buf)
{
using namespace libtorrent::aux;
restart_read_timeout();
int const action = aux::read_int32(buf);
std::uint32_t const transaction = read_uint32(buf);
if (transaction != m_transaction_id)
{
fail(error_code(errors::invalid_tracker_transaction_id));
return false;
}
if (action == action_error)
{
fail(error_code(errors::tracker_failure), -1
, std::string(buf.data(), buf.size()).c_str());
return true;
}
if (action != action_scrape)
{
fail(error_code(errors::invalid_tracker_action));
return true;
}
if (buf.size() < 12)
{
fail(error_code(errors::invalid_tracker_response_length));
return true;
}
int const complete = aux::read_int32(buf);
int const downloaded = aux::read_int32(buf);
int const incomplete = aux::read_int32(buf);
boost::shared_ptr<request_callback> cb = requester();
if (!cb)
{
close();
return true;
}
cb->tracker_scrape_response(tracker_req()
, complete, incomplete, downloaded, -1);
close();
return true;
}
开发者ID:michelmno,项目名称:libtorrent,代码行数:50,代码来源:udp_tracker_connection.cpp
示例20: random_bytes
void random_bytes(span<char> buffer)
{
#if TORRENT_USE_CRYPTOAPI
HCRYPTPROV prov;
if (!CryptAcquireContext(&prov, NULL, NULL
, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
#ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(GetLastError(), system_category()));
#else
std::terminate();
#endif
}
if (!CryptGenRandom(prov, int(buffer.size())
, reinterpret_cast<BYTE*>(buffer.data())))
{
CryptReleaseContext(prov, 0);
#ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(GetLastError(), system_category()));
#else
std::terminate();
#endif
}
CryptReleaseContext(prov, 0);
#elif defined TORRENT_USE_LIBCRYPTO
#ifdef TORRENT_MACOS_DEPRECATED_LIBCRYPTO
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
int r = RAND_bytes(reinterpret_cast<unsigned char*>(buffer.data())
, int(buffer.size()));
if (r != 1)
{
#ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(int(::ERR_get_error()), system_category()));
#else
std::terminate();
#endif
}
#ifdef TORRENT_MACOS_DEPRECATED_LIBCRYPTO
#pragma clang diagnostic pop
#endif
#else
for (auto& b : buffer) b = char(random(0xff));
#endif
}
开发者ID:krattai,项目名称:AEBL,代码行数:49,代码来源:random.cpp
注:本文中的span类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论