本文整理汇总了C++中boost::weak_ptr::lock方法的典型用法代码示例。如果您正苦于以下问题:C++ weak_ptr::lock方法的具体用法?C++ weak_ptr::lock怎么用?C++ weak_ptr::lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::weak_ptr
的用法示例。
在下文中一共展示了weak_ptr::lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dump_wptr
void dump_wptr(void){
std::cout<<"sptr1 "<<sptr1.get()<<" use_count() "<<sptr1.use_count()<<" unique() "<<sptr1.unique()<<std::endl;
std::cout<<"sptr2 "<<sptr2.get()<<" use_count() "<<sptr2.use_count()<<" unique() "<<sptr2.unique()<<std::endl;
std::cout<<"weak ptr1 "<<wptr1.lock().get()<<std::endl;
std::cout<<"weak ptr2 "<<wptr2.lock().get()<<std::endl;
std::cout<<"weak ptr3 "<<wptr3.lock().get()<<std::endl;
}
示例2: weak_shared
void weak_shared(
boost::weak_ptr<FIRST>& first,
boost::shared_ptr<SECOND>& second
){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
int firstm = first.lock()->m_x;
int secondm = second->m_x;
save2(testfile, first, second);
// Clear the pointers, thereby destroying the objects they contain
first.reset();
second.reset();
load2(testfile, first, second);
// Check data member
BOOST_CHECK(firstm == first.lock()->m_x);
BOOST_CHECK(secondm == second->m_x);
// Check pointer to vtable
BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(first.lock()));
BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(second));
std::remove(testfile);
}
示例3: substreamTruncate
bool substreamTruncate(boost::weak_ptr<stream::sub> w_sub,
boost::weak_ptr<stream::seg> w_parent, int len)
{
stream::sub_sptr sub = w_sub.lock();
if (!sub) return false;
stream::seg_sptr parent = w_parent.lock();
if (!parent) return false;
stream::pos off = sub->get_offset();
stream::pos oldLen = sub->size();
// Enlarge the end of the substream (in the parent)
stream::delta delta = len - oldLen;
stream::pos orig = parent->tellp();
try {
if (delta < 0) {
// TODO: untested
parent->seekp(off + oldLen + delta, stream::start);
parent->remove(-delta);
} else {
parent->seekp(off + oldLen, stream::start);
parent->insert(delta);
}
// Update the substream with its new size
sub->resize(len);
} catch (stream::error& e) {
std::cerr << "Error resizing substream: " << e.what() << std::endl;
return false;
}
parent->seekp(orig, stream::start);
return true;
}
示例4:
Level::Level(boost::weak_ptr<Engine> engine) :
_tileSheetManager(engine.lock()->GetTileSheetManager()),
_gameObjectManager(engine.lock()->GetGameObjectManager()),
_physicsManager(engine.lock()->GetPhysicsManager()),
_InputManager(engine.lock()->GetInputManager()),
_engine(engine)
{
}
示例5: blockArrived
ProcessResult GetDisco::blockArrived(JabberDataBlockRef block, const ResourceContextRef rc){
ServiceDiscovery::ref sd=vf.lock();
if (!sd) return CANCEL;
if (block->getAttribute("id")==idinfo) {
if (block->getAttribute("type")=="result") {
sd->infoReply=block->findChildNamespace("query", "http://jabber.org/protocol/disco#info");
} else {
if (block->getAttribute("type")=="error") {
sd->infoReply=block->getChildByName("error");
}
}
SendMessage(sd->getHWnd(), WM_NOTIFY_BLOCKARRIVED, 0,0);
return BLOCK_PROCESSED;
}
if (block->getAttribute("id")==iditems) {
if (block->getAttribute("type")=="result") {
sd->itemReply=block->findChildNamespace("query", "http://jabber.org/protocol/disco#items");
} else {
if (block->getAttribute("type")=="error") {
sd->itemReply=block->getChildByName("error");
}
}
SendMessage(sd->getHWnd(), WM_NOTIFY_BLOCKARRIVED, 0,0);
return LAST_BLOCK_PROCESSED;
}
return BLOCK_REJECTED;
}
示例6: eventOk
void DiscoListView::eventOk() {
ServiceDiscovery::ref sd=serviceDiscovery.lock();
if (!sd) return;
DiscoItem::ref c=boost::dynamic_pointer_cast<DiscoItem> (cursorPos);
if (c) {
sd->discoverJid(c->jid, c->node);
sd->go();
return;
}
DiscoCommand::ref dc=boost::dynamic_pointer_cast<DiscoCommand> (cursorPos);
if (dc) {
switch (dc->cmdId) {
case DiscoCommand::BACK:
sd->back();
return;
case DiscoCommand::VCARD:
sd->vcard();
return;
case DiscoCommand::JOINGC:
sd->joingc();
return;
case DiscoCommand::EXECUTE:
sd->execute();
return;
case DiscoCommand::REGISTER:
sd->registerForm();
}
}
VirtualListView::eventOk();
}
示例7: x
boost::shared_ptr<Loader> Loader::instance() {
static boost::weak_ptr<Loader> _instance;
if(boost::shared_ptr<Loader> r = _instance.lock()) return r;
boost::shared_ptr<Loader> x(new (nothrow) Loader);
_instance = x;
return x;
}
示例8: runInThread
void runInThread()
{
pid_t tid = gettid();
boost::shared_ptr<pid_t> ptid = wkTid_.lock();
if (ptid)
{
*ptid = tid;
ptid.reset();
}
Rabbit::CurrentThread::t_threadName = name_.empty() ? "RabbitThread" : name_.c_str();
try
{
func_();
Rabbit::CurrentThread::t_threadName = "finished";
}
catch (...)
{
Rabbit::CurrentThread::t_threadName = "crashed";
fprintf(stderr, "some exception caught in Thread %s\n", name_.c_str());
perror("");
abort();
}
}
示例9: runInThread
void runInThread()
{
pid_t tid = pai::concurrency::CurrentThread::tid();
boost::shared_ptr<pid_t> ptid = wkTid_.lock();
if (ptid)
{
*ptid = tid;
ptid.reset();
}
pai::concurrency::CurrentThread::t_threadName = name_.empty() ? "paiThread" : name_.c_str();
::prctl(PR_SET_NAME, pai::concurrency::CurrentThread::t_threadName);
try
{
func_();
pai::concurrency::CurrentThread::t_threadName = "finished";
} catch (const std::exception& ex)
{
pai::concurrency::CurrentThread::t_threadName = "crashed";
fprintf(stderr, "exception caught in Thread %s\n", name_.c_str());
fprintf(stderr, "reason: %s\n", ex.what());
abort();
} catch (...)
{
pai::concurrency::CurrentThread::t_threadName = "crashed";
fprintf(stderr, "unknown exception caught in Thread %s\n", name_.c_str());
throw; // rethrow
}
}
示例10: runInThread
void runInThread()
{
DWORD tid = GetCurrentThreadId();
boost::shared_ptr<DWORD> ptid = wkTid_.lock();
if (ptid)
{
//set thread Id
*ptid = tid;
ptid.reset();
}
if (name_.empty())
name_ = "zyThread";
try
{
func_();
name_ += "finished";
}
catch (const std::exception & ex)
{
fprintf(stderr, "exception caught in Thread %s\n", name_.c_str());
fprintf(stderr, "reason: %s\n", ex.what());
name_ += "crashed";
abort();
}
catch (...)
{
fprintf(stderr, "unknown exception caught in Thread %s \n", name_.c_str());
name_ += "crashed";
throw;
}
}
示例11: operator
bool operator()(boost::weak_ptr<T> arg) const {
boost::shared_ptr<T> sp=arg.lock();
if (!sp) {
return false;
}
return func_(*sp,t_);
}
示例12:
http_seed_connection::http_seed_connection(
session_impl& ses
, boost::weak_ptr<torrent> t
, boost::shared_ptr<socket_type> s
, tcp::endpoint const& remote
, std::string const& url
, policy::peer* peerinfo
, std::string const& auth
, web_seed_entry::headers_t const& extra_headers)
: web_connection_base(ses, t, s, remote, url, peerinfo, auth, extra_headers)
, m_url(url)
, m_response_left(0)
, m_chunk_pos(0)
, m_partial_chunk_header(0)
{
INVARIANT_CHECK;
if (!ses.settings().report_web_seed_downloads)
ignore_stats(true);
shared_ptr<torrent> tor = t.lock();
TORRENT_ASSERT(tor);
int blocks_per_piece = tor->torrent_file().piece_length() / tor->block_size();
// multiply with the blocks per piece since that many requests are
// merged into one http request
m_max_out_request_queue = ses.settings().urlseed_pipeline_size
* blocks_per_piece;
prefer_whole_pieces(1);
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("*** http_seed_connection");
#endif
}
示例13: TimerEntry
void PeerSet::TimerEntry (boost::weak_ptr<PeerSet> wptr, const boost::system::error_code& result)
{
if (result == boost::asio::error::operation_aborted)
return;
boost::shared_ptr<PeerSet> ptr = wptr.lock ();
if (ptr)
{
if (ptr->mTxnData)
{
getApp().getJobQueue ().addJob (jtTXN_DATA, "timerEntryTxn",
BIND_TYPE (&PeerSet::TimerJobEntry, P_1, ptr));
}
else
{
int jc = getApp().getJobQueue ().getJobCountTotal (jtLEDGER_DATA);
if (jc > 4)
{
WriteLog (lsDEBUG, InboundLedger) << "Deferring PeerSet timer due to load";
ptr->setTimer ();
}
else
getApp().getJobQueue ().addJob (jtLEDGER_DATA, "timerEntryLgr",
BIND_TYPE (&PeerSet::TimerJobEntry, P_1, ptr));
}
}
}
示例14: onServiceInfoResultIfExists
inline void onServiceInfoResultIfExists(Session_Service* s, qi::Future<qi::ServiceInfo> f,
long requestId, std::string protocol, boost::weak_ptr<Session_Service> self)
{
boost::shared_ptr<Session_Service> sself = self.lock();
if (sself)
sself->onServiceInfoResult(f, requestId, protocol);
}
示例15: RegisterVariable
void Settings::RegisterVariable( std::string name, boost::weak_ptr<BaseDator> dator )
{
boost::shared_ptr<BaseDator> real_dator = dator.lock();
StringMap::iterator it = unparsed_settings_map.find( name );
if( it != unparsed_settings_map.end() && real_dator )
{
std::string ret = real_dator->Set( it->second );
UpdateListeners( name, it->second, ret );
unparsed_settings_map.erase( it );
}
else {
DatorMap::iterator it = dator_map.find( name );
if( it != dator_map.end() && real_dator )
{
boost::shared_ptr<BaseDator> other_dator = it->second.lock();
if( other_dator ) {
std::string ret = real_dator->Set( other_dator->Get() );
UpdateListeners( name, real_dator->Get(), ret );
}
else {
dator_map.erase( it );
}
}
}
if( !dator.expired() ) {
dator_map.insert( std::make_pair( name, dator ) );
}
}