//===== MAIN ENTRY POINT ===== int main() { //Construct data link layer DataLinkLayer dll; //Construct 8 frames Frame input1(192,1); Frame input2(194,2); Frame input3(196,3); Frame input4(198,4); Frame input5(200,5); Frame input6(202,6); Frame input7(204,7); Frame input8(207,8); //Decode four frames and check list // dll.processFrame(input5); // dll.processFrame(input6); // char input; // while(1) // { // std::cin >> input; // if(input=='a') // dll.checkToken(); // if(input=='b') // dll.processFrame(input2); // } }
int main(void){ Mathmatrix matrix1, matrix2,matrix3; ifstream input("/Users/artemdanilov/Desktop/ Test6/Test6/in.txt"),input2("/Users/artemdanilov/Desktop/ Test6/Test6/in2.txt"); input >> matrix1; cout << "Первая матрица "<<endl<<matrix1; input2 >> matrix2; cout <<"Вторая матрица "<<endl<< matrix2; matrix3= matrix1 + matrix2; cout<<"Сложение матриц"<<endl<<matrix3; matrix3=matrix1 - matrix2; cout <<"Вычитание матриц" <<endl<<matrix3; matrix3 = matrix2*matrix1; cout <<"Умножение матриц"<<endl<< matrix3; matrix1.mult(4); cout<<"Умножение на число"<<endl<<matrix1; matrix1.del(2); cout<<"Деление матрицы на число"<<endl<<matrix1; Mathmatrix matrix10; matrix10= Mathmatrix(2,3); cout<<"test"<<endl; Mathmatrix *mat = new Mathmatrix; cout<<mat<<endl; matrix1.change(99,1,3); cout<<"Изменение элемента"<<endl<<matrix1; cout<<"Чтение элемента "<<endl<<matrix1.readel(2,3); return 0; }
void editextbank() { if(dbg_extport == -1) return; unsigned x = input2(ports_x+5, ports_y+2, dgb_extval); if (x != -1) out(dbg_extport, (unsigned char)x); }
void editbank() { unsigned x = input2(ports_x+5, ports_y+1, comp.p7FFD); if (x != -1) { comp.p7FFD = x; set_banks(); } }
static const char* unbind_valued_parameterized_output_action () { automaton1 binder_instance; automaton1 output_instance; automaton1 input1_instance; automaton1 input2_instance; ioa::automaton_handle<automaton1> binder_handle (0); ioa::automaton_handle<automaton1> output_handle (1); ioa::automaton_handle<automaton1> input1_handle (2); ioa::automaton_handle<automaton1> input2_handle (3); int output_parameter = 123; int input_parameter = 345; ioa::action<automaton1, automaton1::p_v_output_action> output (output_handle, &automaton1::p_v_output, output_parameter, ioa::parameterized ()); ioa::action<automaton1, automaton1::up_v_input_action> input1 (input1_handle, &automaton1::up_v_input); ioa::action<automaton1, automaton1::p_v_input_action> input2 (input2_handle, &automaton1::p_v_input, input_parameter, ioa::parameterized ()); ioa::binding<automaton1::p_v_output_action> binding; int binding1; binding.bind (output_instance, output, input1_instance, input1, binder_handle, &binding1); int binding2; binding.bind (output_instance, output, input2_instance, input2, binder_handle, &binding2); binding.execute (); mu_assert (output_instance.p_v_output.state); mu_assert (output_instance.p_v_output.last_parameter == output_parameter); mu_assert (input1_instance.up_v_input.value == 9845); mu_assert (input2_instance.p_v_input.value == 9845); mu_assert (input2_instance.p_v_input.last_parameter == input_parameter); binding.unbind (binder_handle, &binding1); mu_assert (!binding.empty ()); mu_assert (binding.involves_output (output)); mu_assert (!binding.involves_binding (output, input1, binder_handle)); mu_assert (binding.involves_binding (output, input2, binder_handle)); mu_assert (!binding.involves_input (input1)); mu_assert (binding.involves_input (input2)); mu_assert (!binding.involves_input_automaton (input1_handle)); mu_assert (binding.involves_input_automaton (input2_handle)); binding.unbind (binder_handle, &binding2); mu_assert (binding.empty ()); mu_assert (!binding.involves_output (output)); mu_assert (!binding.involves_binding (output, input1, binder_handle)); mu_assert (!binding.involves_binding (output, input2, binder_handle)); mu_assert (!binding.involves_input (input1)); mu_assert (!binding.involves_input (input2)); mu_assert (!binding.involves_input_automaton (input1_handle)); mu_assert (!binding.involves_input_automaton (input2_handle)); return 0; }
int ifuGetString(const char *mesg1, char *buffer1, const char *mesg2, char *buffer2, const char *mesg3, char *buffer3, const char *mesg4, char *buffer4) { int l = strlen(mesg1); if((int)strlen(mesg2)>l) { l = strlen(mesg2); } if((int)strlen(mesg3)>l) { l = strlen(mesg3); } if((int)strlen(mesg4)>l) { l = strlen(mesg4); } Fl_Window window(270+l*8,10+25+10+25+10+25+10+25+10+35); Fl_Input input1(10+l*8, 10, 250, 25, mesg1); input1.value(buffer1); Fl_Input input2(10+l*8, 10+25+10, 250, 25, mesg2); input2.value(buffer2); Fl_Input input3(10+l*8, 10+25+10+25+10, 250, 25, mesg3); input3.value(buffer3); Fl_Input input4(10+l*8, 10+25+10+25+10+25+10, 250, 25, mesg4); input4.value(buffer4); Fl_Button cancel(60, 10+25+10+25+10+25+10+25+10, 80, 25, "Cancel"); Fl_Return_Button ok(150, 10+25+10+25+10+25+10+25+10, 80, 25, "OK"); window.hotspot(&ok); window.end(); window.set_modal(); window.show(); for (;;) { Fl::wait(); Fl_Widget *o; while ((o = Fl::readqueue())) { if (o == &ok) { strcpy(buffer1,input1.value()); strcpy(buffer2,input2.value()); strcpy(buffer3,input3.value()); strcpy(buffer4,input4.value()); return 1; } else { if (o == &cancel || o == &window) { return 0; } } } } }
void ParameterOperator::execute(DataProvider& provider) { Id2DataPair input1(INPUT_1); Id2DataPair input2(INPUT_2); provider.receiveInputData(input1 && input2); // execute... Id2DataPair output1(OUTPUT_1, input1.data()); Id2DataPair output2(OUTPUT_2, input2.data()); provider.sendOutputData(output1 && output2); }
void mdiskgo() { Z80 &cpu = CpuMgr.Cpu(); if (editor == ED_MEM) return; for (;;) { *(unsigned*)str = mem_disk + 'A'; if (!inputhex(mem_x+5, mem_y-1, 1, true)) return; if (*str >= 'A' && *str <= 'D') break; } mem_disk = *str-'A'; showmem(); unsigned x = input2(mem_x+12, mem_y-1, mem_track); if (x == -1) return; mem_track = x; if (editor == ED_PHYS) return; showmem(); // enter sector for (;;) { findsector(cpu.mem_curs); x = input2(mem_x+20, mem_y-1, sector); if (x == -1) return; if (x < edited_track.s) break; } for (cpu.mem_curs = 0; x; x--) cpu.mem_curs += edited_track.hdr[x-1].datlen; }
void RunPP(const char *jobid="test") { Int_t nev=99999999; //TString input0("/star/u/russcher/gamma/analysis/data/pp05/ppProduction.root"); TString input0("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_0.root"); TString input1("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_1.root"); TString input2("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_2.root"); TString input3("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_3.root"); TString input4("/star/u/russcher/gamma/analysis/data/pp05/ppProductionMinBias.root"); TString outdir("/star/u/russcher/gamma/analysis/output/pp05/"); TString psout("pi0_pp05.ps"); TString psout2("eta_pp05.ps"); TString rootout("pi0_pp05.root"); psout.Prepend(jobid); rootout.Prepend(jobid); TString command("mkdir "); command.Append(outdir.Data()); command.Append(jobid); gSystem->Exec(command.Data()); cout<<endl<<"storing results in: "<<command.Data()<<endl<<endl; outdir.Append(jobid); outdir.Append("/"); psout.Prepend(outdir.Data()); psout2.Prepend(outdir.Data()); rootout.Prepend(outdir.Data()); gSystem->Load("$HOME/MyEvent/MyEvent.so"); gSystem->Load("$HOME/gamma/analysis/lib/AnaCuts.so"); gSystem->Load("$HOME/gamma/analysis/lib/EventMixer.so"); gSystem->Load("$HOME/gamma/analysis/lib/Pi0Analysis.so"); Pi0Analysis *pi0=new Pi0Analysis(psout.Data(),psout2.Data(),"pp05"); pi0->setMC(kFALSE); pi0->init(rootout.Data()); pi0->make(nev,input0.Data()); pi0->make(nev,input1.Data()); pi0->make(nev,input2.Data()); pi0->make(nev,input3.Data()); pi0->printPrescales(); cout<<"****** starting with minbias *********"<<endl; pi0->make(nev,input4.Data()); pi0->printPrescales(); pi0->getYield(); pi0->finish(); }
// This is a regression test for crbug.com/619141 TEST(HTMLTokenizerTest, ZeroOffsetAttributeNameRange) { HTMLParserOptions options; std::unique_ptr<HTMLTokenizer> tokenizer = HTMLTokenizer::create(options); HTMLToken token; SegmentedString input("<script "); EXPECT_FALSE(tokenizer->nextToken(input, token)); EXPECT_EQ(HTMLToken::StartTag, token.type()); SegmentedString input2("type='javascript'"); // Below should not fail ASSERT EXPECT_FALSE(tokenizer->nextToken(input2, token)); }
int CircuitObject::output_value() const { if(type() == "SWITCH") return _output_value; else if(type() == "NOT") { // Return the logical negation of the input if(input1()->output_value() == 0) return 1; else return 0; } else if(type() == "AND") { // Return 1 if all of the inputs are 1 if(input1()->output_value() == 1 && input2()->output_value() == 1) return 1; else return 0; } else if(type() == "OR") { // Return 1 if any of the inputs are 1 if(input1()->output_value() == 1 || input2()->output_value() == 1) return 1; else return 0; } else if(type() == "EXIT") { // Just return the input return input1()->output_value(); } }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Transform tests /////////////////////////////////////////////////////////////////////////////////////////////////////////////// TEST(simple1,counting) { bolt::amp::counting_iterator<int> iter(0); bolt::amp::counting_iterator<int> iter2=iter+1024; std::vector<int> input1(1024); std::vector<int> input2(1024); std::vector<int> stdOutput(1024); std::vector<int> boltOutput(1024); for(int i=0 ; i< 1024;i++) { input1[i] = i; } input2 = input1; std::transform( input1.begin(), input1.end(), input2.begin(), stdOutput.begin(), bolt::amp::plus<int>()); bolt::amp::transform(iter,iter2,input1.begin(),boltOutput.begin(),bolt::amp::plus<int>()); cmpArrays( stdOutput, boltOutput, 1024 ); }
void mon_tool() { Z80 &cpu = CpuMgr.Cpu(); static unsigned char unref = 0xCF; if (ripper) { OPENFILENAME ofn = { 0 }; char savename[0x200]; *savename = 0; ofn.lStructSize = (WinVerMajor < 5) ? OPENFILENAME_SIZE_VERSION_400 : sizeof(OPENFILENAME); ofn.lpstrFilter = "Memory dump\0*.bin\0"; ofn.lpstrFile = savename; ofn.nMaxFile = sizeof savename; ofn.lpstrTitle = "Save ripped data"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; ofn.hwndOwner = wnd; ofn.lpstrDefExt = "bin"; ofn.nFilterIndex = 1; if (GetSaveFileName(&ofn)) { for (unsigned i = 0; i < 0x10000; i++) snbuf[i] = (cpu.membits[i] & ripper) ? cpu.DirectRm(i) : unref; FILE *ff = fopen(savename, "wb"); if (ff) fwrite(snbuf, 1, 0x10000, ff), fclose(ff); } ripper = 0; } else { filledframe(tool_x, tool_y, 17, 6); tprint(tool_x, tool_y, " ripper's tool ", FRM_HEADER); tprint(tool_x+1,tool_y+2, "trace reads:", FFRAME_INSIDE); *(unsigned*)str = 'Y'; if (!inputhex(tool_x+15,tool_y+2,1,false)) return; tprint(tool_x+15,tool_y+2,str,FFRAME_INSIDE); if (*str == 'Y' || *str == 'y' || *str == '1') ripper |= MEMBITS_R; *(unsigned*)str = 'N'; tprint(tool_x+1,tool_y+3, "trace writes:", FFRAME_INSIDE); if (!inputhex(tool_x+15,tool_y+3,1,false)) { ripper = 0; return; } tprint(tool_x+15,tool_y+3,str,FFRAME_INSIDE); if (*str == 'Y' || *str == 'y' || *str == '1') ripper |= MEMBITS_W; tprint(tool_x+1,tool_y+4, "unref. byte:", FFRAME_INSIDE); unsigned ub; if ((ub = input2(tool_x+14,tool_y+4,unref)) == -1) { ripper = 0; return; } unref = (unsigned char)ub; if (ripper) for (unsigned i = 0; i < 0x10000; i++) cpu.membits[i] &= ~(MEMBITS_R | MEMBITS_W); } }
void TestReadStruct(Writer& output, Buffer& output_buffer, uint16_t val0, int64_t val1) { output.WriteStructBegin(bond::Metadata(), false); output.WriteFieldBegin(bond::BT_UINT16, 0); output.Write(val0); output.WriteFieldEnd(); output.WriteFieldBegin(bond::BT_INT64, 1); output.Write(val1); output.WriteFieldEnd(); output.WriteStructEnd(); // read from output, using CB version 2 typename Reader::Buffer input_buffer(output_buffer.GetBuffer()); Reader input(input_buffer, 2); uint16_t id; bond::BondDataType type; uint16_t value0; int64_t value1; input.ReadStructBegin(); input.ReadFieldBegin(type, id); input.Read(value0); input.ReadFieldEnd(); UT_AssertAreEqual(type, bond::BT_UINT16); UT_AssertAreEqual(id, 0); UT_AssertAreEqual(val0, value0); input.ReadFieldBegin(type, id); input.Read(value1); input.ReadFieldEnd(); input.ReadStructEnd(); UT_AssertAreEqual(type, bond::BT_INT64); UT_AssertAreEqual(id, 1); UT_AssertAreEqual(val1, value1); // test skipping struct, using CB version 2 typename Reader::Buffer input_buffer2(output_buffer.GetBuffer()); Reader input2(input_buffer2, 2); input2.Skip(bond::BT_STRUCT); UT_AssertIsTrue(input2.GetBuffer().IsEof()); }
int main() { char c[3] = { '1', '2', '3' }; char d[3]; char e[3]; char * s; int length; std::ofstream output("other.bin"); //open da file output.write( c, 3); //writing to a binary file, write( char[], int ) int for how many characters from the array to write onto the file output.close(); //done with the file std::ifstream input("other.bin"); //open da file input.read(d, 3); //simple way to read everything in a binary file, read ( char[], int ) int for how many characters to read input.seekg(0, input.end); //places the cursor at the end of the file, 0 means that it's at position 0 length = input.tellg(); //tellg() returns the int value of how many characters long the file is input.seekg(0, input.beg); //places the cursor at the beginning of the file at position 0 s = new char [ length ]; //make the character array [length] which we just got above input.read(s, length); // read( char *, int ) reads all the data in a binary file up to [length] characters input.close(); //done with the file std::cout.write(s, length); //function to print out everything in char array std::cout << "\n"; //make it pretty delete s; // *s was dynamic, gotta delete it std::ofstream output2 ( "other.txt" ); output2 << c[0] << " " << c[1] << " " << c[2]; output2.close(); std::ifstream input2 ( "other.txt" ); input2 >> e[0] >> e[1] >> e[2]; input2.close(); std::cout << e[0] << " " << e[1] << " " << e[2] << "\n"; std::cout << d[0] << " " << d[1] << " " << d[2] << "\n"; return 0; }
void TestOperator::execute(DataProvider& provider) { if(m_throwException) { throw InternalError("Funny exception."); } Id2DataPair input1(INPUT_1); Id2DataPair input2(INPUT_2); provider.receiveInputData(input1 && input2); // execute... m_numExecutes++; boost::this_thread::sleep_for(boost::chrono::milliseconds(m_sleepTime)); Id2DataPair output1(OUTPUT_1, input1.data()); Id2DataPair output2(OUTPUT_2, input2.data()); provider.sendOutputData(output1 && output2); }
TEST(simple1,Serial_counting) { bolt::amp::counting_iterator<int> iter(0); bolt::amp::counting_iterator<int> iter2=iter+1024; std::vector<int> input1(1024); std::vector<int> input2(1024); std::vector<int> stdOutput(1024); std::vector<int> boltOutput(1024); for(int i=0 ; i< 1024;i++) { input1[i] = i; } input2 = input1; bolt::amp::control ctl = bolt::amp::control::getDefault( ); ctl.setForceRunMode(bolt::amp::control::SerialCpu); std::transform( input1.begin(), input1.end(), input2.begin(), stdOutput.begin(), bolt::amp::plus<int>()); bolt::amp::transform(ctl, iter,iter2,input1.begin(),boltOutput.begin(),bolt::amp::plus<int>()); cmpArrays( stdOutput, boltOutput, 1024 ); }
LPXLFOPER EXCEL_EXPORT xlContainsError( LPXLFOPER input2a) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper input2b( (input2a)); CellMatrix input2( input2b.AsCellMatrix("input2")); bool result( ContainsError( input2) ); return XlfOper(result); EXCEL_END }
/** * Tests that configuring inputs to be filtered succeeds. * * This test actually tests everything except that the actual FPGA * implementation works as intended. We configure the FPGA and then query it to * make sure that the acutal configuration matches. */ TEST(DigitalGlitchFilterTest, BasicTest) { DigitalInput input1(1); DigitalInput input2(2); DigitalInput input3(3); DigitalInput input4(4); Encoder encoder5(5, 6); Counter counter7(7); // Check that we can make a single filter and set the period. DigitalGlitchFilter filter1; filter1.Add(&input1); filter1.SetPeriodNanoSeconds(4200); // Check that we can make a second filter with 2 inputs. DigitalGlitchFilter filter2; filter2.Add(&input2); filter2.Add(&input3); filter2.SetPeriodNanoSeconds(97100); // Check that we can make a third filter with an input, an encoder, and a // counter. DigitalGlitchFilter filter3; filter3.Add(&input4); filter3.Add(&encoder5); filter3.Add(&counter7); filter3.SetPeriodNanoSeconds(167800); // Verify that the period was properly set for all 3 filters. EXPECT_EQ(4200u, filter1.GetPeriodNanoSeconds()); EXPECT_EQ(97100u, filter2.GetPeriodNanoSeconds()); EXPECT_EQ(167800u, filter3.GetPeriodNanoSeconds()); // Clean up. filter1.Remove(&input1); filter2.Remove(&input2); filter2.Remove(&input3); filter3.Remove(&input4); filter3.Remove(&encoder5); filter3.Remove(&counter7); }
ScalarType opencl_convolve(std::vector<ScalarType>& in1, std::vector<ScalarType>& in2, unsigned int /*row*/, unsigned int /*col*/, unsigned int /*batch_size*/) { //if(in1.size() > 2048) return -1; viennacl::vector<ScalarType> input1(in1.size()); viennacl::vector<ScalarType> input2(in2.size()); viennacl::vector<ScalarType> output(in1.size()); viennacl::fast_copy(in1, input1); viennacl::fast_copy(in2, input2); viennacl::linalg::convolve(input1, input2, output); viennacl::backend::finish(); std::vector<ScalarType> res(in1.size()); viennacl::fast_copy(output, res); std::vector<ScalarType> ref(in1.size()); convolve_ref(in1, in2, ref); return diff_max(res, ref); }
void mxOutputView::GetProcessOutput() { if (!process) return; wxTextInputStream input(*(process->GetInputStream())); wxTextInputStream input2(*(process->GetErrorStream())); static wxString line; static char c; line.Clear(); while (process->IsInputAvailable()) { c=input.GetChar(); if (c!='\r') line<<c; } ctrl_std->AppendText(line); ctrl_std->ShowPosition(ctrl_std->GetLastPosition()); line.Clear(); while (process->IsErrorAvailable()) { c=input2.GetChar(); if (c!='\r') line<<c; } if (textfile) textfile->Write(line); ctrl_err->AppendText(line); ctrl_err->ShowPosition(ctrl_err->GetLastPosition()); if (working) timer->Start(500,true); }
void chess(int fd_stdin,int fd_stdout) { dsply(); printf("Please choose players model 1 or computer model 2 :"); //int player; //scanf("%d", &player); char player[80]={0}; int r = read(fd_stdin, player, 80); player[r] = 0; do{ input(fd_stdin,fd_stdout); if(player[0] == '1') input2(fd_stdin,fd_stdout); else if (player[0] == '2') judge(); else{ printf("Sorry! You input wrong number,Please type in again!"); continue; } if(chkWin() == WIN) break; if(chkWin() == UNWIN) break; if(stepFlg == 5 && chkPeace() == PEACE){ printf("Peace!"); return 0; } }while(1); if(chkWin() == WIN) printf("二号玩家胜利! "); if(chkWin() == UNWIN) printf("一号玩家胜利! "); return 0; }
void ExtractZakC64::execute() { int i, j; unsigned short signature; char fname[256]; // Two disks... Common::Filename inpath1(_inputPaths[0].path); Common::Filename inpath2(_inputPaths[1].path); Common::Filename &outpath = _outputPath; if (outpath.empty()) // Standard output path outpath.setFullPath("out/"); Common::File input1(inpath1, "rb"); Common::File input2(inpath2, "rb"); /* check signature */ signature = input1.readUint16LE(); if (signature != 0x0A31) error("Signature not found in disk 1!"); signature = input2.readUint16LE(); if (signature != 0x0132) error("Signature not found in disk 2!"); outpath.setFullName("00.LFL"); Common::File output(outpath, "wb"); output.setXorMode(0xFF); print("Creating 00.LFL..."); /* write signature */ output.writeUint16LE(signature); /* copy object flags */ for (i = 0; i < 775; i++) output.writeByte(input1.readByte()); /* copy room offsets */ for (i = 0; i < NUM_ROOMS; i++) { room_disks_c64[i] = input1.readByte(); output.writeByte(room_disks_c64[i]); } for (i = 0; i < NUM_ROOMS; i++) { room_sectors_c64[i] = input1.readByte(); output.writeByte(room_sectors_c64[i]); room_tracks_c64[i] = input1.readByte(); output.writeByte(room_tracks_c64[i]); } /* copy costume offsets */ for (i = 0; i < 38; i++) output.writeByte(input1.readByte()); for (i = 0; i < 38; i++) output.writeUint16LE(input1.readUint16LE()); /* copy script offsets */ for (i = 0; i < 155; i++) output.writeByte(input1.readByte()); for (i = 0; i < 155; i++) output.writeUint16LE(input1.readUint16LE()); /* copy sound offsets */ for (i = 0; i < 127; i++) output.writeByte(input1.readByte()); for (i = 0; i < 127; i++) output.writeUint16LE(input1.readUint16LE()); output.close(); for (i = 0; i < NUM_ROOMS; i++) { Common::File *input; if (room_disks_c64[i] == '1') input = &input1; else if (room_disks_c64[i] == '2') input = &input2; else continue; sprintf(fname, "%02i.LFL", i); outpath.setFullName(fname); output.open(outpath, "wb"); print("Creating %s...", fname); input->seek((SectorOffset[room_tracks_c64[i]] + room_sectors_c64[i]) * 256, SEEK_SET); for (j = 0; j < ResourcesPerFile[i]; j++) { unsigned short len; do { len = input->readUint16LE(); output.writeUint16LE(len); } while (len == 0xffff); for (len -= 2; len > 0; len--) { output.writeByte(input->readByte()); } } input->rewind(); } print("All done!"); }
//----------------------------------------------------------------------------- int main(int argc, char** argv) { //---- s_pTbl_Items_Basic = new CN3TableBase<__TABLE_ITEM_BASIC>; std::string szFN = "Item_Org.tbl"; if(s_pTbl_Items_Basic->LoadFromFile(szFN.c_str()) == false) { printf("Failed to load Item_Org.tbl\n"); system("pause"); return -1; } //---- SQLHANDLE hEnv, hConn; SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv); SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0); SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hConn); if(SQLConnect(hConn, _T("KN_online"), SQL_NTS, _T("knight"), SQL_NTS, _T("knight"), SQL_NTS) == SQL_ERROR) { printf("SQLConnect\n"); system("pause"); return -1; } SQLHANDLE hStmt; SQLAllocHandle(SQL_HANDLE_STMT, hConn, &hStmt); if(SQLExecDirect(hStmt, _T("SELECT TOP(5000) Num, strName FROM ITEM;"), SQL_NTS) == SQL_ERROR) {//TOP(10000) printf("SQLExecDirect\n"); system("pause"); return -1; } long count = 0; SQLINTEGER cbData; while(SQLFetch(hStmt) == SQL_SUCCESS) { _ITEM_TABLE* item = new _ITEM_TABLE(); SQLGetData(hStmt, 1, SQL_C_ULONG, &(item->m_iNum), sizeof(SQLUINTEGER), &cbData); SQLGetData(hStmt, 2, SQL_C_CHAR, item->m_sName, NAME_LENGTH, &cbData); ItemTableMap.PutData(count++, item); __TABLE_ITEM_BASIC* pItem = s_pTbl_Items_Basic->Find(item->m_iNum/1000*1000); if(!pItem) printf("Item \"%s\" is missing from the TBL!\n", item->m_sName); } SQLFreeHandle(SQL_HANDLE_STMT, hStmt); SQLDisconnect(hConn); SQLFreeHandle(SQL_HANDLE_DBC, hConn); SQLFreeHandle(SQL_HANDLE_ENV, hEnv); //---- dirent** dir_list; int num_files = fl_filename_list("./item", &dir_list); num_disp_files = 0; for(int i=0; i<num_files; ++i) { int len_fn = strlen(dir_list[i]->d_name); if(!strcmp(&dir_list[i]->d_name[len_fn-7], "n3cplug") || !strcmp(&dir_list[i]->d_name[len_fn-7], "n3cpart")) { disp_files = (char**)realloc(disp_files, ++num_disp_files*sizeof(char*)); disp_files[num_disp_files-1] = (char*)calloc(len_fn+1, sizeof(char)); memcpy(disp_files[num_disp_files-1], dir_list[i]->d_name, len_fn); //char* filename = disp_files[num_disp_files-1]; //N3MeshConverter::Convert(filename); } } fl_filename_free_list(&dir_list, num_files); //---- Fl::use_high_res_GL(true); Fl_Window window(1024, 720, "KO Item Editor"); GLItemViewer sw(window.w()-_gl_width, 30, _gl_width, _gl_height); m_sw = &sw; ItemTableView demo_table(0, 30, window.w()-(_gl_width+0), _gl_height); demo_table.selection_color(FL_YELLOW); demo_table.when(FL_WHEN_RELEASE|FL_WHEN_CHANGED); demo_table.table_box(FL_NO_BOX); demo_table.col_resize_min(4); demo_table.row_resize_min(4); demo_table.row_header(true); demo_table.row_header_width(60); demo_table.row_resize(true); demo_table.rows(num_disp_files /*ItemTableMap.GetSize()*/); demo_table.row_height_all(20); demo_table.col_header(true); demo_table.col_header_height(25); demo_table.col_resize(true); demo_table.cols(1 /*2*/); demo_table.col_width_all(150); Fl_Menu_Bar menubar(0, 0, window.w(), 30); menubar.menu(menu_table); menubar.callback(test_cb); // TODO: need to add the positions and widths/heights as variables Fl_Tabs info_tabs(0, _gl_height+40, window.w(), window.h()-_gl_height-30-10); Fl_Group group(0, _gl_height+40+35, window.w(), window.h()-_gl_height-30-10, "Table Info"); tbl_id = new Fl_Int_Input(80, _gl_height+30+35+20+5, 240, 30, "ID:"); tbl_ext_index = new Fl_Int_Input(80, _gl_height+30+35+20+40+5, 240, 30, "Ext Index:"); tbl_name = new Fl_Input (80, _gl_height+30+35+20+80+5, 240, 30, "Name:"); tbl_remark = new Fl_Input (80, _gl_height+30+35+20+120+5, 240, 30, "Remark:"); group.end(); Fl_Group group2(0, _gl_height+40+35, window.w(), window.h()-_gl_height-30-10, "Database Info"); Fl_Input input2(10, _gl_height+30+35+20, 240, 30); group2.end(); info_tabs.end(); window.end(); window.show(argc, argv); sw.show(); sw.redraw_overlay(); return Fl::run(); }
int main(){ std::cout<"hey\n"; Window window; SDL_Event e; SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_EVERYTHING); window.create("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 600, 600, SDL_WINDOW_SHOWN); window.createRenderer(-1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); int imgFlags = IMG_INIT_PNG; if(!(IMG_Init(imgFlags) & imgFlags)) { return 1; } TTF_Init(); std::cout<"hey\n"; std::vector<Button*> buttonObj; Section buttons(&window, 50, 50, 107, 110); Button b1(&buttons, 0, 0, 107, 55); Button b2(&buttons, 0, 55, 107, 55); Button b3(&buttons, 0, 110, 107, 55); buttonObj.push_back(&b1); buttonObj.push_back(&b2); buttonObj.push_back(&b3); for(auto b : buttonObj){ b->addTexture("not pressed", "img/on.png"); b->addTexture("pressed", "img/off.png"); b->addTexture("hovered", "img/hover.png"); b->setState("not pressed"); b->draw(); } Section inputs(&window, 0, 200, 100, 40); InputBox input(&inputs, 10,"/usr/share/fonts/truetype/freefont/FreeSans.ttf", 20, 0, 0 ); InputBox input2(&inputs, 10, "/usr/share/fonts/truetype/freefont/FreeSans.ttf", 20, 0, 10); bool isRunning = true; SDL_StartTextInput(); //SDL_SetTextInputRect(input.position); while(isRunning){ while(SDL_PollEvent(&e) != 0){ if(e.type == SDL_QUIT){ isRunning = false; } int x, y; SDL_GetMouseState(&x, &y); if(e.type == SDL_MOUSEBUTTONUP){ if(buttons.isIn(x, y)){ for(auto button : buttonObj){ if(button->isIn(x, y)){ button->setState("hovered"); //button.draw(); } } //buttons.update(); } } if(e.type == SDL_MOUSEMOTION){ if(buttons.isIn(x, y)){ for(auto button : buttonObj){ if(button->isIn(x, y)){ button->setState("hovered"); //button.draw(); } else{ button->setState("not pressed"); //button.draw(); } } //buttons.update(); } } if(e.type == SDL_MOUSEBUTTONDOWN){ if(buttons.isIn(x, y)){ for(auto button : buttonObj){ if(button->isIn(x, y)){ button->setState("pressed"); //button.draw(); } } //buttons.update(); } } if(e.type == SDL_TEXTINPUT){ input.insertChar(e.text.text); input.moveCursorRight(); input.draw(); input2.insertChar(e.text.text); input.moveCursorRight(); input.draw(); } if(e.type == SDL_KEYDOWN){ if(e.key.keysym.sym == SDLK_BACKSPACE){ } } if(e.type == SDL_MOUSEWHEEL){ buttons.scroll(e.wheel.x, e.wheel.y); } } SDL_SetRenderDrawBlendMode(window.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(window.renderer, 0xff, 0xff, 0xff, 0xff); SDL_RenderClear(window.renderer); for(auto button: buttonObj){ button->draw(); } buttons.render(); if(input.text.size()> 0){ input.draw(); input2.draw(); inputs.render(); } SDL_RenderPresent(window.renderer); ; } window.close(); }
void ExtractMMApple::execute() { int i, j; unsigned short signature; char fname[256]; Common::Filename inpath1(_inputPaths[0].path); Common::Filename inpath2(_inputPaths[1].path); Common::Filename &outpath = _outputPath; if (outpath.empty()) // Standard output path outpath.setFullPath("out/"); Common::File input1(inpath1, "rb"); Common::File input2(inpath2, "rb"); input1.seek(142080, SEEK_SET); input2.seek(143104, SEEK_SET); /* check signature */ signature = input1.readUint16LE(); if (signature != 0x0A31) error("Signature not found in disk 1!"); signature = input2.readUint16LE(); if (signature != 0x0032) error("Signature not found in disk 2!"); outpath.setFullName("00.LFL"); Common::File output(outpath, "wb"); // All output should be xored output.setXorMode(0xFF); print("Creating 00.LFL...\n"); /* write signature */ output.writeUint16LE(signature); /* copy object flags */ for (i = 0; i < 256; i++) output.writeByte(input1.readByte()); /* copy room offsets */ for (i = 0; i < NUM_ROOMS; i++) { room_disks_apple[i] = input1.readByte(); output.writeByte(room_disks_apple[i]); } for (i = 0; i < NUM_ROOMS; i++) { room_sectors_apple[i] = input1.readByte(); output.writeByte(room_sectors_apple[i]); room_tracks_apple[i] = input1.readByte(); output.writeByte(room_tracks_apple[i]); } /* copy costume offsets */ for (i = 0; i < 25; i++) output.writeByte(input1.readByte()); for (i = 0; i < 25; i++) output.writeUint16LE(input1.readUint16LE()); /* copy script offsets */ for (i = 0; i < 160; i++) output.writeByte(input1.readByte()); for (i = 0; i < 160; i++) output.writeUint16LE(input1.readUint16LE()); /* copy sound offsets */ for (i = 0; i < 70; i++) output.writeByte(input1.readByte()); for (i = 0; i < 70; i++) output.writeUint16LE(input1.readUint16LE()); /* NOTE: Extra 92 bytes of unknown data */ for (i = 0; i < NUM_ROOMS; i++) { Common::File *input; if (room_disks_apple[i] == '1') input = &input1; else if (room_disks_apple[i] == '2') input = &input2; else continue; sprintf(fname, "%02i.LFL", i); outpath.setFullName(fname); output.open(outpath, "wb"); print("Creating %s...\n", fname); input->seek((SectorOffset[room_tracks_apple[i]] + room_sectors_apple[i]) * 256, SEEK_SET); for (j = 0; j < ResourcesPerFile[i]; j++) { unsigned short len = input->readUint16LE(); output.writeUint16LE(len); for (len -= 2; len > 0; len--) output.writeByte(input->readByte()); } input->rewind(); } print("All done!"); }
int main( int argc, char** argv) { if( argc != 3) { std::cerr << "Usage: "<<argv[0]<<" [file1.nc file2.nc]\n"; return -1; } std::cout << "Compare "<<argv[1]<<" with "<<argv[2]<<"\n"; //////////////////////////////open nc files////////////////////////////////// file::NC_Error_Handle err; int ncid1, ncid2; err = nc_open( argv[1], NC_NOWRITE, &ncid1); err = nc_open( argv[2], NC_NOWRITE, &ncid2); int dimIDs1[3], dimIDs2[3], timeID1, timeID2; int numDims1=3, numDims2=3; err = nc_inq_dimid( ncid1, "time", &timeID1); err = nc_inq_dimid( ncid2, "time", &timeID2); err = nc_inq_dimid( ncid1, "x", &dimIDs1[0]); err = nc_inq_dimid( ncid2, "x", &dimIDs2[0]); err = nc_inq_dimid( ncid1, "y", &dimIDs1[1]); err = nc_inq_dimid( ncid2, "y", &dimIDs2[1]); try{ err = nc_inq_dimid( ncid1, "z", &dimIDs1[2]);} catch( file::NC_Error) { numDims1=2; } try{ err = nc_inq_dimid( ncid2, "z", &dimIDs2[2]);} catch( file::NC_Error) { numDims2=2; } if( numDims1 != numDims2) { std::cerr << "Files not of same dimensionality!!\n"; return -1; } size_t length1[numDims1+1], length2[numDims2+1]; err = nc_inq_dimlen(ncid1, timeID1, &length1[numDims1]); err = nc_inq_dimlen(ncid2, timeID2, &length2[numDims2]); for(int i=0; i<numDims1; i++) { err = nc_inq_dimlen(ncid1, dimIDs1[i], &length1[i]); err = nc_inq_dimlen(ncid2, dimIDs2[i], &length2[i]); } for( int i=0; i<numDims1+1; i++) { std::cout << "Dimension "<<i<<" has "<<length1[i]<<" points!\n"; if( length1[i] != length2[i]) { std::cerr << "Dimension lengths not equal!! "<<length1[i]<<" "<<length2[i]<<"\n"; return -1; } } int dataID1, dataID2; try{ err = nc_inq_varid(ncid1, "electrons", &dataID1); err = nc_inq_varid(ncid2, "electrons", &dataID2); } catch( file::NC_Error) { try{ err = nc_inq_varid(ncid1, "T", &dataID1); err = nc_inq_varid(ncid2, "T", &dataID2); } catch( file::NC_Error) { std::cerr <<"Neither electrons nor T found!\n"; return -1; } } size_t start[numDims1+1], count[numDims1+1], size=1; for( int i=0; i<numDims1; i++) { start[numDims1-i] = 0; count[numDims1-i] = length1[i]; size*=length1[i]; } start[0] = 0, count[0] = 1; thrust::host_vector<double> input1( size), input2(input1); for( size_t i=0; i<length1[numDims1]; i++) { start[0] = i; err = nc_get_vara_double( ncid1, dataID1, start, count, input1.data()); err = nc_get_vara_double( ncid2, dataID2, start, count, input2.data()); dg::blas1::axpby( 1., input1, -1., input2, input2); double norm = dg::blas1::dot( input1, input1); double diff = dg::blas1::dot( input2, input2); //double norm2 = *thrust::max_element( input2.begin(), input2.end()); std::cout << "Abs. and rel. difference at timestep \t"<<i<<"\t"<<sqrt(diff)<<"\t"<<sqrt(diff/norm)<<"\n"; } err = nc_close(ncid1); err = nc_close(ncid2); return 0; }
// powerful because it handles both cases when there is material and when there's not void GeometryExporter::createPolylist(short material_index, bool has_uvs, bool has_color, Object *ob, std::string& geom_id, std::vector<Face>& norind) { Mesh *me = (Mesh*)ob->data; MFace *mfaces = me->mface; int totfaces = me->totface; // <vcount> int i; int faces_in_polylist = 0; std::vector<unsigned long> vcount_list; // count faces with this material for (i = 0; i < totfaces; i++) { MFace *f = &mfaces[i]; if (f->mat_nr == material_index) { faces_in_polylist++; if (f->v4 == 0) { vcount_list.push_back(3); } else { vcount_list.push_back(4); } } } // no faces using this material if (faces_in_polylist == 0) { fprintf(stderr, "%s: no faces use material %d\n", id_name(ob).c_str(), material_index); return; } Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL; COLLADASW::Polylist polylist(mSW); // sets count attribute in <polylist> polylist.setCount(faces_in_polylist); // sets material name if (ma) { std::ostringstream ostr; ostr << translate_id(id_name(ma)) << material_index+1; polylist.setMaterial(ostr.str()); } COLLADASW::InputList &til = polylist.getInputList(); // creates <input> in <polylist> for vertices COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); // creates <input> in <polylist> for normals COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1); til.push_back(input1); til.push_back(input2); // if mesh has uv coords writes <input> for TEXCOORD int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); for (i = 0; i < num_layers; i++) { // char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i); COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD, makeUrl(makeTexcoordSourceId(geom_id, i)), 2, // offset always 2, this is only until we have optimized UV sets i // set number equals UV map index ); til.push_back(input3); } if (has_color) { COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::COLOR), has_uvs ? 3 : 2); til.push_back(input4); } // sets <vcount> polylist.setVCountList(vcount_list); // performs the actual writing polylist.prepareToAppendValues(); // <p> int texindex = 0; for (i = 0; i < totfaces; i++) { MFace *f = &mfaces[i]; if (f->mat_nr == material_index) { unsigned int *v = &f->v1; unsigned int *n = &norind[i].v1; for (int j = 0; j < (f->v4 == 0 ? 3 : 4); j++) { polylist.appendValues(v[j]); polylist.appendValues(n[j]); if (has_uvs) polylist.appendValues(texindex + j); if (has_color) polylist.appendValues(texindex + j); } } texindex += 3; if (f->v4 != 0) texindex++; } polylist.finish(); }
int main(int argc, char *argv[]) { #if __TBB_FLOW_GRAPH_CPP11_FEATURES try { utility::thread_number_range threads(get_default_num_threads); utility::parse_cli_arguments(argc, argv, utility::cli_argument_pack() //"-h" option for displaying help is present implicitly .positional_arg(threads,"#threads",utility::thread_number_range_desc) .arg(verbose,"verbose"," print diagnostic output to screen") .arg(silent,"silent"," limits output to timing info; overrides verbose") ); if (silent) verbose = false; // make silent override verbose tick_count start = tick_count::now(); for(int p = threads.first; p <= threads.last; p = threads.step(p)) { task_scheduler_init init(p); if (!silent) cout << "graph test running on " << p << " threads.\n"; graph g; { // test buffer: 0, 1 buffer b(g); toggle input(g); led output(g, "OUTPUT", false); // false means we will explicitly call display to see LED make_edge(input.get_out(), input_port<0>(b)); make_edge(output_port<0>(b), output.get_in()); if (!silent) printf("Testing buffer...\n"); input.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input.flip(); // 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test not_gate: 0, 1 not_gate n(g); toggle input(g); led output(g, "OUTPUT", false); make_edge(input.get_out(), input_port<0>(n)); make_edge(output_port<0>(n), output.get_in()); if (!silent) printf("Testing not_gate...\n"); input.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input.flip(); // 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test two-input and_gate: 00, 01, 10, 11 and_gate<2> a(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(a)); make_edge(input1.get_out(), input_port<1>(a)); make_edge(output_port<0>(a), output.get_in()); if (!silent) printf("Testing and_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test three-input or_gate: 000, 001, 010, 100, 011, 101, 110, 111 or_gate<3> o(g); toggle input0(g); toggle input1(g); toggle input2(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(o)); make_edge(input1.get_out(), input_port<1>(o)); make_edge(input2.get_out(), input_port<2>(o)); make_edge(output_port<0>(o), output.get_in()); if (!silent) printf("Testing or_gate...\n"); input2.activate(); input1.activate(); input0.activate(); // 0 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 0 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); // 1 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); input0.flip(); // 0 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); // 1 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 1 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 1 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test two-input xor_gate: 00, 01, 10, 11 xor_gate<2> x(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(x)); make_edge(input1.get_out(), input_port<1>(x)); make_edge(output_port<0>(x), output.get_in()); if (!silent) printf("Testing xor_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test two-input nor_gate: 00, 01, 10, 11 nor_gate<2> n(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(n)); make_edge(input1.get_out(), input_port<1>(n)); make_edge(output_port<0>(n), output.get_in()); if (!silent) printf("Testing nor_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test steady_signal and digit steady_signal input0(g, high); steady_signal input1(g, low); and_gate<2> a(g); or_gate<2> o(g); xor_gate<2> x(g); nor_gate<2> n(g); digit output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(a)); make_edge(input1.get_out(), input_port<1>(a)); make_edge(output_port<0>(a), input_port<0>(output)); make_edge(input0.get_out(), input_port<0>(o)); make_edge(input1.get_out(), input_port<1>(o)); make_edge(output_port<0>(o), input_port<1>(output)); make_edge(input0.get_out(), input_port<0>(x)); make_edge(input1.get_out(), input_port<1>(x)); make_edge(output_port<0>(x), input_port<2>(output)); make_edge(input0.get_out(), input_port<0>(n)); make_edge(input1.get_out(), input_port<1>(n)); make_edge(output_port<0>(n), input_port<3>(output)); if (!silent) printf("Testing steady_signal...\n"); input0.activate(); // 1 input1.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == 6); } { // test push_button push_button p(g); buffer b(g); led output(g, "OUTPUT", !silent); // true means print all LED state changes make_edge(p.get_out(), input_port<0>(b)); make_edge(output_port<0>(b), output.get_in()); if (!silent) printf("Testing push_button...\n"); p.press(); p.release(); p.press(); p.release(); g.wait_for_all(); } { // test one_bit_adder one_bit_adder my_adder(g); toggle A(g); toggle B(g); toggle CarryIN(g); led Sum(g, "SUM"); led CarryOUT(g, "CarryOUT"); make_edge(A.get_out(), input_port<P::A0>(my_adder)); make_edge(B.get_out(), input_port<P::B0>(my_adder)); make_edge(CarryIN.get_out(), input_port<P::CI>(my_adder)); make_edge(output_port<P::S0>(my_adder), Sum.get_in()); make_edge(output_port<1>(my_adder), CarryOUT.get_in()); A.activate(); B.activate(); CarryIN.activate(); if (!silent) printf("A on\n"); A.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("A off\n"); A.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("B on\n"); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("B off\n"); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("CarryIN on\n"); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("CarryIN off\n"); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&B on\n"); A.flip(); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("A&B off\n"); A.flip(); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&CarryIN on\n"); A.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("A&CarryIN off\n"); A.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("B&CarryIN on\n"); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("B&CarryIN off\n"); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&B&CarryIN on\n"); A.flip(); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == high)); if (!silent) printf("A&B&CarryIN off\n"); A.flip(); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); } #if USE_TWO_BIT_FULL_ADDER { // test two_bit_adder if (!silent) printf("testing two_bit adder\n"); two_bit_adder two_adder(g); std::vector<toggle> A(2, toggle(g)); std::vector<toggle> B(2, toggle(g)); toggle CarryIN(g); digit Sum(g, "SUM"); led CarryOUT(g, "CarryOUT"); make_edge(A[0].get_out(), input_port<P::A0>(two_adder)); make_edge(B[0].get_out(), input_port<P::B0>(two_adder)); make_edge(output_port<P::S0>(two_adder), input_port<0>(Sum)); make_edge(A[1].get_out(), input_port<P::A1>(two_adder)); make_edge(B[1].get_out(), input_port<P::B1>(two_adder)); make_edge(output_port<P::S1>(two_adder), input_port<1>(Sum)); make_edge(CarryIN.get_out(), input_port<P::CI>(two_adder)); make_edge(output_port<P::CO>(two_adder), CarryOUT.get_in()); // Activate all switches at low state for (int i=0; i<2; ++i) { A[i].activate(); B[i].activate(); } CarryIN.activate(); if (!silent) printf("1+0\n"); A[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("0+1\n"); A[0].flip(); B[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); } #else { // test four_bit_adder four_bit_adder four_adder(g); std::vector<toggle> A(4, toggle(g)); std::vector<toggle> B(4, toggle(g)); toggle CarryIN(g); digit Sum(g, "SUM"); led CarryOUT(g, "CarryOUT"); make_edge(A[0].get_out(), input_port<P::A0>(four_adder)); make_edge(B[0].get_out(), input_port<P::B0>(four_adder)); make_edge(output_port<P::S0>(four_adder), input_port<0>(Sum)); make_edge(A[1].get_out(), input_port<P::A1>(four_adder)); make_edge(B[1].get_out(), input_port<P::B1>(four_adder)); make_edge(output_port<P::S1>(four_adder), input_port<1>(Sum)); make_edge(A[2].get_out(), input_port<P::A2>(four_adder)); make_edge(B[2].get_out(), input_port<P::B2>(four_adder)); make_edge(output_port<P::S2>(four_adder), input_port<2>(Sum)); make_edge(A[3].get_out(), input_port<P::A3>(four_adder)); make_edge(B[3].get_out(), input_port<P::B3>(four_adder)); make_edge(output_port<P::S3>(four_adder), input_port<3>(Sum)); make_edge(CarryIN.get_out(), input_port<P::CI>(four_adder)); make_edge(output_port<P::CO>(four_adder), CarryOUT.get_in()); // Activate all switches at low state for (int i=0; i<4; ++i) { A[i].activate(); B[i].activate(); } CarryIN.activate(); if (!silent) printf("1+0\n"); A[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("0+1\n"); A[0].flip(); B[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("3+4\n"); A[0].flip(); A[1].flip(); B[0].flip(); B[2].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low)); if (!silent) printf("6+1\n"); A[0].flip(); A[2].flip(); B[0].flip(); B[2].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low)); if (!silent) printf("0+0+carry\n"); A[1].flip(); A[2].flip(); B[0].flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("15+15+carry\n"); A[0].flip(); A[1].flip(); A[2].flip(); A[3].flip(); B[0].flip(); B[1].flip(); B[2].flip(); B[3].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0xf) && (CarryOUT.get_value() == high)); if (!silent) printf("8+8\n"); A[0].flip(); A[1].flip(); A[2].flip(); B[0].flip(); B[1].flip(); B[2].flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0) && (CarryOUT.get_value() == high)); if (!silent) printf("0+0\n"); A[3].flip(); B[3].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0) && (CarryOUT.get_value() == low)); } #endif { // test D_latch D_latch my_d_latch(g); toggle D(g); pulse E(g, 500, 4); // clock changes every 500ms; stops after 4 changes led Q(g, " Q", verbose); // if true, LEDs print at every state change led notQ(g, "~Q", verbose); make_edge(D.get_out(), input_port<0>(my_d_latch)); make_edge(E.get_out(), input_port<1>(my_d_latch)); make_edge(output_port<0>(my_d_latch), Q.get_in()); make_edge(output_port<1>(my_d_latch), notQ.get_in()); D.activate(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == low) && (notQ.get_value() == high)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == low) && (notQ.get_value() == high)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); } } utility::report_elapsed_time((tbb::tick_count::now() - start).seconds()); return 0; } catch(std::exception& e) { cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n"; return 1; } #else utility::report_skipped(); return 0; #endif // __TBB_FLOW_GRAPH_CPP11_FEATURES }
Intervall parseTermOfIntervals(string input){ string::iterator it; int brackets = 0; int closedBrackets = 0; if(input=="") return 0; for(it=input.end();it>=input.begin();it--){ if(*it=='(') brackets++; if(*it==')') brackets--; if(*it=='[') closedBrackets++; if(*it==']') closedBrackets--; if(*it=='|' && brackets==0 && closedBrackets==0){ if(it==input.begin()){ //Bin‰rem Operator fehlt Operand errorWindow("Operand missing!"); return Intervall(NAN); } if(it+1==input.end()){ //Bin‰rem Operator fehlt Operand errorWindow("Operand missing!"); return Intervall(NAN); } string input1(input.begin(),it); string input2(it+1,input.end()); Intervall result = parseTermOfIntervals(input1)||parseTermOfIntervals(input2); if(result.getInf()!=result.getInf()){ errorWindow("Vereinigung disjunkter Intervalle!"); } return result; } } for(it=input.end();it>=input.begin();it--){ if(*it=='(') brackets++; if(*it==')') brackets--; if(*it=='[') closedBrackets++; if(*it==']') closedBrackets--; if(*it=='&' && brackets==0 && closedBrackets==0){ if(it==input.begin()){ //Bin‰rem Operator fehlt Operand errorWindow("Operand missing!"); return Intervall(NAN); } if(it+1==input.end()){ //Bin‰rem Operator fehlt Operand errorWindow("Operand missing!"); return Intervall(NAN); } string input1(input.begin(),it); string input2(it+1,input.end()); Intervall result = parseTermOfIntervals(input1)&&parseTermOfIntervals(input2); if(result.getInf()!=result.getInf()){ errorWindow("Schnitt disjunkter Intervalle!"); } return result; } } for(it=input.end();it>=input.begin();it--){ if(*it=='(') brackets++; if(*it==')') brackets--; if(*it=='[') closedBrackets++; if(*it==']') closedBrackets--; if(*it=='+' && brackets==0 && closedBrackets==0 && *(it-1)!='/' && *(it-1)!='*' && *(it-1)!='-' && *(it-1)!='+'){ if(it==input.begin()){ string input2(it+1,input.end()); return parseTermOfIntervals(input2); } if(it+1==input.end()){ //Bin‰rem Operator fehlt Operand// errorWindow("Operand missing!"); return Intervall(NAN); } string input1(input.begin(),it); string input2(it+1,input.end()); return parseTermOfIntervals(input1)+parseTermOfIntervals(input2); } if(*it=='-' && brackets==0 && closedBrackets==0 && *(it-1)!='/' && *(it-1)!='*' && *(it-1)!='-' && *(it-1)!='+'){ if(it==input.begin()){ string input2(it+1,input.end()); return Intervall(0)-parseTermOfIntervals(input2); } if(it+1==input.end()){ //Bin‰rem Operator fehlt Operand// errorWindow("Operand missing!"); return Intervall(NAN); } string input1(input.begin(),it); string input2(it+1,input.end()); return parseTermOfIntervals(input1)-parseTermOfIntervals(input2); } } it=input.begin(); if(*it=='('){ brackets++; while(brackets>0){ it++; if(*it=='(') brackets++; if(*it==')') brackets--; } it++; if(it==input.end()){ string input1(input.begin()+1,input.end()-1); return parseTermOfIntervals(input1); } if(*it=='*'){ string input1(input.begin()+1,it-1); if(it+1==input.end()){ //Bin‰rem Operator fehlt Operand// errorWindow("Operand missing!"); return Intervall(NAN); } string input2(it+1,input.end()); return parseTermOfIntervals(input1)*parseTermOfIntervals(input2); } if(*it=='/'){ string input1(input.begin()+1,it-1); if(it+1==input.end()){ //Bin‰rem Operator fehlt Operand// errorWindow("Operand missing!"); return Intervall(NAN); } string input2(it+1,input.end()); Intervall result2 = parseTermOfIntervals(input2); if(result2.getInf()<=0 && result2.getSup()>=0){ //Teilen durch 0! errorWindow("Division by zero!"); return Intervall(NAN); } return parseTermOfIntervals(input1)/result2; } } if(*it=='*' || *it=='/'){ //Bin‰rem Operator fehlt Operand// errorWindow("Operand missing!"); return Intervall(NAN); } closedBrackets = 0; if(*it=='['){ for(;it<input.end();it++){ if(*it=='[') closedBrackets++; if(*it==']') closedBrackets--; if(*it=='*' && closedBrackets==0){ string input1(input.begin(),it); string input2(it+1,input.end()); return parseIntervals(input1)*parseTermOfIntervals(input2); } if(*it=='/' && closedBrackets==0){ string input1(input.begin(),it); string input2(it+1,input.end()); Intervall result2 = parseTermOfIntervals(input2); if(result2.getInf()<=0 && result2.getSup()>=0){ //Teilen durch 0! errorWindow("Division by zero!"); return Intervall(NAN); } return parseIntervals(input1)/result2; } } return parseIntervals(input); } size_t found1 = input.find_first_of("*"); if(found1!=string::npos){ string input1 = input.substr(0,found1); string input2 = input.substr(found1+1); return parseNumbers(input1)*parseTermOfIntervals(input2); } size_t found2 = input.find_first_of("/"); if(found2!=string::npos){ string input1 = input.substr(0,found2); string input2 = input.substr(found2+1); Intervall result2 = parseTermOfIntervals(input2); if(result2.getInf()<=0 && result2.getSup()>=0){ //Teilen durch 0! errorWindow("Division by zero!"); return Intervall(NAN); } return parseNumbers(input1)/result2; } if(found1==string::npos && found2==string::npos){ return parseNumbers(input); } errorWindow("42: "+input); return Intervall(NAN); }