int main(int argc, char * argv[]) { int szx = 0, szy = 0, szz = 0; /* x, y, z sizes */ if (argc > 1) { /* single size specified */ szx = szy = szz = atoi(argv[1]); } if (argc > 2) { /* Two sizes specified */ szz = 0; szy = atoi(argv[2]); } if (argc > 3) { /* Three sizes specified */ szz = atoi(argv[3]); } if (szx == 0) szx = 10; if (szy == 0) szy = 10; if (szz == 0) szz = 10; DTArray write_testing(szx,szy,szz); firstIndex ii; secondIndex jj; thirdIndex kk; /* Initialize the array with "coordinates" */ write_testing = ii + 10*jj + 100*kk; /* And test the written outputs */ write_array(write_testing,"dat_seq",0); write_array(write_testing,"dat_seq",1); write_reader(write_testing,"dat_seq",true); /* Nonsequenced version */ write_array(write_testing,"dat_nsq"); write_reader(write_testing,"dat_nsq"); return 0; }
int main(int argc, char* argv[]) { CGAL::Timer timer; // first param is dimension // second param is number of points int dimension = 4; int n = 100; int m = 100; if (argc > 1 && std::string(argv[1])== std::string("-h")) { std::cout<<"usage: "<<argv[0]<<" [dim] [#points] [max coords]\n"; return 1; } if (argc > 1) dimension = atoi(argv[1]); if (argc > 2) n = atoi(argv[2]); if (argc > 3) m = atoi(argv[2]); Delaunay_d T(dimension); std::list<Point_d> L; random_points_in_range(n,dimension,-m,m,L); timer.start(); int i=0; std::list<Point_d>::iterator it; for(it = L.begin(); it!=L.end(); ++it) { T.insert(*it); i++; if (i%10==0) std::cout << i << " points inserted" << std::endl; } timer.stop(); std::cout << "used time for inserts " << timer.time() << std::endl; std::cout << "entering check" << std::endl; timer.reset(); timer.start(); T.is_valid(); timer.stop(); std::cout << "used time for sanity check " << timer.time() << std::endl; std::cout << "entering nearest neighbor location" << std::endl; L.clear(); random_points_in_range(n/10,dimension,-m,m,L); timer.reset(); timer.start(); i = 0; for(it = L.begin(); it!=L.end(); ++it) { T.nearest_neighbor(*it); i++; if (i%10==0) std::cout << i << " points located" << std::endl; } timer.stop(); std::cout << "used time for location " << timer.time() << std::endl; T.print_statistics(); std::cout << "done" << std::endl; return 0; }
Content& Content::updatePlayer(const std::string &steamID64, const std::string &category, std::unordered_map<std::string, int> stats) { char *errMsg; stringstream select(stringstream::out), upsert(stringstream::out); int id= Utils::hashCode(steamID64 + "-" + category); vector<string> newStats(stats.size()); auto playerTable= [&stats](void *tableName, int argc, char **argv, char **colName) -> int { vector<string> statPairs= Utils::split(argv[3], ','); for(auto it= statPairs.begin(); it != statPairs.end(); it++) { vector<string> keyval= Utils::split(*it, '='); if (stats.count(keyval[0]) == 0) { stats[keyval[0]]= atoi(keyval[1].c_str()); } else { stats[keyval[0]]+= atoi(keyval[1].c_str()); } } return 0; }; select << "select * from player where id=" << id; sqlite3_exec(db, select.str().c_str(), playerTable, NULL, &errMsg); for(auto it= stats.begin(); it != stats.end(); it++) { stringstream keyval(stringstream::out); keyval << it->first << "=" << it->second; newStats.push_back(keyval.str()); } upsert << "replace into player (id, steamid, stats, category) values (" << id << ", coalesce(( select steamid from player where id=" << id << "),\'" << steamID64 << "\'), \'" << Utils::join(newStats, ',') << "\', coalesce(( select category from player where id=" << id << "),\'" << category << "\'));"; sqlite3_exec(db, upsert.str().c_str(), NULL, NULL, &errMsg); return *this; }
unsigned int GetApuesta(unsigned int &Dinero){ echo(); int bet; bool ValidBet=false; while(!ValidBet){ mvprintw(20,0,"Ingrese apuesta (Si no desea seguir jugando, apueste 0): "); char actual; int TempBet; string getbet=""; while((actual=getch())!=10){ if(actual>47&&actual<58){ getbet.push_back(actual); } } TempBet=atoi(getbet.c_str()); if(Dinero<TempBet){ mvprintw(23,0,"Apuesta invalida, no puede apostar una cantidad mayor a su dinero actual (%d)",Dinero); }else{ bet=TempBet; Dinero-=bet; ValidBet=true; } } noecho(); return bet; }
int main() { int i = atoi( "2593" ); // convert string to int cout << "The string \"2593\" converted to int is " << i << "\nThe converted value minus 593 is " << i - 593 << endl; return 0; } // end main
int String2Int (string& iStlString) { // stringstream theTmpStream (iStlString); // int theRetInt; // theTmpStream >> theRetInt; // return theRetInt; return atoi (iStlString.c_str()); }
int WebRequest::contentLength() const { std::string lenstr = envValue("CONTENT_LENGTH"); if (lenstr.empty()) return 0; else return atoi(lenstr.c_str()); }
Content& Content::updateRecord(const std::string &steamID64, int wins, int losses, int disconnects) { char *errMsg; stringstream select(stringstream::out), upsert(stringstream::out); int id= Utils::hashCode(steamID64); auto recordTable= [&wins, &losses, &disconnects](void *tableName, int argc, char **argv, char **colName) -> int { wins+= atoi(argv[2]); losses+= atoi(argv[3]); disconnects+= atoi(argv[4]); return 0; }; select << "select * from records where id=" << id; sqlite3_exec(db, select.str().c_str(), recordTable, NULL, &errMsg); upsert << "replace into records (id, steamid, wins, losses, disconnects) values (" << id << ", coalesce(( select steamid from records where id=" << id << "),\'" << steamID64 << "\'), " << wins << ", " << losses << ", " << disconnects << ");"; sqlite3_exec(db, upsert.str().c_str(), NULL, NULL, &errMsg); return *this; }
Content& Content::updateLevel(const std::string &name, int wins, int losses, Time time) { char *errMsg; stringstream select(stringstream::out), upsert(stringstream::out); int id= Utils::hashCode(name); auto levelTable= [&wins, &losses, &time](void *tableName, int argc, char **argv, char **colName) -> int { wins+= atoi(argv[2]); losses+= atoi(argv[3]); time.add(argv[4]); return 0; }; select << "select * from levels where id=" << id; sqlite3_exec(db, select.str().c_str(), levelTable, NULL, &errMsg); upsert << "replace into levels (id, name, wins, losses, time) values (" << id << ", coalesce(( select name from levels where id=" << id << "),\'" << name << "\'), " << wins << ", " << losses << ", \'" << time.toString() << "\');"; sqlite3_exec(db, upsert.str().c_str(), NULL, NULL, &errMsg); return *this; }
void Version::assign(const std::string new_version) { string tempStr; vector<string> parts; size_t i= 0; while(i < new_version.size()) { if (new_version[i] == SEPARATOR && !tempStr.empty()) { parts.push_back(tempStr); tempStr.clear(); } else { tempStr+= new_version[i]; } i++; } if (!tempStr.empty()) { parts.push_back(tempStr); } major = atoi(parts.at(0).c_str()); minor = atoi(parts.at(1).c_str()); step = atoi(parts.at(2).c_str()); }
int test_main( int argc, char* argv[] ) { #ifndef BOOST_NO_STDC_NAMESPACE using std::atoi; #endif int n = 100; if (argc > 1) n = atoi(argv[1]); test<int>(n); test<custom>(n); return 0; }
int main(int argc, char **argv) { int port= atoi(argv[1]); ServerSocket server(port); cout << "Listening on port: " << port << endl; while(true) { Socket client= server.accept(); cout << "Recieved connection from " << client.getAddress() << ":" << client.getPort() << endl; thread th(handler, &client); th.detach(); } return 0; }
Content& Content::updateDiff(const std::string &name, const std::string &length, int wins, int losses, int wave, Time time) { char *errMsg; stringstream select(stringstream::out), upsert(stringstream::out); int id= Utils::hashCode(name + "-" + length); auto diffTable= [&wins, &losses, &wave, &time](void *tableName, int argc, char **argv, char **colName) -> int { wins+= atoi(argv[3]); losses+= atoi(argv[4]); wave+= atoi(argv[5]); time.add(argv[6]); return 0; }; select << "select * from difficulties where id=" << id; sqlite3_exec(db, select.str().c_str(), diffTable, NULL, &errMsg); upsert << "replace into difficulties (id, name, length, wins, losses, wave, time) values (" << id << ", coalesce(( select name from difficulties where id=" << id << "),\'" << name << "\'), " << "coalesce(( select length from difficulties where id=" << id << "),\'" << length << "\'), " << wins << ", " << losses << ", " << wave << ", \'" << time.toString() << "\');"; sqlite3_exec(db, upsert.str().c_str(), NULL, NULL, &errMsg); return *this; }
VoxelBuffer * VoxelBuffer::factory(const string& filename) { ifstream fin(filename); string inputBuffer; VoxelBuffer * tempBuffer; fin >> inputBuffer; // "DELT" fin >> inputBuffer; // Delta value float delta = (float)atof(inputBuffer.c_str()); fin >> inputBuffer; // "XYZC" fin >> inputBuffer; ivec3 dimensions; dimensions.x = atoi(inputBuffer.c_str()); fin >> inputBuffer; dimensions.y = atoi(inputBuffer.c_str()); fin >> inputBuffer; dimensions.z = atoi(inputBuffer.c_str()); tempBuffer = new VoxelBuffer(delta, dimensions); float tempDensity/*, tempLight*/; // Omit reading in lights temporarily voxel tempVoxel; int voxelBufferSize = dimensions.x * dimensions.y * dimensions.z; tempBuffer->voxels = new voxel[voxelBufferSize]; int i = 0; // Read in voxel densities (and lights...later) while (!fin.eof()) { fin >> inputBuffer; tempDensity = (float)atof(inputBuffer.c_str()); tempVoxel.density = tempDensity; tempVoxel.light = -1.0; tempBuffer->voxels[i++] = tempVoxel; // Add voxel to the 1D array } return tempBuffer; }
int main (int argc, char *argv[]) { if(argc == 1) { print(); } else if(argc == 2) { print(argv[1]); } else if(argc == 3) { int times = atoi(argv[2]); if(times < 1) { printIllegalArg(); } else { print(argv[1], times); } } else { printTooManyArgs(); } }
int main(int argc, char* argv[]){ // First arg should be smallest power of 10 for h // Hardwired things: float x_f = sqrt(2); double x_d = sqrt(2); // doesn't look like sqrt works w/ long double string output = "/home/claire/phy480/PHY480/warmup/output.csv"; int h_size = atoi(argv[1]); double *h = new double[h_size]; for (int i=1; i<=h_size; i++){ h[i-1] = pow(10,-i); //cout << h[i] << endl; } /* sizeof float: 4 * sizeof double: 8 * sizeof long double: 16 */ write_to_file(output,"h",h,h_size); delete [] h; // single precision float *eq1_f = new float[h_size]; deriv_eq1(eq1_f,x_f,h,h_size); write_to_file(output,"eq1_f",eq1_f,h_size,true); delete [] eq1_f; float *eq2_f = new float[h_size]; deriv_eq2(eq2_f,x_f,h,h_size); write_to_file(output,"eq2_f",eq2_f,h_size,true); delete [] eq2_f; // double precision double *eq1_d = new double[h_size]; deriv_eq1(eq1_d,x_d,h,h_size); write_to_file(output,"eq1_d",eq1_d,h_size,true); delete [] eq1_d; double *eq2_d = new double[h_size]; deriv_eq2(eq2_d,x_d,h,h_size); write_to_file(output,"eq2_d",eq2_d,h_size,true); delete [] eq2_d; return 0; }
void CONFIGVARIABLE::Set(string newval) { newval = strTrim(newval); val_i = atoi(newval.c_str()); val_f = atof(newval.c_str()); val_s = newval; val_b = false; if (val_i == 0) val_b = false; if (val_i == 1) val_b = true; if (strLCase(newval) == "true") val_b = true; if (strLCase(newval) == "false") val_b = false; if (strLCase(newval) == "on") val_b = true; if (strLCase(newval) == "off") val_b = false; //now process as vector information int pos = 0; int arraypos = 0; string::size_type nextpos = newval.find(",", pos); string frag; while (nextpos < /*(int)*/ newval.length() && arraypos < 3) { frag = newval.substr(pos, nextpos - pos); val_v[arraypos] = atof(frag.c_str()); pos = nextpos+1; arraypos++; nextpos = newval.find(",", pos); } //don't forget the very last one if (arraypos < 3) { frag = newval.substr(pos, newval.length() - pos); val_v[arraypos] = atof(frag.c_str()); } }
Content& Content::updateDeaths(const std::string &name, int value) { char *errMsg; stringstream select(stringstream::out), upsert(stringstream::out); int id= Utils::hashCode(name); auto deathTable= [&value](void *tableName, int argc, char **argv, char **colName) -> int { value+= atoi(argv[2]); return 0; }; select << "select * from deaths where id=" << id; sqlite3_exec(db, select.str().c_str(), deathTable, NULL, &errMsg); upsert << "replace into deaths (id, name, count) values (" << id << ", coalesce(( select name from deaths where id=" << id << "),\'" << name << "\'), " << value << ");"; sqlite3_exec(db, upsert.str().c_str(), NULL, NULL, &errMsg); return *this; }
int main(int argc, char* argv[]) { int liczba{0}; if (argc == 2) { char* arg = argv[1]; liczba = atoi(arg); } else { cout << "Podaj liczbę: "; cin >> liczba; } cout << endl << "dzielniki: "; for (int dzielnik = 1; dzielnik <= liczba/2; dzielnik++) { if (liczba % dzielnik == 0) { cout << dzielnik << " "; } } cout << liczba << endl; }
int main(int argc, char* argv[]) { if( argc < 2 ){ printf("%s", usage); return 1; } int len = atoi(argv[1] ); if( len < 3 || len > 12 ){ printf("%s", usage); return 2; } int fact[16]; fact[0] = 1; for(int i = 1; i<len+1; ++i) fact[i] = fact[i-1]*i; unsigned n_cpu = thread::hardware_concurrency(); Fannkuchredux::R r= { 0, 0}; const unsigned max_cpu_limit = 4; Task parts[max_cpu_limit]; unsigned n = min(n_cpu, max_cpu_limit); thread_group tg; int index = 0; int index_max = fact[len]; int index_step = (index_max + n-1)/n; for(unsigned i = 0; i<n; ++i, index += index_step){ Task& p = parts[i]; p.init(fact, len, index, index + index_step); tg.create_thread(ref(p)); } tg.join_all(); for(unsigned i = 0; i<n; ++i){ Task const& p = parts[i]; r.maxflips = max( p.r.maxflips, r.maxflips ); r.checksum += p.r.checksum; } printf("%d\nPfannkuchen(%d) = %d\n", r.checksum, len, r.maxflips); return 0; }
void Cambiar(carta* deck, carta* mano, unsigned int size, unsigned int handS){ echo(); mvprintw(18,0,"Ingrese los numeros de las cartas que desea cambiar, separados por comas (',') Ejemplo: (1,3,5)\n"); char CurrChar; string input=""; while((CurrChar=getch())!=10){ if(CurrChar=='1'||CurrChar=='2'||CurrChar=='3'||CurrChar=='4'||CurrChar=='5'||CurrChar==','){ input.push_back(CurrChar); } } stringstream convert(input); vector<string> indices; while(convert.good()){ string sub; getline(convert,sub,','); indices.push_back(sub); } noecho(); int HandIndex[indices.size()]; int DeckIndex[indices.size()]; for(int i=0;i<indices.size();i++){ int temp=atoi(indices.at(i).c_str())-1; for(int j=0;j<size;j++){ if((mano[temp].getLetra()==deck[j].getLetra())&&(mano[temp].getSimbolo()==deck[j].getSimbolo())){ HandIndex[i]=temp; DeckIndex[i]=j; j=size; } } } vector<int> NIndex; Random2(deck,mano,NIndex,DeckIndex,indices.size()); for(int i=0;i<indices.size();i++){ mano[HandIndex[i]]=deck[NIndex.at(i)]; } ClearScreen(); PrintHand(mano,handS); }
int main(int argc, char* argv[]){ // Check that argc is at least 3 if( argc < 3 ){ cout << argv[0] << " requires at least 2 inputs: filename & n" << endl; exit(1); } // Read the output filename & number of integration points string output = argv[1]; int n = atoi(argv[2]); // If provided, read in the tridiagonal values. int a_val=-1, b_val=2, c_val=-1; // Defaults bool default_matrix; if (argc == 6){ a_val = atoi(argv[3]); b_val = atoi(argv[4]); c_val = atoi(argv[5]); default_matrix = false; } else{ default_matrix = true; } // Stepsize h double h = 1.0/(n+1.0); // Matrix equation is of the form Av=w, where: // w=h^2*f(x) // v is a vector of solutions // u is a vector of analytical solutions, using interpolation points x double *x = new double[n+2]; x[1]=0; x[n+1]=1; // x is over [0,1] double *u = new double[n+2]; u[0]=0; u[n+1]=0; double *v = new double[n+2]; v[0]=0; v[n+1]=0; double *w = new double[n+1]; // No need to include given endpoints // Setup for (int i=1; i<n+1; i++){ x[i] = i*h; w[i] = h*h * f(x[i]); u[i] = exact_soln(x[i]); } // Numerical solutions // NOTE: w is modified when solving // Generic case if (default_matrix == false) general_solver(w, v, n, a_val, b_val, c_val); // Specific case (default values) if (default_matrix == true) special_solver(w, v, n); // Write to file ofstream ofile; ofile.open(output); ofile << " x: u(x): v(x): " << endl; for (int i=0;i<n+2;i++) { ofile << setw(15) << setprecision(8) << x[i]; ofile << setw(15) << setprecision(8) << u[i]; ofile << setw(15) << setprecision(8) << v[i] << endl; } ofile.close(); delete [] x; delete [] w; delete [] v; delete [] u; return 0; }
void KeyBinder::ParseLine(char *line) { size_t i; SDL_keysym k; ActionType a; k.sym = SDLK_UNKNOWN; k.mod = KMOD_NONE; string s = line, u; string d, desc, keycode; bool show; skipspace(s); // comments and empty lines if (s.length() == 0 || s[0] == '#') return; u = s; u = to_uppercase(u); // get key while (s.length() && !isspace(s[0])) { // check modifiers if (u.substr(0,4) == "ALT-") { k.mod = (SDLMod)(k.mod | KMOD_ALT); s.erase(0,4); u.erase(0,4); } else if (u.substr(0,5) == "CTRL-") { k.mod = (SDLMod)(k.mod | KMOD_CTRL); s.erase(0,5); u.erase(0,5); } else if (u.substr(0,6) == "SHIFT-") { k.mod = (SDLMod)(k.mod | KMOD_SHIFT); s.erase(0,6); u.erase(0,6); } else { i=s.find_first_of(chardata.whitespace); keycode = s.substr(0, i); s.erase(0, i); string t = to_uppercase(keycode); if (t.length() == 0) { cerr << "Keybinder: parse error in line: " << s << endl; return; } else if (t.length() == 1) { // translate 1-letter keys straight to SDLKey char c = t[0]; if (c >= 33 && c <= 122 && c != 37) { if (c >= 'A' && c <= 'Z') c += 32; // need lowercase k.sym = static_cast<SDLKey>(c); } else { cerr << "Keybinder: unsupported key: " << keycode << endl; } } else { // lookup in table ParseKeyMap::iterator key_index; key_index = keys.find(t); if (key_index != keys.end()) { k.sym = (*key_index).second; } else { cerr << "Keybinder: unsupported key: " << keycode << endl; return; } } } } if (k.sym == SDLK_UNKNOWN) { cerr << "Keybinder: parse error in line: " << s << endl; return; } // get function skipspace(s); i=s.find_first_of(chardata.whitespace); string t = s.substr(0, i); s.erase(0, i); t = to_uppercase(t); ParseActionMap::iterator action_index; action_index = actions.find(t); if (action_index != actions.end()) { a.action = (*action_index).second; } else { cerr << "Keybinder: unsupported action: " << t << endl; return; } // get params skipspace(s); int np = 0; while (s.length() && s[0] != '#' && np < c_maxparams) { i=s.find_first_of(chardata.whitespace); string t = s.substr(0, i); s.erase(0, i); skipspace(s); int p = atoi(t.c_str()); a.params[np++] = p; } // read optional help comment if (s.length() >= 1 && s[0] == '#') { if (s.length() >= 2 && s[1] == '-') { show = false; } else { s.erase(0,1); skipspace(s); d = s; show = true; } } else { d = a.action->desc; show = a.action->key_type != Action::dont_show; } if (show) { desc = ""; if (k.mod & KMOD_CTRL) desc += "Ctrl-"; #if defined(MACOS) || defined(MACOSX) if (k.mod & KMOD_ALT) desc += "Cmd-"; #else if (k.mod & KMOD_ALT) desc += "Alt-"; #endif if (k.mod & KMOD_SHIFT) desc += "Shift-"; if(keycode == "`") desc += "grave"; else desc += keycode; desc += " - " + d; // add to help list if (a.action->key_type == Action::normal_keys) keyhelp.push_back(desc); else if (a.action->key_type == Action::cheat_keys) cheathelp.push_back(desc); } // bind key AddKeyBinding(k.sym, k.mod, a.action, np, a.params); }
KeyBinder::KeyBinder(Configuration *config) { FillParseMaps(); std::string keyfilename, dir; config->value("config/keys",keyfilename,"(default)"); bool key_file_exists = fileExists(keyfilename.c_str()); if(keyfilename != "(default)" && !key_file_exists) fprintf(stderr, "Couldn't find the default key setting at %s - trying defaultkeys.txt in the data directory\n", keyfilename.c_str()); if(keyfilename == "(default)" || !key_file_exists) { config->value("config/datadir", dir, "./data"); keyfilename = dir + "/defaultkeys.txt"; } LoadFromFile(keyfilename.c_str()); // will throw() if not found LoadGameSpecificKeys(); // won't load if file isn't found LoadFromPatch(); // won't load if file isn't found #ifdef HAVE_JOYSTICK_SUPPORT joystick = NULL; std::string enable_joystick_str; config->value("config/joystick/enable_joystick", enable_joystick_str, "no"); if(enable_joystick_str == "no") enable_joystick = -1; #if SDL_VERSION_ATLEAST(2,0,0) else if(enable_joystick_str == "auto") init_joystick(127); #endif else init_joystick(clamp(atoi(enable_joystick_str.c_str()), 0, 9)); int config_int; uint16 max_delay = 10000; // 10 seconds but means no repeat uint16 max_deadzone = 32766; // one less than highest possible config->value("config/joystick/repeat_hat", repeat_hat, false); config->value("config/joystick/repeat_delay", config_int, 50); joy_repeat_delay = config_int < max_delay ? config_int : max_delay; if(joy_repeat_delay == max_delay) joy_repeat_enabled = false; else joy_repeat_enabled = true; // AXES_PAIR1 config->value("config/joystick/axes_pair1/x_axis", config_int, 0); x_axis = config_int < 255 ? config_int : 255; config->value("config/joystick/axes_pair1/y_axis", config_int, 1); y_axis = config_int < 255 ? config_int : 255; config->value("config/joystick/axes_pair1/x_deadzone", config_int, 8000); x_axis_deadzone = config_int < max_deadzone ? config_int : max_deadzone; config->value("config/joystick/axes_pair1/y_deadzone", config_int, 8000); y_axis_deadzone = config_int < max_deadzone ? config_int : max_deadzone; config->value("config/joystick/axes_pair1/delay", config_int, 110); pair1_delay = config_int < max_delay ? config_int : max_delay; // AXES_PAIR2 config->value("config/joystick/axes_pair2/x_axis", config_int, 3); x_axis2 = config_int < 255 ? config_int : 255; config->value("config/joystick/axes_pair2/y_axis", config_int, 2); y_axis2 = config_int < 255 ? config_int : 255; config->value("config/joystick/axes_pair2/x_deadzone", config_int, 8000); x_axis2_deadzone = config_int < max_deadzone ? config_int : max_deadzone; config->value("config/joystick/axes_pair2/y_deadzone", config_int, 8000); y_axis2_deadzone = config_int < max_deadzone ? config_int : max_deadzone; config->value("config/joystick/axes_pair2/delay", config_int, 110); pair2_delay = config_int < max_delay ? config_int : max_delay; // AXES_PAIR3 config->value("config/joystick/axes_pair3/x_axis", config_int, 4); x_axis3 = config_int < 255 ? config_int : 255; config->value("config/joystick/axes_pair3/y_axis", config_int, 5); y_axis3 = config_int < 255 ? config_int : 255; config->value("config/joystick/axes_pair3/x_deadzone", config_int, 8000); x_axis3_deadzone = config_int < max_deadzone ? config_int : max_deadzone; config->value("config/joystick/axes_pair3/y_deadzone", config_int, 8000); y_axis3_deadzone = config_int < max_deadzone ? config_int : max_deadzone; config->value("config/joystick/axes_pair3/delay", config_int, 110); pair3_delay = config_int < max_delay ? config_int : max_delay; // AXES_PAIR4 config->value("config/joystick/axes_pair4/x_axis", config_int, 6); x_axis4 = config_int < 255 ? config_int : 255; config->value("config/joystick/axes_pair4/y_axis", config_int, 7); y_axis4 = config_int < 255 ? config_int : 255; config->value("config/joystick/axes_pair4/x_deadzone", config_int, 8000); x_axis4_deadzone = config_int < max_deadzone ? config_int : max_deadzone; config->value("config/joystick/axes_pair4/y_deadzone", config_int, 8000); y_axis4_deadzone = config_int < max_deadzone ? config_int : max_deadzone; config->value("config/joystick/axes_pair4/delay", config_int, 110); pair4_delay = config_int < max_delay ? config_int : max_delay; next_axes_pair_update = next_axes_pair2_update = next_axes_pair3_update = 0; next_axes_pair4_update = next_joy_repeat_time = 0; #endif }
// Handle preprocessor comamnds in the input void FileBuffer::handlePreproc(string fileDataLine) { /*Thanks to the preprocessor step, the location of text in the input file rarely matches that in the source file, but locations should refer to source. The preprocessor handles this by inserting source file locations into its output. These consist of a hash, a number, and the file name in quotes. Hunt for them here and update the source file location accordingly Anything else starting with a hash is an actual preprocessor command. The source code should be run through the preprocessor before calling this routine, so finding one is an error. Issue a warning and ignore it */ // Search for the location by trying to extract it. bool haveLocation = false; unsigned int lineNo = 0; string fileName; bool wasWrapped = _haveWrap; // Wrapped from previous line _haveWrap = hasEscNewline(fileDataLine, false); // Wraps to next line // Locations never wrap if ((!wasWrapped) && (!_haveWrap)) { // Find the line number unsigned short start = 0; unsigned short end = 0; start = fileDataLine.find_first_of('#'); start = burnSpaces(fileDataLine, start + 1); // Actual text of command if (start != string::npos) { // Something on line other than hash if (isdigit(fileDataLine[start])) { // Find first non digit and extract line number end = fileDataLine.find_first_not_of("0123456789", start); if (end != string::npos) { // Something after the digits /* NOTE: This is not the "official" way of extracting an integer from a string, but it is the fastest */ lineNo = atoi(fileDataLine.substr(start, end-start).c_str()); /* The line gives the location of the next source line. Since reading that line will increment the line counter, need to decrement it here to compensate */ lineNo--; // Find the first non-space after the digits. Must be a quote start = burnSpaces(fileDataLine, end); if (start != string::npos) { // Found more data if (fileDataLine[start] == '"') { start++; // Find next quote and extract file name end = fileDataLine.find_first_of('"', start); if (end != string::npos) { // Filename with no chars is illegal if (end > start) { fileName = fileDataLine.substr(start, end - start); /* Find the first non-space after the just extracted file name. If any exist, it's not a location */ end++; if (end != fileDataLine.length()) { end = burnSpaces(fileDataLine, end); haveLocation = (end == string::npos); } // Quote not last char on the line else haveLocation = true; if (haveLocation) _bufferPosition = FilePosition(fileName, lineNo); } // Have at least one char between quotes } // Quote at end of filename exists } // Quote at start of filename exists } // Have non-space after the line number } // More chars exist after the line number } // First thing after hash is a digit } // Have something after the hash } // Preprocessor command did not wrap /* If a file location was no found, this is an actual preprocessor command which indicates a processing error */ if ((!haveLocation) && (!wasWrapped)) cout << "WARNING: Preprocessor directive " << fileDataLine << " ignored on " << _inputPosition << ". Must g++ -E source files before calling" << endl; }
int main(int argc, char *argv[]) { int test = argc > 1 ? atoi(argv[1]) : 0; int verbose = argc > 2; int veryVerbose = argc > 3; printf("TEST " __FILE__ " CASE %d\n", test); switch (test) { case 0: case 2: { // -------------------------------------------------------------------- // USAGE EXAMPLE // // Concerns: //: 1 The usage example provided in the component header file compiles, //: links, and runs as shown. // // Plan: //: 1 Incorporate usage example from header into test driver, remove //: leading comment characters, and replace 'assert' with 'ASSERT'. //: (C-1) // // Testing: // USAGE EXAMPLE // -------------------------------------------------------------------- if (verbose) printf("\nUSAGE EXAMPLE\n" "\n=============\n"); ///Usage ///----- // In this section we show intended use of this component. // ///Example 1: Removing The 'const'-qualifier of A Type ///- - - - - - - - - - - - - - - - - - - - - - - - - - // Suppose that we want to remove any top-level 'const'-qualifier from a // particular type. // // First, we create two 'typedef's -- a 'const'-qualified type ('MyConstType') // and the same type without the 'const'-qualifier ('MyType'): //.. typedef int MyType; typedef const int MyConstType; //.. // Now, we remove the 'const'-qualifier from 'MyConstType' using // 'bsl::remove_const' and verify that the resulting type is the same as // 'MyType': //.. ASSERT(true == (bsl::is_same<bsl::remove_const<MyConstType>::type, MyType>::value)); //.. } break; case 1: { // -------------------------------------------------------------------- // 'bsl::remove_const::type' // Ensure that the 'typedef' 'type' of 'bsl::remove_const' has the // correct type for a variety of template parameter types. // // Concerns: //: 1 'bsl::remove_const' leaves types that are not 'const'-qualified //: at the top-level as-is. //: //: 2 'bsl::remove_const' remove any top-level 'const'-qualifier. // // Plan: // Verify that 'bsl::remove_const::type' has the correct type for // each concern. // // Testing: // bsl::remove_const::type // -------------------------------------------------------------------- if (verbose) printf("\n'bsl::remove_const::type'\n" "\n=========================\n"); // C-1 ASSERT((is_same<remove_const<int>::type, int>::value)); ASSERT((is_same<remove_const<int *>::type, int *>::value)); ASSERT((is_same<remove_const<TestType>::type, TestType>::value)); ASSERT((is_same<remove_const<int const *>::type, int const *>::value)); // C-2 ASSERT((is_same<remove_const<int const>::type, int>::value)); ASSERT((is_same<remove_const<int * const>::type, int *>::value)); ASSERT((is_same<remove_const<TestType const>::type, TestType>::value)); ASSERT((is_same<remove_const<int const volatile>::type, int volatile>::value)); ASSERT((is_same<remove_const<int * const volatile>::type, int * volatile>::value)); ASSERT((is_same<remove_const<TestType const volatile>::type, TestType volatile>::value)); } break; default: { fprintf(stderr, "WARNING: CASE `%d' NOT FOUND.\n", test); testStatus = -1; } } if (testStatus > 0) { fprintf(stderr, "Error, non-zero test status = %d.\n", testStatus); } return testStatus; }
int main(int argc, char *argv[]) { int test = argc > 1 ? atoi(argv[1]) : 0; int verbose = argc > 2; int veryVerbose = argc > 3; printf("TEST " __FILE__ " CASE %d\n", test); switch (test) { case 0: case 2: { // -------------------------------------------------------------------- // USAGE EXAMPLE // // Concerns: //: 1 The usage example provided in the component header file compiles, //: links, and runs as shown. // // Plan: //: 1 Incorporate usage example from header into test driver, remove //: leading comment characters, and replace 'assert' with 'ASSERT'. //: (C-1) // // Testing: // USAGE EXAMPLE // -------------------------------------------------------------------- if (verbose) printf("USAGE EXAMPLE\n" "=============\n"); // Now, we create two 'typedef's -- a function pointer type and a member // function pointer type: //.. typedef int (MyStruct::*MyStructMethodPtr) (); typedef int (*MyFunctionPtr) (); //.. // Finally, we instantiate the 'bsl::is_member_function_pointer' template for // each of the 'typedef's and assert the 'value' static data member of each // instantiation: //.. ASSERT(false == bsl::is_member_function_pointer<MyFunctionPtr >::value); ASSERT(true == bsl::is_member_function_pointer<MyStructMethodPtr>::value); //.. } break; case 1: { // -------------------------------------------------------------------- // 'bsl::is_member_function_pointer::value' // Ensure that the static data member 'value' of // 'bsl::is_member_function_pointer' instantiations having various // (template parameter) 'TYPES' has the correct value. // // Concerns: //: 1 'is_member_function_pointer::value' is 'false' when 'TYPE' is a //: (possibly cv-qualified) primitive type. //: //: 2 'is_member_function_pointer::value' is 'false' when 'TYPE' is a //: (possibly cv-qualified) user-defined type. //: //: 3 'is_member_function_pointer::value' is 'false' when 'TYPE' is a //: (possibly cv-qualified) pointer type other than a non-static //: member function pointer. //: //: 4 'is_member_function_pointer::value' is 'true' when 'TYPE' is a //: (possibly cv-qualified) non-static member function pointer type. //: //: 5 'is_member_function_pointer::value' is 'false' when 'TYPE' is a //: (possibly cv-qualified) function type. // // Plan: // Verify that 'bsl::is_member_function_pointer::value' has the // correct value for each (template parameter) 'TYPE' in the // concerns. // // Testing: // bsl::is_member_function_pointer::value // -------------------------------------------------------------------- if (verbose) printf("bsl::is_member_function_pointer\n" "===============================\n"); // C-1 TYPE_ASSERT_CVQ_SUFFIX(bsl::is_member_function_pointer, void, false); TYPE_ASSERT_CVQ_SUFFIX(bsl::is_member_function_pointer, int, false); TYPE_ASSERT_CVQ_REF (bsl::is_member_function_pointer, int, false); // C-2 TYPE_ASSERT_CVQ_SUFFIX( bsl::is_member_function_pointer, EnumTestType, false); TYPE_ASSERT_CVQ_SUFFIX( bsl::is_member_function_pointer, StructTestType, false); TYPE_ASSERT_CVQ_REF ( bsl::is_member_function_pointer, StructTestType, false); TYPE_ASSERT_CVQ_SUFFIX( bsl::is_member_function_pointer, UnionTestType, false); TYPE_ASSERT_CVQ_REF ( bsl::is_member_function_pointer, UnionTestType, false); TYPE_ASSERT_CVQ_SUFFIX( bsl::is_member_function_pointer, Incomplete, false); TYPE_ASSERT_CVQ_REF ( bsl::is_member_function_pointer, Incomplete, false); TYPE_ASSERT_CVQ_SUFFIX( bsl::is_member_function_pointer, BaseClassTestType, false); TYPE_ASSERT_CVQ_REF ( bsl::is_member_function_pointer, BaseClassTestType, false); TYPE_ASSERT_CVQ_SUFFIX( bsl::is_member_function_pointer, DerivedClassTestType, false); TYPE_ASSERT_CVQ_REF ( bsl::is_member_function_pointer, DerivedClassTestType, false); // C-3 TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, int*, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, StructTestType*, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, int StructTestType::*, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, int StructTestType::* *, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, UnionTestType*, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, PMD BaseClassTestType::*, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, PMD BaseClassTestType::* *, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, BaseClassTestType*, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, DerivedClassTestType*, false); TYPE_ASSERT_CVQ( bsl::is_member_function_pointer, Incomplete*, false); TYPE_ASSERT_CVQ_SUFFIX( bsl::is_member_function_pointer, FunctionPtrTestType, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, int*, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, StructTestType*, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, int StructTestType::*, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, int StructTestType::* *, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, UnionTestType*, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, PMD BaseClassTestType::*, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, PMD BaseClassTestType::* *, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, BaseClassTestType*, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, DerivedClassTestType*, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, Incomplete*, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, FunctionPtrTestType, false); TYPE_ASSERT_CVQ_REF( bsl::is_member_function_pointer, MethodPtrTestType, false); // C-4 TYPE_ASSERT_CVQ_SUFFIX( bsl::is_member_function_pointer, MethodPtrTestType, true); // C-5 TYPE_ASSERT_CVQ_PREFIX( bsl::is_member_function_pointer, int (int), false); TYPE_ASSERT_CVQ_PREFIX( bsl::is_member_function_pointer, void (void), false); TYPE_ASSERT_CVQ_PREFIX( bsl::is_member_function_pointer, int (void), false); TYPE_ASSERT_CVQ_PREFIX( bsl::is_member_function_pointer, void (int), false); } break; default: { cerr << "WARNING: CASE `" << test << "' NOT FOUND." << endl; testStatus = -1; } } if (testStatus > 0) { cerr << "Error, non-zero test status = " << testStatus << "." << endl; } return testStatus; }
int main( int argc, char* argv[]) { // seed for random number generator: int random_seed; // number of matrices: int num; // dimension of matrices to generate: int dim; // bound for matrix entries: int upper_entry_bound; // set of matrices to search: Matrix_cont matrices; // set of vectors the matrices are build from: Vector_cont vectors; // handle command line arguments: if ( argc < 4 || (num = atoi(argv[1])) <= 0 || (dim = atoi(argv[2])) <= 0 || (upper_entry_bound = atoi(argv[3])) <= 0) { cerr << "usage: " << argv[0] << " num dim upper_entry_bound [random_seed]" << endl; exit(1); } if ( argc < 5 || (random_seed = atoi(argv[4])) <= 0) { #ifdef OUTPUT cerr << "No random seed specified - generating it" << endl; #endif // generate random seed random_seed = default_random.get_int( 0, (1 << 30)); } else random_seed = atoi(argv[4]); // define random source: Random r( random_seed); #ifdef OUTPUT cout << "random seed is " << random_seed << endl; #endif // maximum entry of all matrices: Value max_entry( -1); for ( int k = 0; k < num; ++k) { // generate two vectors a and b to build the cartesian // matrix from Vector a, b; assert( a.size() == 0 && b.size() == 0); // fill a and b with random values and sort them: for ( int i = 0; i < dim; ++i) { a.push_back( r( upper_entry_bound)); b.push_back( r( upper_entry_bound)); } // to test some non-quadratic matrices: // for ( i = 0; i < dim / 5; ++i) { // b.push_back( r()); // } sort( a.begin(), a.end(), less< Value >()); sort( b.begin(), b.end(), less< Value >()); /* cout << "a = ("; for ( Vector_iterator pp( a.begin()); pp != a.end(); ++pp) cout << (*pp) << ", "; cout << ")\nb = ("; for ( Vector_iterator pq( a.begin()); pq != a.end(); ++pq) cout << (*pq) << ", "; cout << ")" << endl; */ // evt. update max_entry: max_entry = max( a[dim - 1] + b[dim - 1], max_entry); // keep both vectors: vectors.push_back( a); vectors.push_back( b); } // for ( int k = 0; k < num; ++k) // construct matrices: for ( Vector_iterator i( vectors.begin()); i != vectors.end(); i += 2) { Vector_iterator j = i + 1; matrices.push_back( Matrix( (*i).begin(), (*i).end(), (*j).begin(), (*j).end())); } // search lower bound for a random value v in matrices Value bound; // assure there is any feasible value in m: do bound = r.get_int( 0, 2 * upper_entry_bound); while ( bound > max_entry); #ifdef OUTPUT cout << "searching upper bound for " << bound << endl; #endif Value u( sorted_matrix_search( matrices.begin(), matrices.end(), sorted_matrix_search_traits_adaptor( boost::bind( greater_equal< Value >(), _1, bound), *(matrices.begin())))); #ifdef OUTPUT cout << "************* DONE *************\nresult: " << u << "\n********************************" << endl; CGAL_optimisation_assertion( u == compute_upper_bound( matrices.begin(), matrices.end(), bound, max_entry)); #else Value brute_force( compute_upper_bound( matrices.begin(), matrices.end(), bound, max_entry)); if ( u != brute_force) cerr << "\nerror: num( " << num << "), dim ( " << dim << "), upper_entry_bound( " << upper_entry_bound << ")\nrandom_seed( " << random_seed << ")" << "\nresult was " << u << "\ntrivial algorithm gives " << brute_force << endl; #endif return 0; }
// parse command line options void parsecmdoptions(int argc, char *argv[], Cmdopt* cmdopt) { if (argc < 7) { // no enough arguments buildcontighelp(); exit(1); } bool tag = false; for (int i = 1; i < argc; i += 2) { // read each option if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--mapfile") == 0) { // read mapping file cmdopt->mapfile = argv[i+1]; cmdopt->filetype = "map"; } else if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--samfile") == 0) { // read mapping file cmdopt->mapfile = argv[i+1]; cmdopt->filetype = "sam"; } else if (strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--refseq") == 0) // ref seq file cmdopt->reffile = argv[i+1]; else if (strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--prefix") == 0) // output prefix cmdopt->outprefix = argv[i+1]; else if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--mincov") == 0) { // min depcov for outputing contigs if (atoi(argv[i+1]) < 1) tag = true; cmdopt->mindepcov = atoi(argv[i+1]); } else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--minlen") == 0) { // min length for outputing contigs if (atoi(argv[i+1]) < 1) tag = true; cmdopt->minlen = atoi(argv[i+1]); } else if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--thread") == 0) { // min length for outputing contigs if (atoi(argv[i+1]) < 1) tag = true; cmdopt->nump = atoi(argv[i+1]); } else if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--prof") == 0) { // print .baseprof file or not if (argv[i+1][0] == 'T') cmdopt->printbaseprof = true; else if (argv[i+1][0] == 'F') cmdopt->printbaseprof = false; else tag = true; } else if (strcmp(argv[i], "-n") == 0 || strcmp(argv[i], "--newref") == 0) { // print .newref file or not if (argv[i+1][0] == 'T') cmdopt->printnewref = true; else if (argv[i+1][0] == 'F') cmdopt->printnewref = false; else tag = true; } else if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--usedmap") == 0) { // print .usedmap file or not if (argv[i+1][0] == 'T') cmdopt->printusedmap = true; else if (argv[i+1][0] == 'F') cmdopt->printusedmap = false; else tag = true; } else if (strcmp(argv[i], "-k") == 0 || strcmp(argv[i], "--pickref") == 0) { // how to pick ref seq if (strcmp(argv[i+1], "all") == 0) cmdopt->pickref = "all"; else if (strcmp(argv[i+1], "breadth") == 0) cmdopt->pickref = "breadth"; else if (strcmp(argv[i+1], "random") == 0) cmdopt->pickref = "random"; else if (strcmp(argv[i+1], "depth") == 0) cmdopt->pickref = "depth"; else tag = true; } else // does not match, then something goes wrong tag = true; } // these parameters must be specified if (cmdopt->mapfile == "" || cmdopt->reffile == "" || cmdopt->outprefix == "") tag = true; if (tag) { buildcontighelp(); exit(1); } }
int main(int argc, char *argv[]) { int test = argc > 1 ? atoi(argv[1]) : 0; int verbose = argc > 2; int veryVerbose = argc > 3; printf("TEST " __FILE__ " CASE %d\n", test); switch (test) { case 0: case 2: { // -------------------------------------------------------------------- // USAGE EXAMPLE // // Concerns: //: 1 The usage example provided in the component header file compiles, //: links, and runs as shown. // // Plan: //: 1 Incorporate usage example from header into test driver, remove //: leading comment characters, and replace 'assert' with 'ASSERT'. //: (C-1) // // Testing: // USAGE EXAMPLE // -------------------------------------------------------------------- if (verbose) printf("\nUSAGE EXAMPLE\n" "\n=============\n"); ///Usage ///----- // In this section we show intended use of this component. // ///Example 1: Verify 'Const' Types ///- - - - - - - - - - - - - - - - // Suppose that we want to assert whether a particular type is a // 'const'-qualified. // // First, we create two 'typedef's -- a 'const'-qualified type and a // unqualified type: //.. typedef int MyType; typedef const int MyConstType; //.. // Now, we instantiate the 'bsl::is_const' template for each of the // 'typedef's and assert the 'value' static data member of each instantiation: //.. ASSERT(false == bsl::is_const<MyType>::value); ASSERT(true == bsl::is_const<MyConstType>::value); //.. } break; case 1: { // -------------------------------------------------------------------- // 'bsl::is_const::value' // Ensure that the static data member 'value' of 'bsl::is_const' // instantiations having various (template parameter) 'TYPES' has the // correct value. // // Concerns: //: 1 'is_const::value' is 'false' when 'TYPE' is a (possibly //: 'volatile'-qualified) type. //: //: 2 'is_const::value' is 'true' when 'TYPE' is a 'const'-qualified or //: cv-qualified type. // // Plan: // Verify that 'bsl::is_const::value' has the correct value for // each (template parameter) 'TYPE' in the concerns. // // Testing: // bsl::is_const::value // -------------------------------------------------------------------- if (verbose) printf("\nbsl::is_const::value\n" "\n====================\n"); // C-1 ASSERT(false == is_const<int>::value); ASSERT(false == is_const<int volatile>::value); ASSERT(false == is_const<TestType>::value); ASSERT(false == is_const<TestType volatile>::value); // C-2 ASSERT(true == is_const<int const>::value); ASSERT(true == is_const<int const volatile>::value); ASSERT(true == is_const<TestType const>::value); ASSERT(true == is_const<TestType const volatile>::value); } break; default: { fprintf(stderr, "WARNING: CASE `%d' NOT FOUND.\n", test); testStatus = -1; } } if (testStatus > 0) { fprintf(stderr, "Error, non-zero test status = %d.\n", testStatus); } return testStatus; }