本文整理汇总了C++中lazy_entry::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ lazy_entry::clear方法的具体用法?C++ lazy_entry::clear怎么用?C++ lazy_entry::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lazy_entry
的用法示例。
在下文中一共展示了lazy_entry::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lazy_bdecode
// return 0 = success
int lazy_bdecode(char const* start, char const* end, lazy_entry& ret
, error_code& ec, int* error_pos, int depth_limit, int item_limit)
{
char const* const orig_start = start;
ret.clear();
std::vector<lazy_entry*> stack;
if (start == end)
TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
stack.push_back(&ret);
while (start <= end)
{
if (stack.empty()) break; // done!
lazy_entry* top = stack.back();
if (int(stack.size()) > depth_limit) TORRENT_FAIL_BDECODE(bdecode_errors::depth_exceeded);
if (start >= end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
char t = *start;
++start;
if (start >= end && t != 'e') TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
switch (top->type())
{
case lazy_entry::dict_t:
{
if (t == 'e')
{
top->set_end(start);
stack.pop_back();
continue;
}
if (!numeric(t)) TORRENT_FAIL_BDECODE(bdecode_errors::expected_digit);
std::int64_t len = t - '0';
bdecode_errors::error_code_enum e = bdecode_errors::no_error;
start = parse_int(start, end, ':', len, e);
if (e)
TORRENT_FAIL_BDECODE(e);
// remaining buffer size excluding ':'
const ptrdiff_t buff_size = end - start - 1;
if (len > buff_size)
TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
if (len < 0)
TORRENT_FAIL_BDECODE(bdecode_errors::overflow);
++start;
if (start == end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
lazy_entry* ent = top->dict_append(start);
if (ent == nullptr) TORRENT_FAIL_BDECODE(boost::system::errc::not_enough_memory);
start += len;
if (start >= end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
stack.push_back(ent);
t = *start;
++start;
break;
}
case lazy_entry::list_t:
{
if (t == 'e')
{
top->set_end(start);
stack.pop_back();
continue;
}
lazy_entry* ent = top->list_append();
if (ent == nullptr) TORRENT_FAIL_BDECODE(boost::system::errc::not_enough_memory);
stack.push_back(ent);
break;
}
case lazy_entry::int_t:
case lazy_entry::string_t:
case lazy_entry::none_t:
break;
}
--item_limit;
if (item_limit <= 0) TORRENT_FAIL_BDECODE(bdecode_errors::limit_exceeded);
top = stack.back();
switch (t)
{
case 'd':
top->construct_dict(start - 1);
break;
case 'l':
top->construct_list(start - 1);
break;
case 'i':
{
char const* int_start = start;
start = find_char(start, end, 'e');
top->construct_int(int_start, start - int_start);
if (start == end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
TORRENT_ASSERT(*start == 'e');
++start;
//.........这里部分代码省略.........
示例2: lazy_bdecode
// return 0 = success
int lazy_bdecode(char const* start, char const* end, lazy_entry& ret
, error_code& ec, int* error_pos, int depth_limit, int item_limit)
{
char const* const orig_start = start;
ret.clear();
if (start == end) return 0;
std::vector<lazy_entry*> stack;
stack.push_back(&ret);
while (start < end)
{
if (stack.empty()) break; // done!
lazy_entry* top = stack.back();
if (int(stack.size()) > depth_limit) TORRENT_FAIL_BDECODE(errors::depth_exceeded);
if (start >= end) TORRENT_FAIL_BDECODE(errors::unexpected_eof);
char t = *start;
++start;
if (start >= end && t != 'e') TORRENT_FAIL_BDECODE(errors::unexpected_eof);
switch (top->type())
{
case lazy_entry::dict_t:
{
if (t == 'e')
{
top->set_end(start);
stack.pop_back();
continue;
}
if (!is_digit(t)) TORRENT_FAIL_BDECODE(errors::expected_string);
boost::int64_t len = t - '0';
start = parse_int(start, end, ':', len);
if (start == 0 || start + len + 3 > end || *start != ':')
TORRENT_FAIL_BDECODE(errors::expected_colon);
++start;
if (start == end) TORRENT_FAIL_BDECODE(errors::unexpected_eof);
lazy_entry* ent = top->dict_append(start);
if (ent == 0) TORRENT_FAIL_BDECODE(errors::no_memory);
start += len;
if (start >= end) TORRENT_FAIL_BDECODE(errors::unexpected_eof);
stack.push_back(ent);
t = *start;
++start;
break;
}
case lazy_entry::list_t:
{
if (t == 'e')
{
top->set_end(start);
stack.pop_back();
continue;
}
lazy_entry* ent = top->list_append();
if (ent == 0) TORRENT_FAIL_BDECODE(errors::no_memory);
stack.push_back(ent);
break;
}
default: break;
}
--item_limit;
if (item_limit <= 0) TORRENT_FAIL_BDECODE(errors::limit_exceeded);
top = stack.back();
switch (t)
{
case 'd':
top->construct_dict(start - 1);
continue;
case 'l':
top->construct_list(start - 1);
continue;
case 'i':
{
char const* int_start = start;
start = find_char(start, end, 'e');
top->construct_int(int_start, start - int_start);
if (start == end) TORRENT_FAIL_BDECODE(errors::unexpected_eof);
TORRENT_ASSERT(*start == 'e');
++start;
stack.pop_back();
continue;
}
default:
{
if (!is_digit(t)) TORRENT_FAIL_BDECODE(errors::expected_value);
boost::int64_t len = t - '0';
start = parse_int(start, end, ':', len);
if (start == 0 || start + len + 1 > end || *start != ':')
TORRENT_FAIL_BDECODE(errors::expected_colon);
++start;
top->construct_string(start, int(len));
stack.pop_back();
start += len;
//.........这里部分代码省略.........