in_archive& fobj(gvl::shared_ptr<T>& v, Creator creator) { T* p; fobj(p, creator); v.reset(p); return *this; }
BooleanMappedValue BooleanValueImageExpanderEstimator::visit(SPnode * spn) const { #ifdef MYDEBUG std::cout << "in BooleanValueImageExpanderEstimator::visit, for " << spn->getNodeName() << std::endl; #endif // check if we need to split ivector box = spn->getBox(); #ifdef MYDEBUG std::cout << "this box is " << box << std::endl; #endif #ifdef MYDEBUG std::cout << "this tolerance is " << tolerance << std::endl; #endif interval thisRange = fobj(box); #ifdef MYDEBUG std::cout << "this range is " << thisRange << std::endl; #endif bool retValue = false; if ( !(Sup(thisRange) < infCriterion) && !(Inf(thisRange) > supCriterion) ) { // overlap retValue = true; #ifdef MYDEBUG_MIN std::cout << "overlap, returning true" << std::endl; #endif if ( (Sup(thisRange) > supCriterion) || (Inf(thisRange) < infCriterion) ) { //indet int maxdiamcomp; double maxDiam = MaxDiam (box, maxdiamcomp); // check if box max width is < tolerance, expand if not if (!(maxDiam < tolerance)) { spn->nodeExpand(); #ifdef MYDEBUG_MIN std::cout << "and max width >= tolerance " << std::endl; #endif } } // else thisRange is inside criterion } return BooleanMappedValue(retValue); }
bool operator() (const SPnode * const lhs, const SPnode * const rhs) const { //std::cout << "----doing comparisons" << endl; //std::cout << lhs->getNodeName() << "\t" << lhs->getBox() << "\t"; ivector lbox = lhs->getBox(); interval lRange = fobj(lbox); interval lArea = (lhs->nodeVolume()) * (lRange); //riemann sum //cout << "left area: " << lArea << endl; //std::cout << rhs->getNodeName() << "\t" << rhs->getBox() << "\t"; ivector rbox = rhs->getBox(); interval rRange = fobj(rbox); interval rArea = (rhs->nodeVolume()) * (rRange); //cout << "right area: " << rArea << endl; //cout << (diam(lArea)) << "\t" << (diam(rArea)) << endl; //the diameters are the uncertainty in the approximate to the integral error return (diam(lArea) < diam(rArea)); }
void serialize(std::string filepath) const { std::ofstream fobj(filepath); if(fobj) { for(const LightSource& source : _sources) { fobj << source.x_pos << " " << source.y_pos << " " << source.color << std::endl; } fobj.close(); } else std::cerr << "Couldn't serialize object." << std::endl; }
int main(void) { uint8_t space[1024], *last = space + sizeof(space); FILE *cfp = fopen("first.bin", "wb+"); flatten::file_t fobj(cfp); flatten::memfile_t mfobj(4096); flatten::segment_t<uint32_t> segment(0, 16); uint8_t *cur = segment.save<uint32_t, uint32_t>(space, last); const uint8_t *ccur = segment.load<uint32_t, uint32_t>(space, last); printf("cur = %p, ccur = %p\n", cur, ccur); fclose(cfp); return 0; }
cxsc::interval IntervalExpanderEstimator::visit(SPnode * spn) const { #ifdef MYDEBUG std::cout << "in IntervalExpanderEstimator::visit, for " << spn->getNodeName() << std::endl; #endif // check if we need to split ivector box = spn->getBox(); #ifdef MYDEBUG std::cout << "this box is " << box << std::endl; #endif interval thisRange = fobj(box); real thisMidImage = fobj.imageMid(box); #ifdef MYDEBUG std::cout << "this midImage is " << thisMidImage << std::endl; #endif #ifdef MYDEBUG std::cout << "this range is " << thisRange << std::endl; #endif #ifdef MYDEBUG std::cout << "this tolerance is " << tolerance << std::endl; #endif // split if so if (max(Sup(thisRange) - thisMidImage, thisMidImage - Inf(thisRange)) > tolerance) { spn->nodeExpand(); } #ifdef MYDEBUG_MIN if (!(max(Sup(thisRange) - thisMidImage, thisMidImage - Inf(thisRange)) > tolerance)) { std::cout << "no need to expand further: interval image <= tolerance " << std::endl; } #endif return thisRange; }
void get_best_nest(int nnest, int dim, Nest *best, Nest *new_Nest, Nest *Nests,double (*fobj)(int, double x[], int)){ int i, auxIndex; double auxMin=INFINITY; for (i = 0; i < nnest; i++) { double min = fobj(nnest, new_Nest[i].pos, dim); if(min < Nests[i].fx){ Nests[i].fx = min; memcpy(Nests[i].pos, new_Nest[i].pos, sizeof(Nests[i].pos)); } if(Nests[i].fx < auxMin){ auxMin = Nests[i].fx; auxIndex = i; } } memcpy(best->pos, Nests[auxIndex].pos, sizeof(best->pos)); best->fx = auxMin; }
BooleanMappedValue BooleanValueImageEstimator::visit(SPnode * spn) const { #ifdef MYDEBUG std::cout << "in BooleanValueImageEstimator::visit, for " << spn->getNodeName() << std::endl; #endif ivector box = spn->getBox(); #ifdef MYDEBUG std::cout << "this box is " << box << std::endl; #endif interval thisRange = fobj(box); #ifdef MYDEBUG std::cout << "this range is " << thisRange << std::endl; #endif return BooleanMappedValue( !(Sup(thisRange) < infCriterion) && !(Inf(thisRange) > supCriterion) ); }
z_status z_factory::load_obj_contents(zp_text_parser &parser,void* pObj,zf_feature_flags oper) { z_string s; init_dynamic(); z_status status=zs_ok; zf_obj fobj(this,pObj); while(status==zs_ok) { parser.skip_ws(); status=parser.test_any_identifier(); if(status==zs_no_match) return zs_ok; if(status) break; parser.get_match(s); zf_feature *f=_dynamic->features.get_by_name(s); if(!f) { return Z_ERROR_MSG(zs_feature_not_found,"Feature \"%s\" in not found in class \"%s\"",s.c_str(),get_name()); continue; } z_status status=parser.test_char('='); if(status) return Z_ERROR_MSG(status,"Expected '=' "); ZT("load feature=%s oper=%llx\n",s.c_str(),oper); status=f->load(parser,fobj,oper); if(status) { if(zs_skipped!=status) break; } } if(status==zs_eof) return zs_ok; return status;//Don't log error, should already be logged. }
CCreateData::CCreateData(int nTagCount) { if (nTagCount == 0) { return; } //在内存中生成数据 //实际生成100W条记录 int nUseCount = 1000 * 1000; //nTagCount == 1024 * 1024稍微大于1,000,000 CInfo *pInfo = new CInfo[nTagCount]; assert(pInfo); memset(pInfo, 0, sizeof(CInfo) * nTagCount); //集中管理学生信息对象的指针 CStudent **ptrStu = new CStudent *[nUseCount]; assert(ptrStu); //默认的偏移,就是索引大小,每次添加一个数据还要要加数据大小 int nOffset = sizeof(CInfo) * nTagCount; int i = 0; for (i = 0; i < nUseCount; i++) { ptrStu[i] = new CStudent(i+1, RandSex()); assert(ptrStu[i]); ptrStu[i]->SetID(i+1); ptrStu[i]->SetSex(RandSex()); ptrStu[i]->SetDate(RandDate()); ptrStu[i]->SetName(RandName()); pInfo[i].m_nLenght = sizeof(ptrStu[i]->GetID()) + sizeof(ptrStu[i]->GetSex()) + sizeof(ptrStu[i]->GetDate()) + ptrStu[i]->GetName().GetStrLen() + 1 + 4; //+1表示算上'\0' //+4表示存字符串长度的int pInfo[i].m_nOffset = nOffset; nOffset = nOffset + pInfo[i].m_nLenght; } COpFile fobj("Data.dat"); fobj.Seekp(0, ios::end);//文件打卡方式从app改为ate,所以加上Seekp fobj.Write(pInfo, sizeof(CInfo) * nTagCount); for (i = 0; i < nUseCount; i++) { //new一个临时空间,准备写学生信息用 //+4用于记录姓名长度 int nStuDataSize = pInfo[i].m_nLenght; char *ptrTmp = new char[nStuDataSize]; assert(ptrTmp); //学生信息写文件时用的类,姓名保存的是字符而非CMystring CStuToFile *ptrWrtF = (CStuToFile *)ptrTmp; ptrWrtF->SetID(ptrStu[i]->GetID()); ptrWrtF->SetSex(ptrStu[i]->GetSex()); ptrWrtF->SetDate(ptrStu[i]->GetDate()); ptrWrtF->SetName(ptrStu[i]->GetName()); fobj.Seekp(0, ios::end);//文件打卡方式从app改为ate,所以加上Seekp fobj.Write(ptrWrtF, nStuDataSize); delete[] ptrTmp; ptrTmp = NULL; } fobj.Close(); //释放资源 for (i = 0; i < nUseCount; i++) { if (ptrStu[i] != NULL) { delete ptrStu[i]; } } delete[] ptrStu; ptrStu = NULL; delete[] pInfo; pInfo = NULL; }
out_archive& fobj(gvl::shared_ptr<T>& v) { return fobj(v, 0); }
out_archive& fobj(gvl::shared_ptr<T>& v, Creator creator) { T* p = v.get(); return fobj(p); }
out_archive& fobj(T*& v) { return fobj(v, 0); }
in_archive& fobj(gvl::shared_ptr<T>& v) { return fobj(v, gvl::new_creator<T>()); }
in_archive& fobj(T*& v) { return fobj(v, gvl::new_creator<T>()); }