static void ShowBuildTime(char *trgPath) { trgPath = makeFullPath(trgPath); if(existDir(trgPath)) { autoList_t *paths = lss(trgPath); char *path; uint index; sortJLinesICase(paths); foreach(paths, path, index) { char *relPath = changeRoot(strx(path), trgPath, NULL); if(existDir(path)) { cout("------------------------ %s\n", relPath); } else if( !_stricmp("exe", getExt(path)) || !_stricmp("dll", getExt(path)) || !_stricmp("exe_", getExt(path)) || !_stricmp("dll_", getExt(path)) ) { ShowBuildTime_File(path, relPath); } else { char *hash = md5_makeHexHashFile(path); hash[16] = '\0'; cout(" %s %s\n", hash, relPath); memFree(hash); } memFree(relPath); } releaseDim(paths, 1); }
void CSVReader::parse_line_into_vec ( const std::string& line ) { m_tmp_line.clear(); //clear temp storage std::string tmp; std::istringstream iss(line); while ( std::getline(iss,tmp,'"') ) { std::istringstream lss(tmp); while ( std::getline(lss,tmp, ',') ) m_tmp_line.push_back(tmp); if ( std::getline(iss,tmp,'"') ) m_tmp_line.push_back(tmp); if ( tmp == "" ) m_tmp_line.push_back(""); } }
// Populate this MobTemplate with a data file. // Generally a CSV file. int8_t MOBTemplate::loadFromFile(std::string path, std::vector<Weapon>& allAttacks) { std::ifstream input; input.open(path); // File could not be opened. if (!input) { std::cout << "Could not open " << path<< std::endl; return -1; } std::string line; while (std::getline(input, line)) { std::cout << "Load: " << line << std::endl; std::istringstream lss(line); std::string token; std::string cols[4]; for (int i = 0; i < 4 && std::getline(lss, token, ','); ++i) { cols[i] = token; } // Commence the actual parsing! std::transform(cols[0].begin(), cols[0].end(), cols[0].begin(), tolower); if (!cols[0].compare("name")) { name = cols[1]; } else if(!cols[0].compare("index")) { index = cols[1]; } else if (!cols[0].compare("multiplier")) { int weap = (int)weaponClass(cols[1]); if (weap > N_WEAPONCLASS || weap == 0) { std::cout << "Invalid weapon class in "<<path<<", \"" << line << "\"" << std::endl; } else { resistances[weap] = std::stof(cols[2]); } } else if (!cols[0].compare("icon")) { icon.loadFromFile(cols[1]); } else if (!cols[0].compare("weapon")) { bool found = false; for (int i = 0; i < allAttacks.size() && !found; i++) { if (!allAttacks[i].index.compare(cols[1])) { attacks.push_back(allAttacks[i]); found = true; std::cout << "Found weapon " << cols[1] << std::endl; } } if (!found) { std::cout << "Could not find weapon \"" << cols[1] << "\" from " << path << "" << std::endl; } } else if (!cols[0].compare("hp")) { DefaultStats.MaxHealth = std::stof(cols[1]); } else if (!cols[0].compare("speed")) { std::cout << "Setting speed: " << cols[1] << std::endl; DefaultStats.MovementSpeed = std::stof(cols[1]); } else if (!cols[0].compare("lineofsight")) { DefaultStats.SightDistance = std::stof(cols[1]); } else if (!cols[0].compare("unitType")) { DefaultStats.type = (UnitType)std::stoi(cols[1]); } else if (!cols[0].compare("texsizey")) { texSize.x = (UnitType)std::stoi(cols[1]); } else if (!cols[0].compare("texsizey")) { texSize.y = (UnitType)std::stoi(cols[1]); } } return 0; // VICTORY! }
void opr() { switch ( ir.m) { //rtn case 0: ret(); break; //neg case 1: neg(); break; //add case 2: add(); break; //sub case 3: sub(); break; //mul case 4: mul(); break; //div case 5: divid(); break; //odd case 6: odd(); break; //mod case 7: mod(); break; //eql case 8: eql(); break; //neq case 9: neq(); break; //lss case 10: lss(); break; //leq case 11: leq(); break; //gtr case 12: gtr(); break; //geq case 13: geq(); break; default: fprintf(output, "OP code input was invalid. "); sio3(); } }
void executeInstruction() { switch(ir.op) { case 1: lit(); break; case 2: opr(); break; case 3: lod(); break; case 4: sto(); break; case 5: cal(); break; case 6: inc(); break; case 7: jmp(); break; case 8: jpc(); break; case 9: sio(); default: break; } void opr() { switch ( ir.m) { //rtn case 0: ret(); break; //neg case 1: neg(); break; //add case 2: add(); break; //sub case 3: sub(); break; //mul case 4: mul(); break; //div case 5: divid(); break; //odd case 6: odd(); break; //mod case 7: mod(); break; //eql case 8: eql(); break; //neq case 9: neq(); break; //lss case 10: lss(); break; //leq case 11: leq(); break; //gtr case 12: gtr(); break; //geq case 13: geq(); break; default: fprintf(output, "OP code input was invalid. "); halt = 1; break; } } }
int SCBus::setup_batch(const char* file_name) { cout << "SCBus: setup_batch() invoked" << endl; cout << "Parsing file '" << file_name << "'" << endl; std::string line; // FIXME: check why std:: is needed here ifstream infile(file_name); if (!infile.is_open()) { cout << "SCBus: Unable to open file '" << file_name << "'" << endl; } SCBusPacket packet; unsigned int dctr, data, lctr; long long ts, ts_last; ts_last = 0; lctr = 0; while (std::getline(infile, line)) { std::istringstream lss(line); std::string token; lctr++; getline(lss,token,' '); ts = std::stoll(token.c_str()); if (ts_last >= ts && ts_last != 0) { cout << "WARNING: SCBus batch file time stamp is out of sequence in line " << lctr << ":" << endl; cout << "'" << line << "' (ignoring line)" << endl; continue; } memset(&packet, 0, sizeof(SCBusPacket)); packet.header.timestamp = ts; dctr = 0; while (std::getline(lss,token,' ')) { if (dctr == SCBUS_PACKET_MAX_DATA_LENGTH-1) { cout << "WARNING: SCBus batch file data length is over the limit (" << (int)SCBUS_PACKET_MAX_DATA_LENGTH << ") in line " << lctr << " (truncating line)" << endl; break; } data = std::stoul(token.c_str(),nullptr,16); if (data > 255) { cout << "WARNING: SCBus batch file data out of range in line " << lctr << ":" << endl; cout << "'" << line << "' (truncating value)" << endl; data &= 0xFFul; } packet.data[dctr++] = (char)data; } if (dctr == 0) { cout << "WARNING: SCBus batch file with empty data field in line " << lctr << ":" << endl; cout << "'" << line << "' (ignoring line)" << endl; continue; } packet.header.length = dctr; batch_fifo.push(packet); ts_last = ts; } cout << "Parsing done" << endl; infile.close(); return 0; }
void Tri2dFCBlockSolver::gradSetupQuadratic() { // form quadratic sub elements int nElemQ = 3*nElem; int nneQ = 6; //quadratic elements int nngQ = 4; //quadratic elements Array2D<int> elemQ(nElemQ,nneQ),gNode(nElemQ,nngQ); int m=0; for (int n=0; n<nElem; n++){ elemQ(m ,0) = elem(n,0); elemQ(m ,1) = elem(n,4); elemQ(m ,2) = elem(n,7); elemQ(m ,3) = elem(n,3); elemQ(m ,4) = elem(n,9); elemQ(m ,5) = elem(n,8); gNode(m ,0) = 0; gNode(m ,1) = 3; gNode(m ,2) = 4; gNode(m++,3) = 5; elemQ(m ,0) = elem(n,3); elemQ(m ,1) = elem(n,1); elemQ(m ,2) = elem(n,6); elemQ(m ,3) = elem(n,4); elemQ(m ,4) = elem(n,5); elemQ(m ,5) = elem(n,9); gNode(m ,0) = 1; gNode(m ,1) = 4; gNode(m ,2) = 5; gNode(m++,3) = 3; elemQ(m ,0) = elem(n,8); elemQ(m ,1) = elem(n,5); elemQ(m ,2) = elem(n,2); elemQ(m ,3) = elem(n,9); elemQ(m ,4) = elem(n,6); elemQ(m ,5) = elem(n,7); gNode(m ,0) = 2; gNode(m ,1) = 5; gNode(m ,2) = 3; gNode(m++,3) = 4; } /* for (int n=0; n<nElemQ; n++){ cout << n << " "; for (int j=0; j<nneQ; j++) cout << elemQ(n,j) << " "; cout << endl; } exit(0); */ // Jacobian terms Array2D <double> xr(nElemQ,nngQ),yr(nElemQ,nngQ),xs(nElemQ,nngQ), ys(nElemQ,nngQ),jac(nElemQ,nngQ),rs(nneQ,3),lc(nneQ,nneQ); xr.set(0.); yr.set(0.); xs.set(0.); ys.set(0.); jac.set(0.); int orderE=2; //quadratic elements solutionPoints(orderE, spacing, &rs(0,0)); bool test=true; lagrangePoly(test, orderE, &rs(0,0), &lc(0,0)); int j,km,lm; double lrm,lsm,ri,si; for (int n=0; n<nElemQ; n++){ // evaluate the Jacobian terms at the mesh points for (int i=0; i<nngQ; i++){ //ith mesh point ri = rs(gNode(n,i),0); si = rs(gNode(n,i),1); for (int m=0; m<nneQ; m++){ //mth Lagrange polynomial j = 0; lrm = 0.; lsm = 0.; for (int k=0; k<=orderE; k++) for (int l=0; l<=orderE-k; l++){ km = max(0,k-1); lm = max(0,l-1); lrm +=((double)k)*pow(ri,km)*pow(si,l )*lc(m,j ); lsm +=((double)l)*pow(ri,k )*pow(si,lm)*lc(m,j++); } xr(n,i) += lrm*x(elemQ(n,m),0); yr(n,i) += lrm*x(elemQ(n,m),1); xs(n,i) += lsm*x(elemQ(n,m),0); ys(n,i) += lsm*x(elemQ(n,m),1); } jac(n,i) = xr(n,i)*ys(n,i)-yr(n,i)*xs(n,i); }} // lr(i,j) = (dl_j/dr)_i (a row is all Lagrange polynomials (derivatives) // evaluated at a single mesh point i, same with the other derivatives) Array2D<double> lr(nneQ,nneQ),ls(nneQ,nneQ),lrr(nneQ,nneQ), lss(nneQ,nneQ),lrs(nneQ,nneQ); lr.set(0.); ls.set(0.); lrr.set(0.); lss.set(0.); lrs.set(0.); int kmm,lmm; for (int n=0; n<nneQ; n++) // nth Lagrange polynomial for (int i=0; i<nneQ; i++){ // ith mesh point j = 0; ri = rs(i,0); si = rs(i,1); for (int k=0; k<=orderE; k++) for (int l=0; l<=orderE-k; l++){ km = max(0,k-1); lm = max(0,l-1); kmm = max(0,k-2); lmm = max(0,l-2); lr (i,n) +=((double)k)*pow(ri,km)*pow(si,l )*lc(n,j); ls (i,n) +=((double)l)*pow(ri,k )*pow(si,lm)*lc(n,j); lrr(i,n) +=((double)(k*km))*pow(ri,kmm)*pow(si,l )*lc(n,j ); lss(i,n) +=((double)(l*lm))*pow(ri,k )*pow(si,lmm)*lc(n,j ); lrs(i,n) +=((double)(k*l ))*pow(ri,km )*pow(si,lm )*lc(n,j++); }} // compute averaged quadratic FEM gradient coefficients Array1D<double> sumj(nNode); sumj.set(0.); for (int n=0; n<nElemQ; n++) for (int i=0; i<nngQ; i++){ m = gNode(n,i); sumj(elemQ(n,m)) += jac(n,i); } for (int n=0; n<nNode; n++) sumj(n) = 1./sumj(n); int k1,k2; double xri,yri,xsi,ysi; Array2D<double> ax(nNode,2); ax.set(0.); gxQ.set(0.); for (int n=0; n<nElemQ; n++) for (int i=0; i<nngQ; i++){ m = gNode(n,i); k1 = elemQ(n,m); xri = xr(n,i); yri = yr(n,i); xsi = xs(n,i); ysi = ys(n,i); for (int j=0; j<nneQ; j++){ k2 = elemQ(n,j); ax(k2,0) = lr(m,j)*ysi-ls(m,j)*yri; ax(k2,1) =-lr(m,j)*xsi+ls(m,j)*xri; } for(int j=psp2(k1); j<psp2(k1+1); j++){ k2 = psp1(j); gxQ(j,0) += ax(k2,0); gxQ(j,1) += ax(k2,1); } for (int j=0; j<nneQ; j++){ k2 = elemQ(n,j); ax(k2,0) = 0.; ax(k2,1) = 0.; }} for (int n=0; n<nNode; n++) for (int i=psp2(n); i<psp2(n+1); i++){ gxQ(i,0) *= sumj(n); gxQ(i,1) *= sumj(n); } // deallocate work arrays elemQ.deallocate(); gNode.deallocate(); xr.deallocate(); yr.deallocate(); xs.deallocate(); ys.deallocate(); jac.deallocate(); rs.deallocate(); lc.deallocate(); lr.deallocate(); ls.deallocate(); lrr.deallocate(); lss.deallocate(); lrs.deallocate(); sumj.deallocate(); ax.deallocate(); }