//Loads model information from obj. (simplefied) like described on http://en.wikipedia.org/wiki/Wavefront_.obj_file (25.11.2013; 10:48) bool Model::loadObjFile(const string &filename){ int numberOfVertex, numberOfTriangle; string line; ifstream file(filename.c_str()); fileName = filename; mIsInitialised = file.good(); if(mIsInitialised){ if (file.is_open()) { while ( getline(file,line) ) { if(line.substr(0,2) == "v "){ stringstream ssin(line.substr(2)); vec3 tempValue; ssin >> tempValue.x >> tempValue.y >> tempValue.z; vertices.push_back(tempValue); }else if(line.substr(0,2) == "vt"){ stringstream ssin(line.substr(2)); vec2 tempValue; ssin >> tempValue.x >> tempValue.y ; vTextures.push_back(tempValue); }else if(line.substr(0,2) == "vn"){
int CommandListener::DisableWifiCmd::runCommand(SocketClient *cli, int argc, char ** argv) { dumpArgs(argc, argv, -1); LOG(INFO) << "Running command disable_wifi"; LOG(INFO) << "Number of arguments: " << argc; if(argc > 1){ std::string wifi_uids(argv[1]); int numElements = std::count( wifi_uids.begin(), wifi_uids.end(), ' ' ); int wifiuids[numElements+1]; int i = 0; std::stringstream ssin(wifi_uids); while (ssin.good() && i < numElements+1){ ssin >> wifiuids[i]; ++i; } for(i = 0; i < numElements+1; i++){ LOG(INFO) << "Element " << i << " : " << wifiuids[i]; } FirewallManager *fwm = FirewallManager::Instance(); int result_code = fwm->disableWifi(wifiuids, numElements+1); cli->sendMsg(0, "disabled_wifi completed", false); }
char *proobraz(char* input) { input = registr(input); input= ficha(input); for (int i=0;i<strlen(input);i++) { ssin(i,input); ccos(i,input); aasin(i,input); aacos(i,input); aatan(i,input); cceil(i,input); cch(i,input); eexp(i,input); aabs(i,input); ffloor(i,input); lln(i,input); llog(i,input); ssh(i,input); ssqrt(i,input); ttan(i,input); tth(i,input); cctg(i,input); aactg(i,input); ccth(i,input); } return input; }
string* stringToArrayOfStrings(string str, int countWords){ string* arrayOfStrings = new string[countWords]; int i = 0; stringstream ssin(str); while (ssin.good() && i < 5){ ssin >> arrayOfStrings[i]; ++i; } return arrayOfStrings; }
JValue* loads(std::string buffer, PError& err) { std::stringstream ssin(buffer); IStream fin(ssin); Parser parser(fin); JValue* rst = parser.parse(); if (rst == NULL) { err = parser.error(); } return rst; }
void MatrixRotate(GLSLscalar angle_rad) { GLSLscalar sinAngle = ssin(angle_rad), cosAngle = scos(angle_rad); for (int i = 0; i < /*4*/ 2; i++) { GLSLscalar tmp = mvp_matrix_[i]; mvp_matrix_[ i] = (mvp_matrix_[4+i] * sinAngle) + (tmp * cosAngle); mvp_matrix_[4+i] = (mvp_matrix_[4+i] * cosAngle) - (tmp * sinAngle); mvp_matrix_[8+i] *= cosAngle; } MatrixApply(); }
void undo() { string line; string line_2; ofstream out; out.open("logfile.txt", std::ios_base::app | std::ios_base::out ); m_pInputFile.open("update.txt" ); /* remove_blank("logfile.txt"); remove_blank("update.txt");*/ while(! m_pInputFile.eof()) { getline(m_pInputFile,line); // cout <<line <<"line"<<endl; } m_pInputFile.close(); if (line=="log edited") { remove_blank("logfile.txt"); remove_blank("update.txt"); remove_blank("editedlogs.txt"); // removelastline("logfile.txt"); ifstream editlogs; editlogs.open("editedlogs.txt"); while(! editlogs.eof()) { getline(editlogs, line_2); } string firstCharacter; // line_s=line; stringstream ssin(line_2); ssin >>firstCharacter; cout <<firstCharacter; deletelog(firstCharacter); cout<<line_2; out<<endl<<line_2; out.close(); removelastline("update.txt"); removelastline("deletedlogs.txt"); system("sort -n -k 1 logfile.txt > sorted-out.txt"); remove("logfile.txt"); rename("sorted-out.txt" , "logfile.txt"); removelastline("update.txt"); removelastline("editedlogs.txt"); editlogs.close();}
bool line_parser(graph_type& graph, const std::string& filename, const std::string& textline) { std::istringstream ssin(textline); graphlab::vertex_id_type vid; ssin >> vid; int out_nb; ssin >> out_nb; if (out_nb == 0) graph.add_vertex(vid); while (out_nb--) { graphlab::vertex_id_type other_vid; ssin >> other_vid; graph.add_edge(vid, other_vid); } return true; }
//Load file, create Items and item Array void ItemProcessor::load(std::string nameFile) { nameFile = "./resources/" + nameFile; int numLine = 0; ifstream fe("./Resources/input.txt"); std::string line; while (std::getline(fe, line)) { string arr[5]; int i = 0; stringstream ssin(line); while (ssin.good() && i < 5) { ssin >> arr[i]; ++i; } ItemBuyable *newItem; if (numLine == 0) { _numUniqueItems = atoi(arr[0].c_str()); _cartItems = new ItemBuyable*[_numUniqueItems]; } else { switch (line[0]) { case '1': newItem = new ItemBook(arr[2], arr[1], atof(arr[3].c_str())); break; case '2': newItem = new ItemSuper(arr[1], atof(arr[3].c_str()), atoi(arr[2].c_str())); break; case '3': newItem = new ItemToy(arr[1], arr[2], atof(arr[4].c_str()), atoi(arr[3].c_str())); break; } _cartItems[numLine - 1] = newItem; } numLine++; } fe.close(); }
void CreateCreditAndSpend(const CKeyStore& keystore, const CScript& outscript, CTransactionRef& output, CMutableTransaction& input, bool success = true) { CMutableTransaction outputm; outputm.nVersion = 1; outputm.vin.resize(1); outputm.vin[0].prevout.SetNull(); outputm.vin[0].scriptSig = CScript(); outputm.vout.resize(1); outputm.vout[0].nValue = 1; outputm.vout[0].scriptPubKey = outscript; CDataStream ssout(SER_NETWORK, PROTOCOL_VERSION); ssout << outputm; ssout >> output; assert(output->vin.size() == 1); assert(output->vin[0] == outputm.vin[0]); assert(output->vout.size() == 1); assert(output->vout[0] == outputm.vout[0]); CMutableTransaction inputm; inputm.nVersion = 1; inputm.vin.resize(1); inputm.vin[0].prevout.hash = output->GetHash(); inputm.vin[0].prevout.n = 0; inputm.vout.resize(1); inputm.vout[0].nValue = 1; inputm.vout[0].scriptPubKey = CScript(); bool ret = SignSignature(keystore, *output, inputm, 0, SIGHASH_ALL); assert(ret == success); CDataStream ssin(SER_NETWORK, PROTOCOL_VERSION); ssin << inputm; ssin >> input; assert(input.vin.size() == 1); assert(input.vin[0] == inputm.vin[0]); assert(input.vout.size() == 1); assert(input.vout[0] == inputm.vout[0]); assert(input.vin[0].scriptWitness.stack == inputm.vin[0].scriptWitness.stack); }
/* Converts the string back to integers to use in my program */ void Store::stringToInt (string stringIn) { //Split the string string temp[6]; int i = 0; stringstream ssin(stringIn); while (ssin.good() && i < 6) { ssin >> temp[i]; i++; } //Convert string parts to ints stringstream ss; ss << temp[0] << ' ' << temp[1] << ' ' << temp[2] << ' ' << temp[3] << ' ' << temp[4] << ' ' << temp[5]; ss >> hMIN >> hMAX >> sMIN >> sMAX >> vMIN >> vMAX; cout << "HSV values in : hMIN =" << hMIN << ", "; cout << "hMAX =" << hMAX << ", "; cout << "sMIN =" << sMIN << ", "; cout << "sMAX =" << sMAX << ", "; cout << "vMIN =" << vMIN << ", "; cout << "vMAX =" << vMAX << ", " << endl; }
void InputSimulator::processInput(const std::string &input) { std::vector<std::string> tokens; std::stringstream ssin(input); while (ssin.good()) { std::string value; ssin >> value; tokens.push_back(value); } if (tokens.size() >= 3) { if (tokens[0] == "Mouse" && tokens.size() == 4) { if (tokens[1] == "Move" ) { try { int x = std::stoi(tokens[2]); int y = std::stoi(tokens[3]); moveMouse(x, y); } catch (std::invalid_argument) {} } else if (tokens[1] == "Button") { bool down = tokens[3] == "Down"; if (tokens[2] == "Left") { mouseButton(1, down); } else if (tokens[2] == "Right") { mouseButton(3, down); } } } else if (tokens[0] == "KeyPress" && tokens.size() == 3) { try { bool down = tokens[1] == "Down"; unsigned int keycode = (unsigned int) std::stoi(tokens[2]); key(keycode, down); } catch (std::invalid_argument) {} } } }
void imucalculateestimatedattitude(void) { float EstG[3]; float acc[3]; // holds float accel vector float deltatime; // time in seconds float gyros[3]; vectorcopy ( &EstG[0] , &GEstG[0] ); deltatime = (float)lib_timers_gettimermicrosecondsandreset(&gp_timer) * 0.000001f ; // time in seconds deltatime = deltatime* 0.92; // correction factor // unknown reason readgyro(); readacc(); // correct the gyro and acc readings to remove error // x & y accel offsets only for ( int x = 0; x < 3; ++x) { // was 3 global.gyrorate[x] = global.gyrorate[x] + usersettings.gyrocalibration[x]; global.acc_g_vector[x] = global.acc_g_vector[x] + usersettings.acccalibration[x]; acc[x]= global.acc_g_vector[x]>>6; } // deadzone for yaw rate //global.gyrorate[2] = ( 0 || global.gyrorate[2] > 40000 || global.gyrorate[2]< -40000 ) * global.gyrorate[2] ; for ( int i = 0 ; i < 3; i++) { gyros[i] = tofloat( global.gyrorate[i] ) * deltatime * 0.01745329; } #ifndef SMALL_ANGLE_APPROX // This does a "proper" matrix rotation using gyro deltas without small-angle approximation float mat[3][3]; float tempvect[3]; float cosx, sinx, cosy, siny, cosz, sinz; float coszcosx, coszcosy, sinzcosx, coszsinx, sinzsinx; vectorcopy ( &tempvect[0] , & EstG[0] ); // the signs are differnt due to different conventions // for positive/negative angles in various multiwii forks this is based on cosx = _cosf( gyros[1]); sinx = _sinf( gyros[1]); cosy = _cosf( -gyros[0]); siny = _sinf( -gyros[0]); cosz = _cosf( -gyros[2]); sinz = _sinf( -gyros[2]); coszcosx = cosz * cosx; coszcosy = cosz * cosy; sinzcosx = sinz * cosx; coszsinx = sinx * cosz; sinzsinx = sinx * sinz; mat[0][0] = coszcosy; mat[0][1] = -cosy * sinz; mat[0][2] = siny; mat[1][0] = sinzcosx + (coszsinx * siny); mat[1][1] = coszcosx - (sinzsinx * siny); mat[1][2] = -sinx * cosy; mat[2][0] = (sinzsinx) - (coszcosx * siny); mat[2][1] = (coszsinx) + (sinzcosx * siny); mat[2][2] = cosy * cosx; EstG[0] = tempvect[0] * mat[0][0] + tempvect[1] * mat[1][0] + tempvect[2] * mat[2][0]; EstG[1] = tempvect[0] * mat[0][1] + tempvect[1] * mat[1][1] + tempvect[2] * mat[2][1]; EstG[2] = tempvect[0] * mat[0][2] + tempvect[1] * mat[1][2] + tempvect[2] * mat[2][2]; #endif // end rotation matrix #ifdef SMALL_ANGLE_APPROX // this is a rotation with small angle approximation float deltagyroangle; // holds float gyro angle in rad // Rotate Estimated vector(s), ROLL EstG[2] = scos(gyros[0]) * EstG[2] - ssin(gyros[0]) * EstG[0]; EstG[0] = ssin(gyros[0]) * EstG[2] + scos(gyros[0]) * EstG[0]; // Rotate Estimated vector(s), PITCH EstG[1] = scos(gyros[1]) * EstG[1] + ssin(gyros[1]) * EstG[2]; EstG[2] = -ssin(gyros[1]) * EstG[1] + scos(gyros[1]) * EstG[2]; // Rotate Estimated vector(s), YAW EstG[0] = scos(gyros[2]) * EstG[0] - ssin(gyros[2]) * EstG[1]; EstG[1] = ssin(gyros[2]) * EstG[0] + scos(gyros[2]) * EstG[1]; #endif // end small angle approx // yaw not tested ( maybe for yaw hold? ) // includes deadzone // global.currentestimatedeulerattitude[YAWINDEX] += ( 0 || global.gyrorate[2] > 40000 || global.gyrorate[2]< -40000 ) * ( (float) ( global.gyrorate[2] ) * deltatime + 0.5f); // yaw without deadzone // not tested , i am not sure what the yaw angle is even used for global.currentestimatedeulerattitude[YAWINDEX] += ( (float) ( global.gyrorate[2] ) * deltatime); lib_fp_constrain180(&global.currentestimatedeulerattitude[YAWINDEX]); // global.estimateddownvector[ZINDEX] < 0 // in pilotcontrol.c fix for inverted(not tested) global.estimateddownvector[ZINDEX] = (EstG[2]>0)? 1111:-1111 ; // orientation vector magnitude float mag = 0; mag = calcmagnitude( &EstG[0] ); // normalize orientation vector if (1) { for (int axis = 0; axis < 3; axis++) { EstG[axis] = EstG[axis] / ( mag / ACC_1G ); } } //debug4 = mag; // calc acc mag float accmag; accmag = calcmagnitude( &acc[0] ); // debug2 = accmag; //normvector( acc , accmag, normal); // normalize acc for (int axis = 0; axis < 3; axis++) { acc[axis] = acc[axis] / (accmag / ACC_1G) ; } // test acc mag //debug5 = calcmagnitude( &acc[0] ); /* Set the Gyro Weight for Gyro/Acc complementary filter */ /* Increasing this value would reduce and delay Acc influence on the output of the filter*/ // times for 3ms loop time // filter time changes linearily with loop time // 0.970 0.1s // 0.988 0.25s // 0.994 0.5 s // 0.996 0.75 s // 0.997 1.0 sec // 0.998 1.5 sec // 0.9985 2 sec // 0.999 3 sec // 0.99925 4 s #define GYR_CMPF_FACTOR 0.998f // was 0.998 #define DISABLE_ACC 0 #define ACC_MIN 0.8f #define ACC_MAX 1.2f static unsigned int count = 0; if ( ( accmag > ACC_MIN * ACC_1G ) && ( accmag < ACC_MAX * ACC_1G ) && !DISABLE_ACC ) { //for (axis = 0; axis < 3; axis++) if ( count >= 10 ) // loop time = 3ms so 30ms wait { //x4_set_leds( 0xFF); EstG[0] = EstG[0] * GYR_CMPF_FACTOR + (float)acc[0] * ( 1.0f - GYR_CMPF_FACTOR ); EstG[1] = EstG[1] * GYR_CMPF_FACTOR + (float)acc[1] * ( 1.0f - GYR_CMPF_FACTOR ); EstG[2] = EstG[2] * GYR_CMPF_FACTOR + (float)acc[2] * ( 1.0f - GYR_CMPF_FACTOR ); } count++; } else {// acc mag out of bounds //x4_set_leds( 0x00); count = 0; } vectorcopy ( &GEstG[0] , &EstG[0]); // convert our vectors to euler angles global.currentestimatedeulerattitude[ROLLINDEX] = lib_fp_atan2( FIXEDPOINTCONSTANT(EstG[0]*8 ), FIXEDPOINTCONSTANT(EstG[2]*8 ) ) ; /* global.currentestimatedeulerattitude[PITCHINDEX] = lib_fp_atan2( FIXEDPOINTCONSTANT( EstG[1]*8), FIXEDPOINTCONSTANT( EstG[2]*8) ); */ if (lib_fp_abs(global.currentestimatedeulerattitude[ROLLINDEX]) > FIXEDPOINT45 && lib_fp_abs(global.currentestimatedeulerattitude[ROLLINDEX]) < FIXEDPOINT135) { global.currentestimatedeulerattitude[PITCHINDEX] = lib_fp_atan2(EstG[1]*8, lib_fp_abs(EstG[0])*8); } else { global.currentestimatedeulerattitude[PITCHINDEX] = lib_fp_atan2( EstG[1]*8, EstG[2]*8); } }
Facility::Facility(int facil, std::string in, boost::variate_generator< boost::mt19937&, boost::random::triangle_distribution < > > * triangle, boost::variate_generator< boost::mt19937&, boost::random::uniform_real_distribution < > > * uniform, int incdist, double upinc, double lowinc, int infdist, double upinf, double lowinf) { facility = facil; std::string input[11]; int i = 0; std::stringstream ssin(in); while (ssin.good() && i < 11) { ssin >> input[i]; ++i; } name = input[0]; subfacil = stoi(input[1]); startS = stoi(input[2]); startE = stoi(input[3]); startI = stoi(input[4]); bed_size = stoi(input[5]); prev = stod(input[6]); inc = stod(input[7]); LOS_mean = stod(input[8]); LOS_dev = stod(input[9]); LOS_dist = stoi(input[10]); RNGpoint = uniform; triangleRNGpoint = triangle; genpoint = new boost::mt19937 (time(0)); //create RNG boost::random::lognormal_distribution< > lognormalDistribution(LOS_mean, LOS_dev); boost::random::normal_distribution< > normalDistribution(LOS_mean, LOS_dev); lognormRNGpoint = new boost::variate_generator< boost::mt19937&, boost::random::lognormal_distribution < > >(*genpoint, lognormalDistribution); normalRNGpoint = new boost::variate_generator< boost::mt19937&, boost::random::normal_distribution < > >(*genpoint, normalDistribution); inf_dist = infdist; inc_dist = incdist; lower_inf = lowinf; upper_inf = upinf; lower_inc = lowinc; upper_inc = upinc; //initialize agents for (int i = 0; i < startS; i++) { Agent * a = new Agent(); (*a).setState(0); (*a).setEI(-1); (*a).setIS(-1); (*a).setDischarge(LOS()); (*a).setFacility(facility); agents.push_back(a); } for (int i = 0; i < startE; i++) { Agent * a = new Agent(); (*a).setState(1); if (inc_dist == 1 || inc_dist == 0) { //uniform or single value (*a).setEI(ceil(randUniform()*(upper_inc - lower_inc)) + lower_inc); } else if (inc_dist == 2) { //triangular (*a).setEI(ceil(randTriangle()*(upper_inc - lower_inc)) + lower_inc); } (*a).setIS(-1); (*a).setDischarge(LOS()); (*a).setFacility(facility); agents.push_back(a); } for (int i = 0; i < startI; i++) { Agent * a = new Agent(); (*a).setState(2); (*a).setEI(-1); if (inf_dist == 1 || inf_dist == 0) { //uniform or single value (*a).setIS(ceil(randUniform()*(upper_inf - lower_inf)) + lower_inf); } else if (inf_dist == 2) { //triangular (*a).setIS(ceil(randTriangle()*(upper_inf - lower_inf)) + lower_inf); } (*a).setDischarge(LOS()); (*a).setFacility(facility); agents.push_back(a); } }
void parse() { string tmp = ""; redirect_to = ""; delay = 0; list.clear(); recv_from_user = 0; send_to_user_flag = 0; /***********************************************************************************************/ for (int i = 0; i < cmd.size(); i++) { if (cmd[i] == ' ' || cmd[i] == '\t' || cmd[i] == '\n' || cmd[i] == '\r') { if (tmp != "") { list.push_back(tmp); tmp = ""; } } else tmp += cmd[i]; } if (tmp != "")list.push_back(tmp); /***********************************************************************************************/ for (int i = 0; i < list.size(); i++) { /* this code assume those pipe commands (i.e. > file name >| >!) will appear at the last list */ if (list[i] == ">") { redirect_to = list[i+1]; list.erase(list.begin() + i); list.erase(list.begin() + i); } if (list[i] == ">|") { list.erase(list.begin() + i); send_to_user_flag = 1; } if (list[i] == ">!") { list.erase(list.begin() + i); send_to_user_flag = 2; } if (list[i][0] == '<') { //cout << "in!" << endl; list[i].erase(0,1); istringstream ssin(list[i]); ssin >> recv_from_user; list.erase(list.begin() + i); } }
int main(int argc, char *argv[]) { if (exist("konfig.txt")) { FILE *konfIN, *konfOUT; konfIN = fopen("konfig.txt", "rb");//File to be encrypted; plain text konfOUT = fopen("temp.txt", "wb"); decrypt(konfIN, konfOUT, tajneHaslo); fclose(konfIN); fclose(konfOUT); std::string buffer; std::ifstream fin("temp.txt"); getline(fin, buffer, char(-1)); fin.close(); char inpute[100]; std::cout << "Podaj pin: " << std::endl; std::cin.getline(inpute, sizeof(inpute)); std::string arr[4]; int i = 0; std::stringstream ssin(buffer); while (ssin.good() && i < 4){ ssin >> arr[i]; ++i; } if (remove("temp.txt") != 0) perror("Error deleting file"); //std::cout << arr[0]; if (arr[0] == inpute) { std::string buffer2; std::ifstream keystore("keystore.txt"); getline(keystore, buffer2, char(-1)); keystore.close(); std::string arr2[4]; i = 0; std::stringstream ssin(buffer2); while (ssin.good() && i < 4){ ssin >> arr2[i]; ++i; } FILE *fIN, *fOUT; fIN = fopen("example1.mp3", "rb");//File to be written; cipher text fOUT = fopen("tt3.mp3", "wb");//File to be written; cipher text unsigned char* keyg = (unsigned char*)arr2[1].c_str(); decrypt(fIN, fOUT, keyg); std::cout << arr2[1] << " . " << arr2[2] << std::endl; fclose(fIN); fclose(fOUT); //puszczenie mp3 std::string ll = "tt3.mp3"; std::string luj = "open " + ll + " type mpegvideo alias song1 "; MCIERROR me = mciSendString(luj.c_str(), NULL, 0, 0); if (me == 0) { me = mciSendString("play song1 wait", NULL, 0, 0); mciSendString("close song1", NULL, 0, 0); } if (remove("tt3.mp3") != 0) perror("Error deleting file"); }