本文整理汇总了C++中entry类的典型用法代码示例。如果您正苦于以下问题:C++ entry类的具体用法?C++ entry怎么用?C++ entry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了entry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wx_entry_print
void wx_entry_print(entry e, int depth)
{
wxString padding(wxT(""));
switch(e.type())
{
case entry::int_t:
wxLogMessage(wxT("print:")+padding.Pad(depth, '\t')+wxString::Format(_T("int: %u"), e.integer()));
break;
case entry::string_t:
wxLogMessage(wxT("print:")+padding.Pad(depth, '\t')+wxString::Format(wxT("str-len: %u "), e.string().length())+wxT("str: ")+wxString(e.string().c_str(), wxConvUTF8));
break;
case entry::list_t:
for (entry::list_type::const_iterator i = e.list().begin(); i != e.list().end(); ++i)
{
wx_entry_print(*i, depth+1);
}
break;
case entry::dictionary_t:
for (entry::dictionary_type::const_iterator i = e.dict().begin(); i != e.dict().end(); ++i)
{
wx_entry_print(i->first, depth+1);// write key
wx_entry_print(i->second, depth+1);// write value
}
break;
default:
break;
}
}
示例2: start
void dht_tracker::start(entry const& bootstrap)
{
std::vector<udp::endpoint> initial_nodes;
if (bootstrap.type() == entry::dictionary_t)
{
try
{
if (entry const* nodes = bootstrap.find_key("nodes"))
read_endpoint_list<udp::endpoint>(nodes, initial_nodes);
} catch (std::exception&) {}
}
error_code ec;
m_timer.expires_from_now(seconds(1), ec);
m_timer.async_wait(bind(&dht_tracker::tick, self(), _1));
m_connection_timer.expires_from_now(seconds(10), ec);
m_connection_timer.async_wait(
bind(&dht_tracker::connection_timeout, self(), _1));
m_refresh_timer.expires_from_now(seconds(5), ec);
m_refresh_timer.async_wait(bind(&dht_tracker::refresh_timeout, self(), _1));
m_dht.bootstrap(initial_nodes, boost::bind(&dht_tracker::on_bootstrap, self()));
}
示例3: swap
void entry::swap(entry& e)
{
bool clear_this = false;
bool clear_that = false;
if (m_type == undefined_t && e.m_type == undefined_t)
return;
if (m_type == undefined_t)
{
construct((data_type)e.m_type);
clear_that = true;
}
if (e.m_type == undefined_t)
{
e.construct((data_type)m_type);
clear_this = true;
}
if (m_type == e.m_type)
{
switch (m_type)
{
case int_t:
std::swap(*reinterpret_cast<integer_type*>(data)
, *reinterpret_cast<integer_type*>(e.data));
break;
case string_t:
std::swap(*reinterpret_cast<string_type*>(data)
, *reinterpret_cast<string_type*>(e.data));
break;
case list_t:
std::swap(*reinterpret_cast<list_type*>(data)
, *reinterpret_cast<list_type*>(e.data));
break;
case dictionary_t:
std::swap(*reinterpret_cast<dictionary_type*>(data)
, *reinterpret_cast<dictionary_type*>(e.data));
break;
default:
break;
}
if (clear_this)
destruct();
if (clear_that)
e.destruct();
}
else
{
// currently, only swapping entries of the same type or where one
// of the entries is uninitialized is supported.
TORRENT_ASSERT(false && "not implemented");
}
}
示例4: start
void dht_tracker::start(entry const& bootstrap)
{
std::vector<udp::endpoint> initial_nodes;
if (bootstrap.type() == entry::dictionary_t)
{
TORRENT_TRY {
if (entry const* nodes = bootstrap.find_key("nodes"))
read_endpoint_list<udp::endpoint>(nodes, initial_nodes);
} TORRENT_CATCH(std::exception&) {}
}
示例5: write_entry
static void write_entry(serializer & s, entry const & e) {
s << static_cast<char>(e.kind()) << e.overload() << e.parse_only() << e.get_expr();
if (e.is_numeral()) {
s << e.get_num();
} else {
s << static_cast<char>(e.group()) << length(e.get_transitions());
for (auto const & t : e.get_transitions())
s << t;
s << e.priority();
}
}
示例6: fillstr
strings fillstr(entry& e) {
// oh this is so stupid. Normalise requires strings, which it then countpaths
// for me. So I have to take my clean-room hashes and recreate the strings so
// that normalise can turn them back into hashes.
strings ss;
for(entry::const_iterator i = e.begin(); i!=e.end(); i++) {
for(int j = 0; j < (int)i->second; j++) {
ss.push_back(i->first);
}
}
return ss;
}
示例7: TORRENT_ASSERT
void dht_tracker::start(entry const& bootstrap
, find_data::nodes_callback const& f)
{
TORRENT_ASSERT(m_ses.is_network_thread());
std::vector<udp::endpoint> initial_nodes;
if (bootstrap.type() == entry::dictionary_t)
{
TORRENT_TRY {
if (entry const* nodes = bootstrap.find_key("nodes"))
read_endpoint_list<udp::endpoint>(nodes, initial_nodes);
} TORRENT_CATCH(std::exception&) {}
}
示例8: copy
void entry::copy(entry const& e)
{
switch (e.type())
{
case int_t:
new (&data) integer_type(e.integer());
break;
case string_t:
new (&data) string_type(e.string());
break;
case list_t:
new (&data) list_type(e.list());
break;
case dictionary_t:
new (&data) dictionary_type(e.dict());
break;
case undefined_t:
TORRENT_ASSERT(e.type() == undefined_t);
break;
case preformatted_t:
new (&data) preformatted_type(e.preformatted());
break;
}
m_type = e.type();
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
}
示例9: TORRENT_ASSERT_PRECOND
torrent_handle session_handle::add_torrent(
char const* tracker_url
, sha1_hash const& info_hash
, char const* name
, std::string const& save_path
, entry const& resume_data
, storage_mode_t storage_mode
, bool paused
, storage_constructor_type sc
, void* userdata)
{
TORRENT_ASSERT_PRECOND(!save_path.empty());
add_torrent_params p(sc);
p.trackers.push_back(tracker_url);
p.info_hash = info_hash;
p.save_path = save_path;
p.storage_mode = storage_mode;
if (paused) p.flags |= add_torrent_params::flag_paused;
else p.flags &= ~add_torrent_params::flag_paused;
p.userdata = userdata;
p.name = name;
if (resume_data.type() != entry::undefined_t)
{
bencode(std::back_inserter(p.resume_data), resume_data);
}
return add_torrent(p);
}
示例10: convert0
static object convert0(entry const& e)
{
switch (e.type())
{
case entry::int_t:
return object(e.integer());
case entry::string_t:
return object(e.string());
case entry::list_t:
return convert(e.list());
case entry::dictionary_t:
return convert(e.dict());
default:
return object();
}
}
示例11: extract_single_file
void extract_single_file(const entry& dict, file_entry& target
, std::string const& root_dir)
{
target.size = dict["length"].integer();
target.path = root_dir;
// prefer the name.utf-8
// because if it exists, it is more
// likely to be correctly encoded
const entry::list_type* list = 0;
if (entry const* p = dict.find_key("path.utf-8"))
{
list = &p->list();
}
else
{
list = &dict["path"].list();
}
for (entry::list_type::const_iterator i = list->begin();
i != list->end(); ++i)
{
if (i->string() != "..")
target.path /= i->string();
}
verify_encoding(target);
if (target.path.is_complete()) throw std::runtime_error("torrent contains "
"a file with an absolute path: '"
+ target.path.native_file_string() + "'");
}
示例12: cache_
void repository::builder::unpack_source(
const entry &package, const boost::filesystem::path &destination,
snapshot &snapshot_) {
BUNSAN_LOG_DEBUG << "Starting " << package << " import unpack";
const index deps = cache_().read_index(package);
// extract sources
for (const auto &i : deps.source.self)
extractor_().extract_source(package, i.source, destination / i.path);
// dump package checksum into snapshot
{
const auto iter = snapshot_.find(package);
const snapshot_entry checksum = cache_().read_checksum(package);
if (iter != snapshot_.end())
BOOST_ASSERT(iter->second == checksum);
else
snapshot_[package.name()] = checksum;
}
// extract source imports
for (const auto &i : deps.source.import.source)
unpack_source(i.package, destination / i.path, snapshot_);
// extract package imports
for (const auto &i : deps.source.import.package) {
extractor_().extract_installation(i.package, destination / i.path);
merge_maps(snapshot_, cache_().read_installation_snapshot(i.package));
}
}
示例13: fail
bool http_tracker_connection::extract_peer_info(const entry& info, peer_entry& ret)
{
// extract peer id (if any)
if (info.type() != entry::dictionary_t)
{
fail(-1, "invalid response from tracker (invalid peer entry)");
return false;
}
entry const* i = info.find_key("peer id");
if (i != 0)
{
if (i->type() != entry::string_t || i->string().length() != 20)
{
fail(-1, "invalid response from tracker (invalid peer id)");
return false;
}
std::copy(i->string().begin(), i->string().end(), ret.pid.begin());
}
else
{
// if there's no peer_id, just initialize it to a bunch of zeroes
std::fill_n(ret.pid.begin(), 20, 0);
}
// extract ip
i = info.find_key("ip");
if (i == 0 || i->type() != entry::string_t)
{
fail(-1, "invalid response from tracker");
return false;
}
ret.ip = i->string();
// extract port
i = info.find_key("port");
if (i == 0 || i->type() != entry::int_t)
{
fail(-1, "invalid response from tracker");
return false;
}
ret.port = (unsigned short)i->integer();
return true;
}
示例14: integer
bool entry::operator==(entry const& e) const
{
if (m_type != e.m_type) return false;
switch(m_type)
{
case int_t:
return integer() == e.integer();
case string_t:
return string() == e.string();
case list_t:
return list() == e.list();
case dictionary_t:
return dict() == e.dict();
default:
assert(m_type == undefined_t);
return true;
}
}
示例15: bencode_recursive
int bencode_recursive(OutIt& out, const entry& e)
{
int ret = 0;
switch(e.type())
{
case entry::int_t:
write_char(out, 'i');
ret += write_integer(out, e.integer());
write_char(out, 'e');
ret += 2;
break;
case entry::string_t:
ret += write_integer(out, e.string().length());
write_char(out, ':');
ret += write_string(e.string(), out);
ret += 1;
break;
case entry::list_t:
write_char(out, 'l');
for (entry::list_type::const_iterator i = e.list().begin(); i != e.list().end(); ++i)
ret += bencode_recursive(out, *i);
write_char(out, 'e');
ret += 2;
break;
case entry::dictionary_t:
write_char(out, 'd');
for (entry::dictionary_type::const_iterator i = e.dict().begin();
i != e.dict().end(); ++i)
{
// write key
ret += write_integer(out, i->first.length());
write_char(out, ':');
ret += write_string(i->first, out);
// write value
ret += bencode_recursive(out, i->second);
ret += 1;
}
write_char(out, 'e');
ret += 2;
break;
default:
// trying to encode a structure with uninitialized values!
TORRENT_ASSERT_VAL(false, e.type());
// do nothing
break;
}
return ret;
}