int main() { const char* file = "./datakit/schemas/xtk_schema.xml"; XReader* read = new XReader(new ifstream(file, ifstream::in)); if (1) { XObject* obj; do { obj = read->read(); } while (obj); XDocument* doc = read->document(); read->dispose(); delete read; return 0; } else { NSchemaReader sch(read); NSchema *schema = sch.read(); NString sql = schema->getSqlCreate(); } return 0; }
void test_circuit_rc() { ngdc dc("dc1", 5); ngresistor r("r1", 5); ngcapacitor c("c1", 0.2); ngground gnd; ngline line1(dc[0], r[0]); ngline line2(r[1], c[0]); ngline line3(c[1], dc[1]); ngline line4(dc[0], gnd[0]); schema sch("design1"); sch.AddDevice(&dc); sch.AddDevice(&r); sch.AddDevice(&c); sch.AddDevice(&gnd); sch.AddLine(&line1); sch.AddLine(&line2); sch.AddLine(&line3); sch.AddLine(&line4); circuit cir(&sch); cir.Tran("1s"); do { Sleep(200); } while (cir.IsRunning()); }
RcppExport SEXP cfamounts(SEXP params){ SEXP rl=R_NilValue; char* exceptionMesg=NULL; try{ RcppParams rparam(params); QuantLib::Date maturity(dateFromR(rparam.getDateValue("Maturity"))); QuantLib::Date settle(dateFromR(rparam.getDateValue("Settle"))); QuantLib::Date issue(dateFromR(rparam.getDateValue("IssueDate"))); double rate = rparam.getDoubleValue("CouponRate"); std::vector<double> rateVec(1, rate); double faceAmount = rparam.getDoubleValue("Face"); double period = rparam.getDoubleValue("Period"); double basis = rparam.getDoubleValue("Basis"); DayCounter dayCounter = getDayCounter(basis); Frequency freq = getFrequency(period); Period p(freq); double EMR = rparam.getDoubleValue("EMR"); Calendar calendar=UnitedStates(UnitedStates::GovernmentBond); Schedule sch(settle, maturity, p, calendar, Unadjusted, Unadjusted, DateGeneration::Backward, (EMR == 1)? true : false); FixedRateBond bond(1, faceAmount, sch, rateVec, dayCounter, Following, 100, issue); //cashflow int numCol = 2; std::vector<std::string> colNames(numCol); colNames[0] = "Date"; colNames[1] = "Amount"; RcppFrame frame(colNames); Leg bondCashFlow = bond.cashflows(); for (unsigned int i = 0; i< bondCashFlow.size(); i++){ std::vector<ColDatum> row(numCol); Date d = bondCashFlow[i]->date(); row[0].setDateValue(RcppDate(d.month(), d.dayOfMonth(), d.year())); row[1].setDoubleValue(bondCashFlow[i]->amount()); frame.addRow(row); } RcppResultSet rs; rs.add("cashFlow", frame); rl = rs.getReturnList(); } catch(std::exception& ex) { exceptionMesg = copyMessageToR(ex.what()); } catch(...) { exceptionMesg = copyMessageToR("unknown reason"); } if(exceptionMesg != NULL) Rf_error(exceptionMesg); return rl; }
bool Database::loadFromFile(std::string filename){ std::string page; std::ifstream in(filename); if (!in) return false; std::string dataLine; while (in>>dataLine){ page+=dataLine; page+='\n'; } //get the first line of the input as a token std::string delimiters="'\n'"; Tokenizer t(page, delimiters); std::string firstLine; t.getNextToken(firstLine); //specify schema Tokenizer sch(firstLine,","); std::string fName; std::vector <FieldDescriptor> vecDes; while (sch.getNextToken(fName)){ FieldDescriptor fdtemp; if (fName[fName.size()-1]=='*'){ fName=fName.substr(0,fName.size()-1); fdtemp.name=fName; fdtemp.index=it_indexed; vecDes.push_back(fdtemp); } else { fdtemp.name=fName; fdtemp.index=it_none; vecDes.push_back(fdtemp); } } specifySchema(vecDes); std::string temp2; while (t.getNextToken(temp2)){ std::vector<std::string> line; std::string lines; Tokenizer t2(temp2,","); while (t2.getNextToken(lines)){ line.push_back(lines); } addRow(line); } return true; }
RcppExport SEXP cfdates(SEXP params){ SEXP rl = R_NilValue; char* exceptionMesg = NULL; try { RcppParams rparam(params); double basis = rparam.getDoubleValue("dayCounter"); DayCounter dayCounter = getDayCounter(basis); double p = rparam.getDoubleValue("period"); Frequency freq = getFrequency(p); Period period(freq); double emr = rparam.getDoubleValue("emr"); bool endOfMonth = false; if (emr == 1) endOfMonth = true; QuantLib::Date d1(dateFromR(rparam.getDateValue("settle"))); QuantLib::Date d2(dateFromR(rparam.getDateValue("maturity"))); Calendar calendar=UnitedStates(UnitedStates::GovernmentBond); Schedule sch(d1, d2, period, calendar, Unadjusted, Unadjusted, DateGeneration::Backward, endOfMonth); //cfdates int numCol = 1; std::vector<std::string> colNames(numCol); colNames[0] = "Date"; RcppFrame frame(colNames); std::vector<QuantLib::Date> dates = sch.dates(); for (unsigned int i = 0; i< dates.size(); i++){ std::vector<ColDatum> row(numCol); Date d = dates[i]; row[0].setDateValue(RcppDate(d.month(), d.dayOfMonth(), d.year())); frame.addRow(row); } RcppResultSet rs; rs.add("", frame); rl = rs.getReturnList(); } catch(std::exception& ex) { exceptionMesg = copyMessageToR(ex.what()); } catch(...) { exceptionMesg = copyMessageToR("unknown reason"); } if(exceptionMesg != NULL) Rf_error(exceptionMesg); return rl; }
void OcrEngine::slotScrollToWord(const QRect &r) { if (m_imgCanvas==NULL) return; if (m_currHighlight>-1) m_imgCanvas->removeHighlight(m_currHighlight); m_currHighlight = -1; if (!m_trackingActive) return; // not highlighting KColorScheme sch(QPalette::Active, KColorScheme::Selection); QColor col = sch.background(KColorScheme::NeutralBackground).color(); m_imgCanvas->setHighlightStyle(ImageCanvas::HighlightUnderline, QPen(col, 2)); m_currHighlight = m_imgCanvas->addHighlight(r, true); }
void OcrEngine::slotHighlightWord(const QRect &r) { if (m_imgCanvas==NULL) return; if (m_currHighlight>-1) m_imgCanvas->removeHighlight(m_currHighlight); m_currHighlight = -1; if (!m_trackingActive) return; // not highlighting if (!r.isValid()) return; // word rectangle invalid KColorScheme sch(QPalette::Active, KColorScheme::Selection); QColor col = sch.background(KColorScheme::NegativeBackground).color(); m_imgCanvas->setHighlightStyle(ImageCanvas::HighlightBox, QPen(col, 2)); m_currHighlight = m_imgCanvas->addHighlight(r, true); }
void Portfolio::ReadFromDB() { QSqlQuery query; QString strTemp; strTemp = "%1%2"; QString strQuery = strTemp.arg("Select * from Schemes where PortfolioCode=").arg(m_Code); query.exec(strQuery); while(query.next()) { QString name = query.value(0).toString(); int Code = query.value(1).toInt(); double nav = query.value(3).toDouble(); QDate navdate = query.value(6).toDate(); Scheme sch(name,Code,nav,navdate); addScheme(sch); } for(int i=0; i<m_Schemes.count();i++) { m_Schemes[i].ReadFromDB(); m_AmountInvested += m_Schemes[i].getAmoutInvested(); m_MarketValue += m_Schemes[i].getMarketValue(); m_Gain += m_Schemes[i].getGain(); m_xirrTransactions.append(m_Schemes[i].getxirrTransactions()); } m_absReturn = (100*m_Gain)/m_AmountInvested; xirrTransaction xtranLatest; xtranLatest.amount = 0-m_MarketValue; xtranLatest.date = QDate::currentDate(); m_xirrTransactions << xtranLatest; m_CAGR = 0- CalculateXIRR(m_xirrTransactions,m_absReturn)*100; }
void AGActivityGenHandler::parseSchool(const SUMOSAXAttributes& attrs) { try { std::string edge = attrs.getString(SUMO_ATTR_EDGE); SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION); AGPosition posi(myCity.getStreet(edge), positionOnEdge); int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); int endAge = attrs.getInt(AGEN_ATTR_ENDAGE); int capacity = attrs.getInt(AGEN_ATTR_CAPACITY); int openingHour = attrs.getInt(AGEN_ATTR_OPENING); int closingHour = attrs.getInt(AGEN_ATTR_CLOSING); AGSchool sch(capacity, posi, beginAge, endAge, openingHour, closingHour); myCity.schools.push_back(sch); } catch (const std::exception& e) { WRITE_ERROR("Error while parsing the element " + SUMOXMLDefinitions::Tags.getString(AGEN_TAG_SCHOOL) + ": " + e.what()); throw ProcessError(); } }
/* * === FUNCTION ====================================================================== * Name: main * Description: Program entry point * ===================================================================================== */ int main( int argc,char* argv[] ) { ShellCommand sch(VERSION); ShellCommand::SHELLCOMMAND result = sch.Analyze( argc,argv ); if ( result == ShellCommand::NORMAL ) { standard_function(); } else if ( result == ShellCommand::SERVER ) { server_function(); } else if ( result == ShellCommand::CLIENT ) { client_function(); } else if ( result == ShellCommand::TEST ) { Basicio basicio; basicio.test(); } return EXIT_SUCCESS; }
int kategw(class zar_kateg_rek *data,FILE *kaw, GtkWidget *view, GtkTextBuffer *buffer, GtkWidget *bar, GtkWidget *wpredok) { short kon=0; /*Количество статей начисления*/ short kou=0; /*Количество статей удержания*/ short kka=0; /*Количество категорий*/ int in,iu,ik; SQL_str row; char strsql[512]; short dkm=0; int klst=0; short mn,gn; short mk,gk; iceb_u_rsdat1(&mn,&gn,data->datan.ravno()); iceb_u_rsdat1(&mk,&gk,data->datak.ravno()); if(mk == 0) { mk=mn; gk=gn; } sprintf(strsql,"%s %d.%d %s %d.%d\n",gettext("Период с"),mn,gn, gettext("по"),mk,gk); iceb_printw(iceb_u_toutf(strsql),buffer,view); /*Определяем количество начислений и удержаний*/ kka=kon=kou=0; in=iu=ik=0; sprintf(strsql,"select kod from Nash"); class SQLCURSOR cur; if((kon=cur.make_cursor(&bd,strsql)) < 0) { iceb_msql_error(&bd,gettext("Ошибка создания курсора !"),strsql,wpredok); return(1); } if(kon == 0) { iceb_menu_soob(gettext("Не введены начисления !"),wpredok); return(1); } short na[kon]; while(cur.read_cursor(&row) != 0) na[in++]=atoi(row[0]); sprintf(strsql,"select kod from Uder"); if((kou=cur.make_cursor(&bd,strsql)) < 0) { iceb_msql_error(&bd,gettext("Ошибка создания курсора !"),strsql,wpredok); return(1); } if(kou == 0) { iceb_menu_soob(gettext("Не введены удержания !"),wpredok); return(1); } short ud[kou]; while(cur.read_cursor(&row) != 0) ud[iu++]=atoi(row[0]); sprintf(strsql,"select kod from Kateg"); if((kka=cur.make_cursor(&bd,strsql)) < 0) { iceb_msql_error(&bd,gettext("Ошибка создания курсора !"),strsql,wpredok); return(1); } if(kka == 0) { iceb_menu_soob(gettext("Не введены категории !"),wpredok); return(1); } short ka[kka]; while(cur.read_cursor(&row) != 0) ka[ik++]=atoi(row[0]); double nao[kka*kon]; memset(&nao,'\0',sizeof(nao)); double udo[kka*kou]; memset(&udo,'\0',sizeof(udo)); short kollnah[kka]; short kollud[kka]; memset(&kollnah,'\0',sizeof(kollnah)); memset(&kollud,'\0',sizeof(kollud)); iceb_u_dpm(&dkm,&mk,&gk,5); iceb_u_zagolov(gettext("Расчёт начислений и удержаний по категориям"),1,mn,gn,dkm,mk,gk,organ,kaw); if(data->podr.ravno()[0] != '\0') { fprintf(kaw,"%s:%s\n",gettext("Код подразделения"),data->podr.ravno()); iceb_printcod(kaw,"Podr","kod","naik",0,data->podr.ravno(),&klst); } else fprintf(kaw,"%s\n",gettext("По всем подразделениям")); if(data->kod_nah.ravno()[0] != '\0') fprintf(kaw,"%s:%s\n",gettext("Код начисления"),data->kod_nah.ravno()); if(data->kod_ud.ravno()[0] != '\0') fprintf(kaw,"%s:%s\n",gettext("Код удержания"),data->kod_ud.ravno()); if(data->kod_kat.ravno()[0] != '\0') fprintf(kaw,"%s:%s\n",gettext("Коды категории"),data->kod_kat.ravno()); if(data->tabnom.ravno()[0] != '\0') fprintf(kaw,"%s:%s\n",gettext("Табельный номер"),data->tabnom.ravno()); if(data->shet.ravno()[0] != '\0') fprintf(kaw,"%s:%s\n",gettext("Счет"),data->shet.ravno()); sch(mn,gn,mk,gk,na,kon,ud,kou,ka,kka,kollnah,kollud,kaw,nao,udo,data,view,buffer,bar,wpredok); iceb_podpis(kaw,wpredok); return(0); }
void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) { // Close other windows. if( !Kiway().PlayersClose( false ) ) return; wxString title = _( "Import Eagle Project Files" ); int style = wxFD_OPEN | wxFD_FILE_MUST_EXIST; wxString default_dir = GetMruPath(); ClearMsg(); wxFileDialog schdlg( this, title, default_dir, wxEmptyString, EagleFilesWildcard(), style ); if( schdlg.ShowModal() == wxID_CANCEL ) return; wxFileName sch( schdlg.GetPath() ); sch.SetExt( SchematicFileExtension ); wxFileName pro = sch; pro.SetExt( ProjectFileExtension ); wxString protitle = _( "KiCad Project Destination" ); // Don't use wxFileDialog here. On GTK builds, the default path is returned unless a // file is actually selected. wxDirDialog prodlg( this, protitle, pro.GetPath(), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST ); if( prodlg.ShowModal() == wxID_CANCEL ) return; pro.SetPath( prodlg.GetPath() ); // Check if the project directory is empty wxDir directory( pro.GetPath() ); if( directory.HasFiles() ) { wxString msg = _( "The selected directory is not empty. We recommend you " "create projects in their own clean directory.\n\nDo you " "want to create a new empty directory for the project?" ); KIDIALOG dlg( this, msg, _( "Confirmation" ), wxYES_NO | wxICON_WARNING ); dlg.DoNotShowCheckbox( __FILE__, __LINE__ ); if( dlg.ShowModal() == wxID_YES ) { // Append a new directory with the same name of the project file // and try to create it pro.AppendDir( pro.GetName() ); if( !wxMkdir( pro.GetPath() ) ) // There was a problem, undo pro.RemoveLastDir(); } } wxFileName pcb( sch ); pro.SetExt( ProjectFileExtension ); // enforce extension pcb.SetExt( LegacyPcbFileExtension ); // enforce extension if( !pro.IsAbsolute() ) pro.MakeAbsolute(); SetProjectFileName( pro.GetFullPath() ); wxString prj_filename = GetProjectFileName(); if( sch.FileExists() ) { KIWAY_PLAYER* schframe = Kiway().Player( FRAME_SCH, false ); if( !schframe ) { try // SCH frame was not available, try to start it { schframe = Kiway().Player( FRAME_SCH, true ); } catch( const IO_ERROR& err ) { wxMessageBox( _( "Eeschema failed to load:\n" ) + err.What(), _( "KiCad Error" ), wxOK | wxICON_ERROR, this ); return; } } std::string packet = StrPrintf( "%d\n%s", SCH_IO_MGR::SCH_EAGLE, TO_UTF8( sch.GetFullPath() ) ); schframe->Kiway().ExpressMail( FRAME_SCH, MAIL_IMPORT_FILE, packet, this ); if( !schframe->IsShown() ) // the frame exists, (created by the dialog field editor) // but no project loaded. { schframe->Show( true ); } if( schframe->IsIconized() ) schframe->Iconize( false ); schframe->Raise(); } if( pcb.FileExists() ) { KIWAY_PLAYER* pcbframe = Kiway().Player( FRAME_PCB, false ); if( !pcbframe ) { try // PCB frame was not available, try to start it { pcbframe = Kiway().Player( FRAME_PCB, true ); } catch( const IO_ERROR& err ) { wxMessageBox( _( "Pcbnew failed to load:\n" ) + err.What(), _( "KiCad Error" ), wxOK | wxICON_ERROR, this ); return; } } // a pcb frame can be already existing, but not yet used. // this is the case when running the footprint editor, or the footprint viewer first // if the frame is not visible, the board is not yet loaded if( !pcbframe->IsVisible() ) { pcbframe->Show( true ); } std::string packet = StrPrintf( "%d\n%s", IO_MGR::EAGLE, TO_UTF8( pcb.GetFullPath() ) ); pcbframe->Kiway().ExpressMail( FRAME_PCB, MAIL_IMPORT_FILE, packet, this ); // On Windows, Raise() does not bring the window on screen, when iconized if( pcbframe->IsIconized() ) pcbframe->Iconize( false ); pcbframe->Raise(); } ReCreateTreePrj(); m_active_project = true; }