std::string prepared_item::to_string()

in src/native/diffs/core/prepared_item.cpp [211:301]


std::string prepared_item::to_string() const
{
	std::string str;

	str = "{result: ";
	str += m_item_definition.to_string();
	str += ", ";

	std::visit(
		overload{
			[&](reader_kind &reader)
			{
				str += "reader";

				if (reader.m_ingredients.empty())
				{
					return;
				}

				str += ", {ingredients: {";
				auto item = reader.m_ingredients.cbegin();
				while (item != reader.m_ingredients.cend())
				{
					str += (*item)->to_string();
					item++;
					if (item != reader.m_ingredients.cend())
					{
						str += ", ";
					}
				}
				str += "}";
			},
			[&](sequential_reader_kind &reader)
			{
				str += "sequential_reader";

				if (reader.m_ingredients.empty())
				{
					return;
				}

				str += ", {ingredients: {";
				auto item = reader.m_ingredients.cbegin();
				while (item != reader.m_ingredients.cend())
				{
					str += (*item)->to_string();
					item++;
					if (item != reader.m_ingredients.cend())
					{
						str += ", ";
					}
				}
				str += "}";
			},
			[&](slice_kind &slice)
			{
				str += "slice: {offset: ";
				str += std::to_string(slice.m_offset);
				str += ", length: ";
				str += std::to_string(slice.m_length);
				str += ", ";
				str += slice.m_item->to_string();
				str += "}";
			},
			[&](chain_kind &chain)
			{
				str += "chain: {";
				auto item = chain.m_items.cbegin();
				while (item != chain.m_items.cend())
				{
					str += (*item)->to_string();
					item++;
					if (item != chain.m_items.cend())
					{
						str += ", ";
					}
				}
				str += "}";
			},
			[&]([[maybe_unused]] fetch_slice_kind &fetch) { str += "kitchen_fetch_slice"; },
			[](auto)
			{
				throw errors::user_exception(
					errors::error_code::diffs_prepared_item_unkown, "Unknown kind when trying to convert to string.");
			},
		},
		m_kind);

	str += "}";
	return str;
}