void DMove::simulate(Conf const & pConf, Pos const pos, Dir const dir, kblock<R> & deltaFitness)const { Pos tPlace = 1; if(pos==0) tPlace = pos + 1; else tPlace = pos - 1; Point mTrial= pConf[tPlace]+ Lmodel::lm().DirVec(dir); for(Idx tIdx= 0; tIdx < Emodel::ModelCount(); ++tIdx) { R newDist = 0; R oldDist = 0; R tDelta = 0; for(Idx tCmp = 0; tCmp < Protein::Length() ; ++tCmp) { if(pConf.cacheEnabled(tIdx)) oldDist = pConf.cacheFitness(tCmp,pos,tIdx); else oldDist = Emodel::em(tIdx).Level(pConf,tCmp,pos); newDist = Emodel::em(tIdx).Level(tCmp,pConf[tCmp],pos,mTrial); tDelta = tDelta + newDist - oldDist; } deltaFitness[tIdx]=tDelta; } }
R DMove::simulate(Conf const & pConf, Pos const pos, Dir const dir,Idx const modelIdx)const { Pos tPlace = 1; if(pos==0) tPlace = pos + 1; else tPlace = pos - 1; Point mTrial= pConf[tPlace]+ Lmodel::lm().DirVec(dir); R newDist = 0; R oldDist = 0; R tDelta = 0; for(Cmp tCmp = 0; tCmp < Protein::Length() ; ++tCmp) { if(pConf.cacheEnabled(modelIdx)) oldDist = pConf.cacheFitness(tCmp,pos,modelIdx); else oldDist = Emodel::em(modelIdx).Level(pConf,tCmp,pos); newDist = Emodel::em(modelIdx).Level(tCmp,pConf[tCmp],pos,mTrial); tDelta = tDelta + newDist - oldDist; } return tDelta; }
int main(int argc, char *argv[]) { Conf c; DEWMA d; /* Path of the AP data file */ const char *curr_data_file; const char *next_data_file; /* IDs of the current AP and the next AP */ const char *curr_AP_id; const char *next_AP_id; /* DEWMA parameters */ double alpha; double gamma; const char *a; const char *g; /* Window to choose alpha and beta parameters */ int window; const char *w; if(argc != 8) { cerr << "Error: wrong command" << endl; cout << "Command: ./shs curr_AP_id next_AP_id curr_AP_data_file next_AP_data_file alpha gamma window" << endl; exit(1); } curr_AP_id = argv[1]; next_AP_id = argv[2]; curr_data_file = argv[3]; next_data_file = argv[4]; a = argv[5]; g = argv[6]; alpha = atof(argv[5]); gamma = atof(argv[6]); w = argv[7]; window = atoi(argv[7]); c.read_curr_AP(curr_data_file); c.read_next_AP(next_data_file); d.curr_forecast(curr_AP_id, alpha, gamma); d.next_forecast(next_AP_id, alpha, gamma); d.do_curr_forecast(window); d.write_do_curr_forecast(curr_AP_id, a, g, w); d.do_next_forecast(window); d.write_do_next_forecast(next_AP_id, a, g, w); /* Uncomment this function if you need to calculate the MSE value (or values) * Set the parameter 'use_window' of the 'prediction.cpp' file to FALSE */ d.MSE(); }
void Log::out(LogType type, const char *file, unsigned int line, const char *format, ...) { Conf *conf = Conf::instance(); if(!conf || conf->logLevel() < type) return; ostream *o = &cout; fstream f; if(!conf->logFile().empty()) { f.open(File::encodeName(conf->logFile()).c_str(), fstream::out|fstream::app); o = &f; } switch(type) { case ErrorType: *o << "ERROR"; break; case WarnType: *o << "WARN"; break; case InfoType: *o << "INFO"; break; case DebugType: *o << "DEBUG"; break; } *o << " [" << File::fileName(file) << ":" << line << "] - "; va_list args; va_start(args, format); *o << formatArgList(format, args).c_str() << "\n"; va_end(args); }
/* 取当前KEY对应的数据(包) * 注意,当数据有修改时,可能需是更新包的内容,所以 * 不返回const类型; */ Conf *Page::GetCurrentPack() { // 空,则先加载其值; if(NULL == m_pack) { const string &key = GetCurrentKey(); const string &username = m_request->GetCurrentUser(); UserData data( username ); Conf *pack = new Conf; if(NULL != pack) { Ini ini; // 填充一个空Conf,以便插入key对应的所有值; ini.Set(key, *pack); data.Get( ini ); pack->Set( *(ini.Get(key)) ); m_pack = pack; LOG_DEBUG("Pack[key:%s] loading... ok", key.c_str()); } } if(NULL == m_pack) { // 返回一空值,避免外部做过多的NULL检测; static Conf pack; return &pack; } return m_pack; }
/*! The constructor */ ACoreDistObj::ACoreDistObj(Conf const & theConf, B const NeedHint) : Function(theConf.SysHdl(), NeedHint) { WatchError //Alert(Energy::e().ModelId() != EnergyCls<HpEnergy>::ModelId, eEnergyMismatch); Dim tDimen = Space::Dimen(); Hdl tSysHdl = theConf.SysHdl(); Dim tSpan = Protein::p().Span(); Dim tLength = Protein::p().Length(); block1<Prm,nmm> tResult(tSpan * tLength / 2); block1<Prm,nmm> hCore(tDimen); for(Cmp tCmp = 0; tCmp < tDimen; ++tCmp) { block1<Prm,xmm> corePrms; for(Pos tPos = 0; tPos < tSpan; ++tPos) { Typ tTyp = Protein::p().Type(tPos); if (toHp[tTyp]==0) continue; corePrms.insertMem(Prm(TermVar,tPos * tDimen + tCmp)); } // now sum all the points Prm SumComp = Prm(TermFunc,SumXiFeVi::def(Xv, tSysHdl, corePrms.items(), corePrms.itemCount())); Prm CompVal = Prm(TermFunc,UdivXiFeVi::def(Xv,tSysHdl, SumComp,UdivXiFeVi::bind(corePrms.itemCount()))); hCore.insert(CompVal); } for(Pos tPos = 0; tPos < tSpan; ++tPos) { Typ tTyp = Protein::p().Type(tPos); if (toHp[tTyp]==0) continue; Prm tDiff[tDimen], tSqrd[tDimen]; for(Cmp tCmp = 0; tCmp < tDimen; ++tCmp) { Prm tVar1 = Prm(TermVar,tPos * tDimen + tCmp); Prm tVar2 = Prm(hCore[tCmp]); tDiff[tCmp] = Prm(TermFunc,BsubXiFeVi::def(Xv, tSysHdl, tVar1, tVar2)); tSqrd[tCmp] = Prm(TermFunc,UsqrXiFeVi::def(Xv, tSysHdl, tDiff[tCmp])); } tResult.insert(Prm(TermFunc,SumXiFeVi::def(Xv, tSysHdl, tSqrd, tDimen),ValueAsEvalMin)); } //mFuncHdl = SumXiFcMi::def(Xv, tSysHdl, tResult.items(), tResult.size()); //mMetricRec = &SumXiFcMi::ref(tSysHdl, mFuncHdl).MetricRec(); if (NeedHint) { mFuncHdl = SumXiEFcMiHn::def(Xv | EvalMin, tSysHdl, tResult.items(), tResult.itemCount()); mMetricRec = &SumXiEFcMiHn::refc(tSysHdl, mFuncHdl).MetricRec(); } else { mFuncHdl = SumXiFcMi::def(Xv, tSysHdl, tResult.items(), tResult.itemCount()); mMetricRec = &SumXiFcMi::refc(tSysHdl, mFuncHdl).MetricRec(); } CatchError }
openPlatypusSpace /*! The constructor */ PlusDistObj::PlusDistObj(Conf const & theConf, B const NeedHint) : Function(theConf.SysHdl(), NeedHint) { WatchError Warn(!(Energy::e().ModelId() != EnergyCls<MjEnergy>::ModelId || Energy::e().ModelId() != EnergyCls<BarerraEnergy>::ModelId), eEnergyMismatch); Z modelCutoff=(Energy::e().ModelId() == EnergyCls<MjEnergy>::ModelId)?0:-1000; Dim tDimen = Space::Dimen(); Hdl tSysHdl = theConf.SysHdl(); Dim tSpan = Protein::p().Span(); Dim tLength = Protein::p().Length(); block1<Prm,nmm> tResult(tSpan * tLength / 2); for(Pos tPos1 = 0; tPos1 < tSpan; ++tPos1) { Typ tTyp1 = Protein::p().Type(tPos1); //if (tTyp1 != Energy::e().Type(2, 'H')) continue; for(Pos tPos2 = tPos1 + 2; tPos2 < tLength; ++tPos2) { Typ tTyp2 = Protein::p().Type(tPos2); //if (tTyp2 != Energy::e().Type(2, 'H')) continue; if(Energy::e().Level(tTyp1,tTyp2)<=modelCutoff) continue; Prm tDiff[tDimen], tSqrd[tDimen]; for(Cmp tCmp = 0; tCmp < tDimen; ++tCmp) { Prm tVar1 = Prm(TermVar,tPos1 * tDimen + tCmp); Prm tVar2 = Prm(TermVar,tPos2 * tDimen + tCmp); tDiff[tCmp] = Prm(TermFunc,BsubXiFeVi::def(Xv, tSysHdl, tVar1, tVar2)); tSqrd[tCmp] = Prm(TermFunc,UsqrXiFeVi::def(Xv, tSysHdl, tDiff[tCmp])); } tResult.insert(Prm(TermFunc,SumXiFeVi::def(Xv, tSysHdl, tSqrd, tDimen),ValueAsEvalMin)); } } //mFuncHdl = SumXiFcMi::def(Xv, tSysHdl, tResult.items(), tResult.size()); //mMetricRec = &SumXiFcMi::ref(tSysHdl, mFuncHdl).MetricRec(); if (NeedHint) { mFuncHdl = SumXiEFcMiHn::def(Xv | EvalMin, tSysHdl, tResult.items(), tResult.itemCount()); mMetricRec = &SumXiEFcMiHn::refc(tSysHdl, mFuncHdl).MetricRec(); } else { mFuncHdl = SumXiFcMi::def(Xv, tSysHdl, tResult.items(), tResult.itemCount()); mMetricRec = &SumXiFcMi::refc(tSysHdl, mFuncHdl).MetricRec(); } CatchError }
virtual Conf default_conf() const { Conf conf; // Size can be small or large (small by default) conf.def_choice("size", {"large", "small"}, "small"); // lol can be between 0 and 1 (0 by default). conf.def_float("lol", 0.0, 1.0, 0.0); // negative is a logical value (true by default) conf.def_bool("add5", false); return conf; }
TcpServer::TcpServer() { //Read conf Conf config; this->svrPort = config.GetParameter("WEB/listen_port").toInt(); this->svrAddr = config.GetParameter("WEB/listen_ip").toString(); this->maxConnections = config.GetParameter("WEB/max_connections").toInt(); //qDebug() << "[TcpServer::TcpServer] Creating tcp server (" << this->svrAddr.toString() << "," << this->svrPort << "," << this->maxConnections << ")"; }
void VsBlockSize::setUp() { cout << " VsBlockSize::setUp()..." << endl; int x = 0; int total = blockSizes_.size(); for (size_t blockSize : blockSizes_) { x++; std::cout << " " << x << "/" << total << std::endl; string dbDirPath = "data"; string expName = str(boost::format("tweetDB%08d") % blockSize); string pathAndName = str(boost::format("data/tweetDB%08d") % blockSize); // Create tweetDB if its not there if( !(boost::filesystem::exists(pathAndName))) { boost::filesystem::create_directory(pathAndName); } #ifdef RECREATE // Clean up anything that is in the directory boost::filesystem::path path_to_remove(pathAndName); for (boost::filesystem::directory_iterator end_dir_it, it(path_to_remove); it!=end_dir_it; ++it) { remove_all(it->path()); } #endif // Create the graph conf, one for each block size Conf conf = ExpSetupHelper::createGraphConf(dbDirPath, expName); conf.setBlockSize(blockSize); conf.setBlockBufferSize(blockBufferSize_); confs_.push_back(conf); // Create a graph for each block size std::unique_ptr<core::InteractionGraph> graph; graph.reset(new InteractionGraph(conf)); graphs_.push_back(std::move(graph)); } cout << " done." << endl; cout << " populateGraphFromTweets..." << endl; ExpSetupHelper::populateGraphFromTweets( "data/tweets", graphs_, tsStart_, tsEnd_, vertices_); cout << " done." << endl; std::cout << "start " << tsStart_ << std::endl; std::cout << "stop " << tsEnd_ << std::endl; }
void SignatureDDOC::extendSignatureProfile(const string &) { Conf *c = Conf::instance(); if(!c->proxyHost().empty()) { d->lib->f_createOrReplacePrivateConfigItem(nullptr, "USE_PROXY", "true"); d->lib->f_createOrReplacePrivateConfigItem(nullptr, "DIGIDOC_PROXY_HOST", c->proxyHost().c_str()); d->lib->f_createOrReplacePrivateConfigItem(nullptr, "DIGIDOC_PROXY_PORT", c->proxyPort().c_str()); d->lib->f_createOrReplacePrivateConfigItem(nullptr, "DIGIDOC_PROXY_USER", c->proxyUser().c_str()); d->lib->f_createOrReplacePrivateConfigItem(nullptr, "DIGIDOC_PROXY_PASS", c->proxyPass().c_str()); } else d->lib->f_createOrReplacePrivateConfigItem(nullptr, "USE_PROXY", "false"); if(!c->PKCS12Disable()) { d->lib->f_createOrReplacePrivateConfigItem(nullptr, "SIGN_OCSP", "true"); d->lib->f_createOrReplacePrivateConfigItem(nullptr, "DIGIDOC_PKCS_FILE", c->PKCS12Cert().c_str()); d->lib->f_createOrReplacePrivateConfigItem(nullptr, "DIGIDOC_PKCS_PASSWD", c->PKCS12Pass().c_str()); } else d->lib->f_createOrReplacePrivateConfigItem(nullptr, "SIGN_OCSP", "false"); int err = d->lib->f_notarizeSignature(d->doc, s); d->throwSignError(s, err, "Failed to sign document", __LINE__); }
/** * * return * @throws SignatureException */ digidoc::OCSP::CertStatus digidoc::SignatureBES::validateOnline() const throw(SignatureException) { // FIXME: Add exception handling. // Get signing signature. X509Cert cert = getSigningCertificate(); // Get issuer certificate. X509* issuerCert = X509CertStore::getInstance()->getCert(*(cert.getIssuerNameAsn1())); X509_scope issuerCertScope(&issuerCert); if(issuerCert == NULL) { THROW_SIGNATUREEXCEPTION("Failed to load issuer certificate."); } Conf* conf = Conf::getInstance(); // Get OCSP responder certificate. // FIXME: throws IOException, handle it Conf::OCSPConf ocspConf = conf->getOCSP(cert.getIssuerName()); if(ocspConf.issuer.empty()) { SignatureException e(__FILE__, __LINE__, "Failed to find ocsp responder."); e.setCode( Exception::OCSPResponderMissing ); throw e; } STACK_OF(X509)* ocspCerts = X509Cert::loadX509Stack(ocspConf.cert); X509Stack_scope ocspCertsScope(&ocspCerts); // Check the certificate validity from OCSP server. try { OCSP ocsp; ocsp.setSkew(120);//XXX: load from conf ocsp.setOCSPCerts(ocspCerts); ocsp.setUrl(ocspConf.url); std::auto_ptr<Digest> calc = Digest::create(); calc->update(getSignatureValue()); return ocsp.checkCert(cert.getX509(), issuerCert, calc->getDigest()); } catch(const IOException& e) { THROW_SIGNATUREEXCEPTION("Failed to check the certificate validity from OCSP server."); } catch(const OCSPException& e) { THROW_SIGNATUREEXCEPTION("Failed to check the certificate validity from OCSP server."); } return digidoc::OCSP::GOOD; }
openPlatypusSpace /*! The constructor */ SideChainCns::SideChainCns(Conf const & theConf, B const NeedHint) : Function(theConf.SysHdl(), NeedHint) { WatchError Dim tDimen = Space::Dimen(); Hdl tSysHdl = theConf.SysHdl(); Dim tSpan = Protein::p().Span(); Dim tLength = Protein::p().Length(); block1<Prm,nmm> tResult(tSpan * tLength / 2); Int tSqrNeighDist = Lattice::l().SqrNeighDist(); for(Pos tPos1 = 0; tPos1 < tLength; ++tPos1) { Pos tPos2; if(tPos1<tLength/2) tPos2 = tPos1 + 1; else tPos2 = tPos1 - tLength/2; Prm tDiff[tDimen], tSqrd[tDimen]; for(Cmp tCmp = 0; tCmp < tDimen; ++tCmp) { Prm tVar1 = Prm(TermVar,tPos1 * tDimen + tCmp); Prm tVar2 = Prm(TermVar,tPos2 * tDimen + tCmp); tDiff[tCmp] = Prm(TermFunc,BsubXiFeVi::def(Xv, tSysHdl, tVar1, tVar2)); tSqrd[tCmp] = Prm(TermFunc,UsqrXiFeVi::def(Xv, tSysHdl, tDiff[tCmp])); } Prm tDist = Prm(TermFunc,SumXiFeVi::def(Xv, tSysHdl, tSqrd, tDimen)); tResult.insert(Prm(TermFunc,UequXiFcMi::def(Xv, tSysHdl, tDist, UequXiFcMi::bind(tSqrNeighDist)), MetricAsEvalMin)); } cout << tResult.itemCount() <<endl; if (NeedHint) { mFuncHdl = SumXiEFcMiHn::def(Xm | EvalMin, tSysHdl, tResult.items(), tResult.itemCount()); mMetricRec = &SumXiEFcMiHn::refc(tSysHdl, mFuncHdl).MetricRec(); } else { mFuncHdl = SumXiFcMi::def(Xm, tSysHdl, tResult.items(), tResult.itemCount()); mMetricRec = &SumXiFcMi::refc(tSysHdl, mFuncHdl).MetricRec(); } CatchError }
void Connect::sendProxyAuth() { Conf *c = Conf::instance(); if(c->proxyUser().empty() || c->proxyPass().empty()) return; BIO_printf(d, "Proxy-Authorization: Basic "); SCOPE(BIO, b64, BIO_new(BIO_f_base64())); BIO_set_flags(b64.get(), BIO_FLAGS_BASE64_NO_NL); BIO_push(b64.get(), d); BIO_printf(b64.get(), "%s:%s", c->proxyUser().c_str(), c->proxyPass().c_str()); (void)BIO_flush(b64.get()); BIO_pop(b64.get()); BIO_printf(d, "\r\n"); }
int main(int argc,char* argv[]) { //mytest(argc,argv); srandom(time(NULL)); processbase.mainbase_pid=getpid(); if(argc!=3||string(argv[1])!="mainbase") { DisplayUsage(); return -1; } my_argc=argc; my_argv=argv; signal(SIGCHLD,SIG_IGN); string errmsg; if(conf.LoadFromFile(argv[2],errmsg)==false) { kobe_printf("%s\tERROR: failed to load conf, %s\n",GetCurrentTime().c_str(), errmsg.c_str()); return -3; } conf.Display(); //---------------------------------------------- StartWatcher(argc,argv);//fork watcher StartSender(argc,argv);//fork sender my_role=ROLE_MAINBASE; //---------------------------------------------- atexit(mainbase_exit); //mainbase run //---------------------------------------------- main_el=aeCreateEventLoop(); if(main_el==NULL) { kobe_printf("%s\tERROR: failed to create event loop\n", GetCurrentTime().c_str()); return -1; } //---------------------------------------------- HTTPServerRun(); UnixSocketServerRun(); ProcessMonitorRun(); MainbaseLoopRun(); //---------------------------------------------- signal(SIGINT,mainbase_cleanup); aeMain(main_el); //---------------------------------------------- return 0; }
void SenderRun() { if(main_el!=NULL) { aeDeleteEventLoop(main_el); main_el=NULL; } //---------------------------------------------- atexit(sender_exit); //watcher run string errmsg; if(conf.LoadFromFile(my_argv[2],errmsg)==false) { kobe_printf("%s\tERROR: failed to load conf,%s\n",GetCurrentTime().c_str(), errmsg.c_str()); exit(-3); } //---------------------------------------------- sender=new Sender(conf); main_el=aeCreateEventLoop(); if(main_el==NULL) { kobe_printf("%s\tERROR: failed to create event loop\n", GetCurrentTime().c_str()); exit(-1); } //---------------------------------------------- UnixSocketServerRun(); //---------------------------------------------- signal(SIGINT,sender_cleanup); aeMain(main_el); }
int main(int nargs, char * vargs[]) { if(!single_instance_dmn(nargs, vargs,"pizu")) { return 0; } system("sync"); signal(SIGINT, ControlC); signal(SIGABRT, ControlC); signal(SIGKILL, ControlC); signal(SIGTRAP, SIG_IGN); signal(SIGPIPE, SIG_IGN); Conf f; f.load("pizu.conf"); GCFG = &f; Modules m; __modules = &m; //as well if(!m.is_not_empty()) { std::cout << "Cannot load modules. At least libhtml_mod.so should be build. \n"; return -1; } do { ThreadPool tpa(false); //asyncronous. replies that flows Listeners thel(&tpa); __pl = &thel; // ugly __tp = &tpa; if(thel.start_thread()!=0) break; if(tpa.start_thread()!=0) break; while( thel.san() && __alive) { usleep(0xFFFF); } } while(__alive); __tp = 0; __pl = 0; printf("ALL OBJECTS GONE \n"); return 0; }
//---------------------------------------------------------------------------- // main //---------------------------------------------------------------------------- int main() { Conf *conf = new Conf; ConfObj *o; o = 0; #include"modules_new.cpp" printf("ok\n"); bool success = false; if(conf->exec()) { QFile f("conf.pri"); if(!f.open(IO_WriteOnly | IO_Truncate)) { printf("Error writing %s\n", f.name().latin1()); return 1; } QString str; str += "# qconf\n"; str += "QT_PATH_PLUGINS = " + QString(qInstallPathPlugins()) + '\n'; if(!conf->DEFINES.isEmpty()) str += "DEFINES += " + conf->DEFINES + '\n'; if(!conf->INCLUDEPATH.isEmpty()) str += "INCLUDEPATH += " + conf->INCLUDEPATH + '\n'; if(!conf->LIBS.isEmpty()) str += "LIBS += " + conf->LIBS + '\n'; if(!conf->extra.isEmpty()) str += conf->extra; str += '\n'; char *p = getenv("BINDIR"); if(p) { str += QString("target.path = ") + p + '\n'; str += "INSTALLS += target\n"; } QCString cs = str.latin1(); f.writeBlock(cs.data(), cs.length()); f.close(); success = true; } delete conf; if(success) return 0; else return 1; }
// 统一处理保存(出便于同步处理缓存更新) int Page::Save(const Ini &pack) { const string &username = m_request->GetCurrentUser(); UserData save( username ); // 保存 if(save.Set( pack ) < 0) { return ERR; } // 更新缓存 const string &key = GetCurrentKey(); Conf *syn = GetCurrentPack(); syn->Set( *(pack.Get(key)) ); return OK; }
Property* PropertyImpl::Get(string _uid){ Conf* conf = Conf::GetInstance(); string pro = conf->find("DataBase", "Property"); Trace("SQL property: sql=%s", pro.c_str()); sql::PreparedStatement *pstmt = sql::PreparedStatement(pro); pstmt->SetString(1, _uid); sql::ResultSet* res = mysql_->Qurey(pstmt); if(NULL != res){ Property* property = new Property(); assert(NULL != property); //set property property->set_uid(_uid); property->set_hp(res->getInt("hp")); property->set_rank(res->getInt("rank")); property->set_faint(res->getInt("faint")); property->dress().set_id(res->getInt("dress_id")); property->dress().set_defense(res->getInt("dress_defens")); property->prop().set_id(res->getInt("prop_id")); property->prop().set_harm(res->getInt("harm")); property->energy().set_id(res->getInt("energy_id")); property->energy().set_defense(res->getInt("energy_defense")); property->energy().set_addhp(res->getInt("addhp")); delete pstmt; return property; }//ResultSet Error("Can't find this user: uid=%s", _uid.c_str()); return NULL; }//Get
/** * The entry point for console version of ShowGraph */ static int doAll( int argc, char **argv) { QApplication app(argc, argv); app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); Conf conf; conf.addOption( new Option( OPT_STRING, "f", "file", "input graph description file name")); conf.addOption( new Option( OPT_STRING, "o", "output", "output image file name")); conf.readArgs( argc, argv); Option *fopt = conf.longOption("file"); Option *out_opt = conf.longOption("output"); assertd( isNotNullP( fopt)); assertd( isNotNullP( out_opt)); if ( fopt->isDefined()) { QString xmlname = fopt->string(); QString outname("image.png"); Renderer r; if ( out_opt->isDefined()) { outname = out_opt->string(); } r.render( xmlname, outname); } else { conf.printOpts(); // Print options to console } //return app.exec(); return 0; }
void DMove::execute(Conf & pConf, Pos const pos, Dir const dir)const { Pos tPlace = 1; if(pos == 0) tPlace = pos +1; else tPlace = pos -1; Point mTrial = pConf[tPlace] + Lmodel::lm().DirVec(dir); for(Idx tIdx =0; tIdx < Emodel::ModelCount(); ++tIdx) { R tDelta = 0; R oldDist =0; R newDist = 0; for(Idx tCmp = 0 ; tCmp < Protein::Length(); ++tCmp) { if(pConf.cacheEnabled(tIdx)) oldDist = pConf.cacheFitness(tCmp,pos,tIdx); else oldDist = Emodel::em(tIdx).Level(pConf,tCmp,pos); newDist = Emodel::em(tIdx).Level(tCmp,pConf[tCmp],pos,mTrial); if(pConf.cacheEnabled(tIdx)) pConf.cacheFitness(tCmp,pos,tIdx) = newDist; tDelta = tDelta + newDist - oldDist; } pConf.fitness(tIdx)+=tDelta; } pConf.remove(pConf[pos]); pConf[pos]=mTrial; pConf.add(mTrial); }
bool ExtraRfbServers::reload(bool asService, RfbClientManager *mgr) { Log::detail(_T("Considering to reload extra RFB servers")); Conf newConf; getConfiguration(&newConf); bool noConfigChanges = newConf.equals(&m_effectiveConf); bool enoughServers = (newConf.extraPorts.count() == m_servers.size()); Log::detail(_T("Same Extra Ports configuration = %d, enough servers = %d"), (int)noConfigChanges, (int)enoughServers); if (noConfigChanges && enoughServers) { return true; } Log::message(_T("Need to reconfigure extra RFB servers")); shutDown(); return startUp(asService, mgr); }
// 删除一条数据 int Submit_DeleteData::Deal(Page *page) { const string &key = page->GetCurrentKey(); Conf *pack = page->GetCurrentPack(); // 设为删除,并调用处理函数: pack->Set("status", "delete"); pack->Set("text", ""); pack->Set("modify", NowTime("%Y%m%d%H%M%S")); Ini data; data.Set(key, *pack); const string &username = page->GetRequest()->GetCurrentUser(); UserData del( username ); /* * 保存(删除数据) */ if(del.Set(data, true) < 0) { LOG_ERROR("Detete error: [%s]", key.c_str()); return ERR; } /* * 删除附件 */ vector<string> attachs; vector<string>::iterator it; del.GetAttachList(key, attachs); // 取附件列表 for(it = attachs.begin(); attachs.end() != it; it++) { LOG_INFO("Delete attach: [%s]", it->c_str()); DeleteFile(*it); } LOG_INFO("Detete: [%s]", key.c_str()); return OK; }
/*=============================================================== * @protected ===============================================================*/ int PropertyImpl::init(){ Conf* conf = Conf::GetInstance(); assert(NULL != conf); string user = conf->find("DataBase", "user"); string pass = conf->find("DataBase", "pass"); string name = conf->find("DataBase", "name"); mysql_ = new MySQL(user, pass, name); assert(NULL != mysql_); mysql_->Connect(); return 1; }
void Log::dbgPrintfMemImpl(const char *msg, const void *ptr, size_t size, const char *file, int line) { Conf *conf = Conf::instance(); if(!conf || conf->logLevel() < DebugType) return; ostream *o = &cout; fstream f; if(!conf->logFile().empty()) { f.open(File::encodeName(conf->logFile()).c_str(), fstream::out|fstream::app); o = &f; } const unsigned char *data = (const unsigned char*)ptr; *o << "DEBUG [" << File::fileName(file) << ":" << line << "] - " << msg << " { "; *o << hex << uppercase << setfill('0'); for(size_t i = 0; i < size; ++i) *o << setw(2) << static_cast<int>(data[i]) << ' '; *o << dec << nouppercase << setfill(' ') <<"}:" << size << "\n"; }
void Log::dbgPrintfMemImpl(const char *msg, const void *ptr, size_t size, const char *file, int line) { Conf *conf = Conf::getInstance(); if(!conf || conf->getLogLevel() < DebugType) return; std::ostream *o = &std::cout; std::fstream f; if(!conf->getLogFile().empty()) { f_string enc = util::File::encodeName(conf->getLogFile()); f.open(enc.c_str(), std::fstream::out|std::fstream::app); o = &f; } const unsigned char *data = (const unsigned char*)ptr; *o << "DEBUG [" << file << ":" << line << "] - " << msg << " { "; for(size_t i = 0; i < size; ++i) *o << '%' << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << static_cast<int>(data[i]) << ' '; *o << "}:" << size << "\n"; }
bool ExtraRfbServers::reload(bool asService, RfbClientManager *mgr) { m_log->detail(_T("Considering to reload extra RFB servers")); Conf newConf; getConfiguration(&newConf); bool noConfigChanges = newConf.equals(&m_effectiveConf); bool enoughServers = (newConf.extraPorts.count() == m_servers.size()); m_log->detail(_T("Same Extra Ports configuration = %d, enough servers = %d"), (int)noConfigChanges, (int)enoughServers); if (noConfigChanges && enoughServers) { return true; // no work needed, no errors encountered } // Either configuration was actually changed, or our number of actually // running servers does not match the configuration. In either case, // restart the servers. m_log->message(_T("Need to reconfigure extra RFB servers")); shutDown(); return startUp(asService, mgr); }
/*! Compute and store a possible initialisation change. */ void RandomValidSC::compute(Conf & theConf) { WatchError Dim tNeighCount = Lattice::l().NeighCount(); Dim tLength = Protein::p().Length(); hset<Point,xmmh> tPoints(tLength); mChange.reset(); tPoints.clear(); Point tPoint(0), sPoint; mChange.add(0,tPoint); tPoints.insertBll(tPoint); Pos tPos = 1; do { Idx tIdx = 0; do { ++tIdx; // if tPos is a side chain take the point from backbone if(theConf.isPosSideChain(tPos)) { sPoint = mChange.Destination(tPos-Protein::p().Length()/2); } else // the previous point sPoint = tPoint; Dir tDir = uniform(mRnd, tNeighCount); sPoint = sPoint + Lattice::l().DirVec(tDir); } while (!tPoints.insertBll(sPoint) && tIdx < tNeighCount); if (tIdx <= tNeighCount) { mChange.add(tPos, sPoint); tPoint = sPoint; ++tPos; } else { tPoints.removeItr(tPoint); tPoint = mChange.Destination(mChange.size() - 1); mChange.remove(); --tPos; } } while (tPos < tLength); CatchError }
/*======================================================================*/ GraphicManager::GraphicManager(): _uiDisplayListMask( OC_OPAQUE_ONESIDE_LIST | OC_OPAQUE_TWOSIDE_LIST | OC_ALPHA_LIST ) { OPENCITY_DEBUG( "GraphicManager ctor" ); // Initialize the model table int i; for (i = 0; i < OC_GRAPHIC_CODE_MAX; i++ ) { _tabpModel[i] = NULL; } // Try to open the graphism config file Conf* pConf = new Conf(); if (pConf->Open( ocConfigDirPrefix(OC_GRAPHISM_FILE_FILENAME) ) != OC_ERR_FREE) { OPENCITY_FATAL( "Failed to open the graphism config file" ); delete pConf; abort(); } // Load all the specified models from the config file string strPath; std::stringstream ss; for (i = 0; i < OC_GRAPHIC_CODE_MAX; i++ ) { ss.str(""); ss << i; strPath = pConf->GetValue( ss.str() ); if (strPath == "") continue; _tabpModel[i] = ModelLoader::Load( ocDataDirPrefix(strPath) ); if (_tabpModel[i] == NULL) { OPENCITY_FATAL( "Failed to load the file: " << ocDataDirPrefix(strPath) ); abort(); } } // for delete pConf; }