• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ smart_ptr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中smart_ptr的典型用法代码示例。如果您正苦于以下问题:C++ smart_ptr类的具体用法?C++ smart_ptr怎么用?C++ smart_ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了smart_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1:

template<class T, class U> inline bool operator!=(smart_ptr<T> & a, smart_ptr<U> & b)

{

return a.get() != b.get();

}
开发者ID:perry2008084,项目名称:TestCPP,代码行数:7,代码来源:Smart_Ptr.cpp


示例2: receiveChanged

	//Turns on and off standard and error logging
	void log::receiveChanged(smart_ptr<logStatusHolder> h)
	{
		if(h==&logStatus)
		{
			if(!std_log->getSpecialCase()) std_log->setIsOn(h->getSTDStatus());
			if(!err_log->getSpecialCase()) err_log->setIsOn(h->getERRStatus());
		}
	}
开发者ID:JonWBedard,项目名称:osMechanics,代码行数:9,代码来源:log.cpp


示例3: assert

void smart_ptr_tests::test_case_dereference()
{
    const smart_ptr<char> ptr1;
    assert(ptr1 == nullptr);
    assert(ptr1.use_count() == 0);

    const smart_ptr<char> ptr2(new char);
    *ptr2 = 123;
    assert(*ptr2 == 123);
}
开发者ID:yurai007,项目名称:my_shared_ptr,代码行数:10,代码来源:smart_ptr_tests.cpp


示例4: send

	//Send data
	bool UDPClient::send(smart_ptr<UDPPacket> pck)
	{
		if(!pck)
			return false;
		
		os::smart_ptr<uint8_t> sent = pck->sendData();
        sockaddr* cast;
        if(addr.isIPv6())
            cast= (sockaddr*) &ipv6_addr;
        else
            cast= (sockaddr*) &ipv4_addr;
		if (sendto(s, (char*)sent.get(), (int) (pck->getLength()+2), 0 , cast, slen) > 0)
			return true;
		return false;
	}
开发者ID:JonWBedard,项目名称:osMechanics,代码行数:16,代码来源:UDPClient.cpp


示例5: FillPreallocatedBuckets

int FillPreallocatedBuckets(smart_ptr<DhtImpl> &dhtObj, time_t rtt)
{
	int added = 0;

	DhtID dctr;
	DhtPeerID peerId;
	peerId.addr.set_port(128);
	peerId.addr.set_addr4(0xf0f0f0f0);

	for(int ctr=0; ctr<32; ++ctr)
	{
		dctr.id[4] = ctr;

		// put 8 nodes in the bucket
		for(int nodenum=0; nodenum<8; nodenum++)
		{
			// make a random myID
			for(int y=0; y<5; ++y)
				peerId.id.id[y] = rand();

			// copy the counter bits (5 bits) into the upper 5 bits of the id to be added
			// (to address the particular preallocated bucket)
			for(int x=0; x<5; ++x)
			{
				ProgramBit(peerId.id, 159-x, GetBit(dctr, 4-x));
			}

			// add the node
			(dhtObj->Update(peerId, 0, true, rtt))? ++added:0;
		}
	}
	return added;
}
开发者ID:tempbottle,项目名称:libbtdht,代码行数:33,代码来源:TestDHTRoutingTable.cpp


示例6: OverFillBuckets

int OverFillBuckets(smart_ptr<DhtImpl> &dhtObj, time_t rtt)
{
	int added = 0;
	DhtID dctr;
	DhtPeerID peerId;
	peerId.addr.set_port(128);
	peerId.addr.set_addr4(0xf0f0f0f0);
	int numPrefixBits;

	for(int bucketNum=0; bucketNum < dhtObj->_buckets.size(); ++bucketNum)
	{
		numPrefixBits = 160 - dhtObj->_buckets[bucketNum]->span;
		for(int ctr=0; ctr<16; ++ctr)
		{
			// copy "first"
			for(int y=0; y<5; ++y)
				peerId.id.id[y] = dhtObj->_buckets[bucketNum]->first.id[y];

			dctr.id[4] = ctr;
			// move the counter bits (4 bits) into the bits immediatly following the prefix bits
			// the bit range is 0 -> 159
			for(int x=0; x<4; ++x)
			{
				ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(dctr, 3-x));
			}
			(dhtObj->Update(peerId, 0, true, rtt))? ++added:0;
		}
	}
	return added;
}
开发者ID:tempbottle,项目名称:libbtdht,代码行数:30,代码来源:TestDHTRoutingTable.cpp


示例7: swap

inline void swap (smart_ptr<T> &pt, 
                  smart_ptr<T> &pt2)
{  
   typename smart_ptr<T>::value_type *ptr = pt.get();
   pt = pt2;
   pt2 = ptr;
}
开发者ID:Ruinland,项目名称:boost-doc-zh,代码行数:7,代码来源:smart_ptr.hpp


示例8:

  void
  calc_model_data_tmp_holder::save (const smart_ptr <calc_model> &cm)
  {
    pressure->assign (cm->pressure->begin (), cm->pressure->end ());
    saturation_3p->assign (cm->saturation_3p->begin (), cm->saturation_3p->end ());

    if (cm->is_gas ())
      {
        gas_oil_ratio->assign (cm->gas_oil_ratio->begin (), cm->gas_oil_ratio->end ());
        main_var.assign (cm->main_variable.begin (), cm->main_variable.end ());
      }
  }
开发者ID:bs-eagle,项目名称:bs-eagle,代码行数:12,代码来源:calc_model_data_tmp_holder.cpp


示例9: ID

/**
	Uses the dht's ID (myId) as the base for nodes to be added.  New nodes are always added
	to the bucket that contains myId thus forcing the split.  The dht buckets quit splitting
	once the span of the bucket containing myId reaches 3 (decending from 160).  At this
	there are only 8 possible ID's that can fill the 8 slots in the bucket.

	Note that the number of additions returned includes both new nodes added and existing
	nodes already in the list that are updated.
*/
int FillBucketList(smart_ptr<DhtImpl> &dhtObj, time_t rtt, SubPrefixType subPrefixType, int numPrefixBits = 0, int diff = 1)
{
	int added = 0;
	if(numPrefixBits >=160 || numPrefixBits < 0)
		return added;

	DhtID subPrefixBits;
	DhtPeerID peerId;
	peerId.addr.set_port(128);
	peerId.addr.set_addr4(0xf0f0f0f0);

	for(int ctr=0; ctr<16; ++ctr)
	{
		// copy myID
		for(int y=0; y<5; ++y)
			peerId.id.id[y] = dhtObj->_my_id.id[y];

		subPrefixBits.id[4] = subPrefixType==evenBitDistribution ? ctr : rand()*rand();
		if(subPrefixType==evenBitDistribution)
		{
			// move the counter bits (4 bits) into the bits immediatly following the prefix bits
			// the bit range is 0 -> 159
			for(int x=0; x<4; ++x)
			{
				ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(subPrefixBits, 3-x));
			}
		}
		else
		{
			for(int x=0; x<32; ++x)
			{
				ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(subPrefixBits, x));
			}
		}


		//dctr.id[4] = subPrefixType==evenBitDistribution ? ctr : rand()*rand();
		//// move the counter bits (4 bits) into the bits immediatly following the prefix bits
		//// the bit range is 0 -> 159
		//for(int x=0; x<32; ++x)
		//{
		//	ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(dctr, x));
		//}
		(dhtObj->Update(peerId, 0, true, rtt))? ++added:0;
	}
	added += FillBucketList(dhtObj, rtt, subPrefixType, numPrefixBits+diff, diff);

	return added;
}
开发者ID:tempbottle,项目名称:libbtdht,代码行数:58,代码来源:TestDHTRoutingTable.cpp


示例10:

inline bool operator>= (const smart_ptr<T1> &pt1, 
                        const smart_ptr<T2> &pt2)
{  return pt1.get() >= pt2.get();  }
开发者ID:Ruinland,项目名称:boost-doc-zh,代码行数:3,代码来源:smart_ptr.hpp


示例11: smart_ptr

 smart_ptr(const smart_ptr<Y> & r, detail::reinterpret_cast_tag)
    :  m_ptr(reinterpret_cast<PointedType*>(r.get()))
 {}
开发者ID:Ruinland,项目名称:boost-doc-zh,代码行数:3,代码来源:smart_ptr.hpp


示例12: uiRunExe

bool uiRunExe(wxFrame* parent,const wxString& path,const wxString& labelOutput, wxWindow* progressDialog,smart_ptr<InterfLogger> extLogger)
{
    _("Elapsed time : ");
    _("Remaining time : ");
    _("Close");
    _("Cancel");
    _("unknown");
    wxProgressDialog * progDialog=wxDynamicCast(progressDialog,wxProgressDialog);
    bool hasOutput=true;
    processManager* process = new processManager(parent,path);
    if(extLogger.get()!=NULL)
        process->AddLogger(extLogger);

    wxLogInfo(_("Execution d'un programme externe :"));
    wxLogInfo(path);

    int processId=wxExecute(path,wxEXEC_ASYNC,process);
    if(!processId)
    {
        wxLogInfo("L'execution du programme a échoué");
        delete process;
        return false;
    }
    float percFinish=0;
    wxDateTime lastProgShow=wxDateTime::UNow();
    while(process->IsRunning())
    {
        hasOutput=true;
        wxMilliSleep(50);
        while(hasOutput) //&& (!progDialog || progDialog->Update(percFinish*100))
        {
            process->LogOutput(hasOutput,labelOutput,&percFinish);
        }
        if(wxDateTime::UNow().GetValue()-lastProgShow.GetValue()>500)
        {
            lastProgShow=wxDateTime::UNow();
            if(parent)
                parent->Update();
            if(percFinish>99.f)
                percFinish=99;
            if(progDialog && !progDialog->Update(percFinish*100))
            {
                wxKillError killerror=wxProcess::Kill(processId,wxSIGKILL);
                wxLogInfo(_("Execution du programme externe annulé."));
                wxLogInfo(_("Réponse du processus :"));
                switch(killerror)
                {
                case wxKILL_OK:              // no error
                    wxLogInfo(_("Pas d'erreur."));
                    break;
                case wxKILL_BAD_SIGNAL:      // no such signal
                    wxLogError(_("Le signal n'existe pas."));
                    break;
                case wxKILL_ACCESS_DENIED:   // permission denied
                    wxLogError(_("Fermeture du processus non autorisée."));
                    break;
                case wxKILL_NO_PROCESS:      // no such process
                    wxLogError(_("Ce processus n'existe pas."));
                    break;
                case wxKILL_ERROR :           // another, unspecified error
                    wxLogError(_("Retour du processus non spécifié"));
                    break;
                default:
                    wxLogError(_("Retour du processus inconnue"));
                    break;
                }
                //Si on supprime le processus maintenant on aura une erreur
                //Si on ne le supprime pas il y a une fuite mémoire
                //delete process;
                return false;
            }
        }
    }
    // On récupère les derniers messages
    wxMilliSleep(150);
    process->LogOutput(hasOutput,labelOutput,&percFinish);
    while(hasOutput)
        process->LogOutput(hasOutput,labelOutput,&percFinish);
    delete process;
    return true;
}
开发者ID:JimmyFarcy,项目名称:I-Simpa,代码行数:81,代码来源:processManager.cpp


示例13:

	friend bool operator!= (const smart_ptr &left, nullptr_t)
	{
		return left.get() != nullptr;
	}
开发者ID:yurai007,项目名称:my_shared_ptr,代码行数:4,代码来源:complex_smart_ptr.hpp


示例14: bar

void bar(smart_ptr p) {
  delete p.get(); // expected-note{{Memory is released}}
  p.get()->foo(); // expected-note{{Calling 'smart_ptr::get'}}
}
开发者ID:LegalizeAdulthood,项目名称:clang,代码行数:4,代码来源:dtors.cpp


示例15: read_surface

ulong read_surface(
	const std::string& fname, ulong nx, ulong ny,
	smart_ptr< h5_pool_iface > pool, const std::string& surf_name = "",
	const bool invert_z = false
) {
	// set C locale for proper numbers reading
	setlocale(LC_NUMERIC, "C");

	// open file
	std::ifstream f(fname.c_str(), std::ios::in);
	if(!f) {
		BSERR << "Error opening file " << fname << bs_end;
		return 0;
	}

	std::string linebuf;
	std::istringstream line_s;
	//std::size_t pos;
	//t_float point[3];
	//ulong row, col;

	// setup buffer with dimensions passed
	ulong dims[3] = {nx, ny};
	spv_float databuf = BS_KERNEL.create_object(v_float::bs_type());
	databuf->resize(dims[0] * dims[1] * 3);
	std::fill(databuf->begin(), databuf->end(), 0.);

	// actually read file
	ulong n_points = 0;
	while(std::getline(f, linebuf)) {
		line_s.clear();

		// parse some info from comments
		if(linebuf[0] == '#') {
			if(linebuf.find("Information from grid:") != std::string::npos) {
				// EarthVision grid format
				n_points = read_earth_vision_grid(f, dims, databuf);
				break;
			}
			continue;
		}
		// skip ! comments
		if(linebuf[0] == '!') continue;

		if(linebuf.substr(0, 6) == "FSASCI") {
			// CPS-3 grid format
			n_points = read_cps3_grid(f, dims, databuf);
			break;
		}

		if(linebuf[0] == '@') {
			if(linebuf.find("grid") != std::string::npos) {
				// Zmap+grid format
				n_points = read_zmap_grid(f, dims, databuf);
				break;
			}
		}

		// try to read as Irap classic grid
		// TODO: impleent Irap reading
	}

	// restore locale
	setlocale(LC_NUMERIC, "");

	// check if we read nothing
	if(!n_points) {
		BSERR << "No valid data is read from " << fname << bs_end;
		return n_points;
	}
	else {
		BSOUT << "read_surface: succefully read " << n_points << " points from " << fname << bs_end;
	}

	// find out surface name
	std::string surf_name_ = surf_name;
	if(!surf_name.size()) {
		surf_name_ = fname.substr(0, fname.rfind('.'));
		const std::size_t slashpos = std::min(surf_name_.rfind('/'), surf_name_.rfind('\\'));
		if(slashpos != std::string::npos)
			surf_name_ = surf_name_.substr(slashpos + 1);
	}

	// write array to pool
	if(invert_z) {
		for(ulong i = 0; i < databuf->size() / 3; ++i) {
			databuf->ss(i*3 + 2) = -databuf->ss(i*3 + 2);
		}
	}
	//npy_intp h5p_dims[] = { 0, npy_intp(dims[0]), 0, npy_intp(dims[1]), 0, 1 };
	npy_intp h5p_dims[] = { npy_intp(dims[0]), npy_intp(dims[1]), 3 };
	//pool->declare_fp_data(surf_name_, 0, 3, &h5p_dims[0], 1);
	pool->declare_fp_data(surf_name_, 0, 3, &h5p_dims[0], 0);
	pool->set_fp_data(surf_name_, databuf);
	return n_points;
}
开发者ID:bs-eagle,项目名称:bs-eagle,代码行数:96,代码来源:surface_reader.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ socket类代码示例发布时间:2022-05-31
下一篇:
C++ slot_visitor类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap