template<class T, class U> inline bool operator!=(smart_ptr<T> & a, smart_ptr<U> & b) { return a.get() != b.get(); }
//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()); } }
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); }
//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; }
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; }
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; }
inline void swap (smart_ptr<T> &pt, smart_ptr<T> &pt2) { typename smart_ptr<T>::value_type *ptr = pt.get(); pt = pt2; pt2 = ptr; }
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 ()); } }
void calc_model_data_tmp_holder::restore (smart_ptr <calc_model> &cm) { cm->pressure->assign (pressure->begin (), pressure->end ()); cm->saturation_3p->assign (saturation_3p->begin (), saturation_3p->end ()); if (cm->is_gas ()) { cm->gas_oil_ratio->assign (gas_oil_ratio->begin (), gas_oil_ratio->end ()); cm->main_variable.assign (main_var.begin (), main_var.end ()); } }
/** 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; }
inline bool operator>= (const smart_ptr<T1> &pt1, const smart_ptr<T2> &pt2) { return pt1.get() >= pt2.get(); }
smart_ptr(const smart_ptr<Y> & r, detail::reinterpret_cast_tag) : m_ptr(reinterpret_cast<PointedType*>(r.get())) {}
smart_ptr(const smart_ptr<Y> & r, detail::dynamic_cast_tag) : m_ptr(dynamic_cast<PointedType*>(r.get())) {}
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; }
friend bool operator!= (const smart_ptr &left, nullptr_t) { return left.get() != nullptr; }
void bar(smart_ptr p) { delete p.get(); // expected-note{{Memory is released}} p.get()->foo(); // expected-note{{Calling 'smart_ptr::get'}} }
friend bool operator!= (nullptr_t, const smart_ptr &right) { return right.get() != nullptr; }
inline std::ptrdiff_t operator- (const smart_ptr<T> &pt, const smart_ptr<T2> &pt2) { return pt.get()- pt2.get(); }
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; }
friend bool operator!= (const smart_ptr &left, const smart_ptr &right) { return left.get() != right.get(); }