forked from premiere/premiere-libtorrent
clean up entry::print
This commit is contained in:
parent
2f43f2c428
commit
df3204874d
|
@ -228,10 +228,7 @@ namespace libtorrent
|
||||||
entry* find_key(std::string const& key);
|
entry* find_key(std::string const& key);
|
||||||
entry const* find_key(std::string const& key) const;
|
entry const* find_key(std::string const& key) const;
|
||||||
|
|
||||||
// TODO: could this be removed?
|
std::string to_string() const;
|
||||||
#if (defined TORRENT_VERBOSE_LOGGING || defined TORRENT_DEBUG) && TORRENT_USE_IOSTREAM
|
|
||||||
void print(std::ostream& os, int indent = 0) const;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -241,6 +238,8 @@ namespace libtorrent
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void to_string_impl(std::string& out, int indent) const;
|
||||||
|
|
||||||
#if (defined(_MSC_VER) && _MSC_VER < 1310) || TORRENT_COMPLETE_TYPES_REQUIRED
|
#if (defined(_MSC_VER) && _MSC_VER < 1310) || TORRENT_COMPLETE_TYPES_REQUIRED
|
||||||
// workaround for msvc-bug.
|
// workaround for msvc-bug.
|
||||||
// assumes sizeof(map<string, char>) == sizeof(map<string, entry>)
|
// assumes sizeof(map<string, char>) == sizeof(map<string, entry>)
|
||||||
|
@ -279,10 +278,10 @@ namespace libtorrent
|
||||||
mutable boost::uint8_t m_type_queried:1;
|
mutable boost::uint8_t m_type_queried:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
#if TORRENT_USE_IOSTREAM
|
||||||
inline std::ostream& operator<<(std::ostream& os, const entry& e)
|
inline std::ostream& operator<<(std::ostream& os, const entry& e)
|
||||||
{
|
{
|
||||||
e.print(os, 0);
|
os << e.to_string();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,8 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/pch.hpp"
|
#include "libtorrent/pch.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#if (defined TORRENT_VERBOSE_LOGGING || defined TORRENT_DEBUG) && TORRENT_USE_IOSTREAM
|
#if TORRENT_USE_IOSTREAM
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#endif
|
#endif
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
@ -42,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/config.hpp"
|
#include "libtorrent/config.hpp"
|
||||||
#include "libtorrent/escape_string.hpp"
|
#include "libtorrent/escape_string.hpp"
|
||||||
#include "libtorrent/lazy_entry.hpp"
|
#include "libtorrent/lazy_entry.hpp"
|
||||||
|
#include "libtorrent/escape_string.hpp"
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#define for if (false) {} else for
|
#define for if (false) {} else for
|
||||||
|
@ -495,15 +495,22 @@ namespace libtorrent
|
||||||
TORRENT_ASSERT(false);
|
TORRENT_ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined TORRENT_VERBOSE_LOGGING || defined TORRENT_DEBUG) && TORRENT_USE_IOSTREAM
|
std::string entry::to_string() const
|
||||||
void entry::print(std::ostream& os, int indent) const
|
{
|
||||||
|
std::string ret;
|
||||||
|
to_string_impl(ret, 0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::to_string_impl(std::string& out, int indent) const
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(indent >= 0);
|
TORRENT_ASSERT(indent >= 0);
|
||||||
for (int i = 0; i < indent; ++i) os << " ";
|
for (int i = 0; i < indent; ++i) out += " ";
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
case int_t:
|
case int_t:
|
||||||
os << integer() << "\n";
|
out += libtorrent::to_string(integer()).elems;
|
||||||
|
out += "\n";
|
||||||
break;
|
break;
|
||||||
case string_t:
|
case string_t:
|
||||||
{
|
{
|
||||||
|
@ -516,20 +523,28 @@ namespace libtorrent
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (binary_string) os << to_hex(string()) << "\n";
|
if (binary_string)
|
||||||
else os << string() << "\n";
|
{
|
||||||
|
out += to_hex(string());
|
||||||
|
out += "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out += string();
|
||||||
|
out += "\n";
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case list_t:
|
case list_t:
|
||||||
{
|
{
|
||||||
os << "list\n";
|
out += "list\n";
|
||||||
for (list_type::const_iterator i = list().begin(); i != list().end(); ++i)
|
for (list_type::const_iterator i = list().begin(); i != list().end(); ++i)
|
||||||
{
|
{
|
||||||
i->print(os, indent+1);
|
i->to_string_impl(out, indent+1);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case dictionary_t:
|
case dictionary_t:
|
||||||
{
|
{
|
||||||
os << "dictionary\n";
|
out += "dictionary\n";
|
||||||
for (dictionary_type::const_iterator i = dict().begin(); i != dict().end(); ++i)
|
for (dictionary_type::const_iterator i = dict().begin(); i != dict().end(); ++i)
|
||||||
{
|
{
|
||||||
bool binary_string = false;
|
bool binary_string = false;
|
||||||
|
@ -541,23 +556,22 @@ namespace libtorrent
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int j = 0; j < indent+1; ++j) os << " ";
|
for (int j = 0; j < indent+1; ++j) out += " ";
|
||||||
os << "[";
|
out += "[";
|
||||||
if (binary_string) os << to_hex(i->first);
|
if (binary_string) out += to_hex(i->first);
|
||||||
else os << i->first;
|
else out += i->first;
|
||||||
os << "]";
|
out += "]";
|
||||||
|
|
||||||
if (i->second.type() != entry::string_t
|
if (i->second.type() != entry::string_t
|
||||||
&& i->second.type() != entry::int_t)
|
&& i->second.type() != entry::int_t)
|
||||||
os << "\n";
|
out += "\n";
|
||||||
else os << " ";
|
else out += " ";
|
||||||
i->second.print(os, indent+2);
|
i->second.to_string_impl(out, indent+2);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
os << "<uninitialized>\n";
|
out += "<uninitialized>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,9 +125,7 @@ void test_feed(std::string const& filename, rss_expect const& expect)
|
||||||
f->save_state(state);
|
f->save_state(state);
|
||||||
|
|
||||||
fprintf(stderr, "feed_state:\n");
|
fprintf(stderr, "feed_state:\n");
|
||||||
#ifdef TORRENT_DEBUG
|
std::cerr << state.to_string() << "\n";
|
||||||
state.print(std::cerr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO: verify some key state is saved in 'state'
|
// TODO: verify some key state is saved in 'state'
|
||||||
}
|
}
|
||||||
|
|
|
@ -979,9 +979,8 @@ void test_fastresume(std::string const& test_path)
|
||||||
TEST_CHECK(!exists(combine_path(test_path, combine_path("tmp1", "temporary"))));
|
TEST_CHECK(!exists(combine_path(test_path, combine_path("tmp1", "temporary"))));
|
||||||
if (exists(combine_path(test_path, combine_path("tmp1", "temporary"))))
|
if (exists(combine_path(test_path, combine_path("tmp1", "temporary"))))
|
||||||
return;
|
return;
|
||||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
|
||||||
resume.print(std::cout);
|
std::cerr << resume.to_string() << "\n";
|
||||||
#endif
|
|
||||||
|
|
||||||
// make sure the fast resume check fails! since we removed the file
|
// make sure the fast resume check fails! since we removed the file
|
||||||
{
|
{
|
||||||
|
@ -1071,9 +1070,8 @@ void test_rename_file_in_fastresume(std::string const& test_path)
|
||||||
TEST_CHECK(!exists(combine_path(test_path, "tmp2/temporary")));
|
TEST_CHECK(!exists(combine_path(test_path, "tmp2/temporary")));
|
||||||
TEST_CHECK(exists(combine_path(test_path, "tmp2/testing_renamed_files")));
|
TEST_CHECK(exists(combine_path(test_path, "tmp2/testing_renamed_files")));
|
||||||
TEST_CHECK(resume.dict().find("mapped_files") != resume.dict().end());
|
TEST_CHECK(resume.dict().find("mapped_files") != resume.dict().end());
|
||||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
|
||||||
resume.print(std::cout);
|
std::cerr << resume.to_string() << "\n";
|
||||||
#endif
|
|
||||||
|
|
||||||
// make sure the fast resume check succeeds, even though we renamed the file
|
// make sure the fast resume check succeeds, even though we renamed the file
|
||||||
{
|
{
|
||||||
|
@ -1105,9 +1103,9 @@ void test_rename_file_in_fastresume(std::string const& test_path)
|
||||||
ses.remove_torrent(h);
|
ses.remove_torrent(h);
|
||||||
}
|
}
|
||||||
TEST_CHECK(resume.dict().find("mapped_files") != resume.dict().end());
|
TEST_CHECK(resume.dict().find("mapped_files") != resume.dict().end());
|
||||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
|
||||||
resume.print(std::cout);
|
std::cerr << resume.to_string() << "\n";
|
||||||
#endif
|
|
||||||
remove_all(combine_path(test_path, "tmp2"), ec);
|
remove_all(combine_path(test_path, "tmp2"), ec);
|
||||||
if (ec) std::cerr << "remove_all '" << combine_path(test_path, "tmp2")
|
if (ec) std::cerr << "remove_all '" << combine_path(test_path, "tmp2")
|
||||||
<< "': " << ec.message() << std::endl;
|
<< "': " << ec.message() << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue