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


C++ lazy_entry::clear方法代码示例

本文整理汇总了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;
//.........这里部分代码省略.........
开发者ID:RealImage,项目名称:libtorrent,代码行数:101,代码来源:lazy_bdecode.cpp

示例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;
//.........这里部分代码省略.........
开发者ID:hammer,项目名称:genetorrent,代码行数:101,代码来源:lazy_bdecode.cpp


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