bool ConfigManager::load() { clear(); // Check that the config file actually exists. UString file = getConfigFile(); if (!FilePath::isRegularFile(file)) return false; try { // Open and load the config ReadFile config; if (!config.open(file)) throw Exception(kOpenError); _config = new ConfigFile; _config->load(config); // Get the application domain _domainApp = _config->addDomain(kDomainApp); } catch (...) { exceptionDispatcherWarning("Failed loading config file \"%s\"", file.c_str()); return false; } return true; }
int main() { String* str = new String("Insomnium"); str->displayString(); std::cout << std::endl; Tokens* tokens = new Tokens(str, 'n'); tokens->displayTokens(); int num_tokens = tokens->getNumTokens(); for (int i = 0; i < num_tokens; i++) { String* token = tokens->getToken(i); delete token; } delete tokens; //does not delete the individual tokens delete str; ReadFile* rf = new ReadFile("cds.txt"); WriteFile* wf = new WriteFile("out.txt"); while(!rf->eof()) { String* line = rf->readLine(); wf->writeLine(line); delete line; } rf->close(); wf->close(); delete rf; delete wf; return 0; }
/** * Load all *.wav from directory. * @param directory path to the directory */ void SDLSound::loadSound(const char* directory) { char **list = FileSystem::enumerateFiles(directory); for (char **i = list; *i != NULL; i++) { std::string filename = directory; filename.append(*i); if (!FileSystem::isDirectory(filename.c_str())) { try { ReadFile *file = FileSystem::openRead(filename.c_str()); Mix_Chunk *chunk = Mix_LoadWAV_RW(file->getSDLRWOps(), 1); if (chunk) { std::string idName = getIdName(*i); m_chunks.insert( std::pair<std::string,Mix_Chunk*>(idName, chunk)); } else { LOG (("Couldn't load wav_rw '%s': %s", filename.c_str(), Mix_GetError())); } } catch (Exception &e) { LOG (("Couldn't load wav '%s': %s", filename.c_str(), e.getMessage())); } } } FileSystem::freeList(list); }
void LineNum(ReadFile& f) { //f.read(); int i=1; while(f.read()) { std::cout.setf(std::ios::right); std::cout.width(3); std::cout<<i++<<" "; f.Printbuffer(); } }
int ReadFile::RWOps_Read(SDL_RWops* context, void* ptr, int size, int maxnum) { ReadFile* file = (ReadFile*) context->hidden.unknown.data1; try { file->read(ptr, size, maxnum); } catch(FileReadException& e) { return e.getReadCount(); } catch(...) { return 0; } return maxnum; }
int main () { ReadFile crossword; crossword.MapFile(); //long size = crossword.getFileSize(); //qsort (letters, linesOfFile, sizeof(unsigned long long int), compare); for(int i=0;i<linesOfFile; i++) { cout << letters[i].word <<"\t" << letters[i].value <<endl; } }
int main() { ReadFile* rf = new ReadFile("cds.txt"); WriteFile* wf = new WriteFile("out.txt"); while(!rf->eof()) { String* line = rf->readLine(); wf->writeLine(line); delete line; } rf->close(); wf->close(); delete rf; delete wf; return 0; }
void addWords(Password* fh) { Keyboard* kb = Keyboard::getKeyboard(); String* file_str = kb->readString("Enter the file name containing the possible passwords: "); ReadFile* rf = new ReadFile(file_str->getText()); delete file_str; String* num_words_str = rf->readLine(); int num_words = num_words_str->a_to_i(); delete num_words_str; for (int i = 0; i < num_words; i++) { String* word = rf->readLine(); fh->addWord(word); } delete rf; fh->displayViableWords(); }
//assumes a specific format for the file //why is this method static in the header file? Poly* Poly::readPoly(const char* file_name) { ReadFile* rf = new ReadFile(file_name); //for reading String* degree_str = rf->readLine(); int degree = degree_str->a_to_i(); delete degree_str; Poly* poly = new Poly(degree); for (int i = 0; i <= degree; i++) { String* coeff_str = rf->readLine(); float coeff = coeff_str->a_to_f(); delete coeff_str; poly->setCoeff(i, (double) coeff); } delete rf; return poly; }
// loadTable //--------------------------------------------------------------------------- void ColorTable::loadTable(const char *filename) { ReadFile *file = FileSystem::openRead(filename); // make sure palette in file is the same as current one for(size_t i=0; i<PALETTE_LENGTH; i++) { RGBColor checkcolor; if(file->read(&checkcolor, sizeof(uint8_t), 3) != 3) throw Exception("couldn't load colortable '%s': " "file corrupted(too short)", filename); if(Palette::originalColor[i] != checkcolor) throw Exception("couldn't load colortable '%s': " "palettes don't match", filename); } // put the color table data into the colorArray if(file->read(colorArray, colorCount, 1) != 1) throw Exception("couldn't load colortable '%s': " "file corrupted(too short)", filename); delete file; } // end ColorTable::loadTable
int ReadFile::RWOps_Seek(SDL_RWops* context, int offset, int whence) { ReadFile* file = (ReadFile*) context->hidden.unknown.data1; try { // catch exceptions switch(whence) { case SEEK_SET: file->seek(offset); break; case SEEK_CUR: file->seek(file->tell() + offset); break; case SEEK_END: file->seek(file->fileLength() + offset); break; } } catch(...) { LOG(("Unexpected exception while seeking in file.")); return -1; } return file->tell(); }
int main(int argc, const char * argv[]) { //// test data/////////////////////////////////////////// // int d[10]; // for (int i= 1; i <=9 ; ++i) { // d[i] = i; // } vector<BumpNode*>previousSeq, currentSeq; // BumpNode *node1 = new BumpNode(1, &d[1], DirectRoute, false); // previousSeq.push_back(node1); // BumpNode *node2 = new BumpNode(2, &d[4], DirectRoute, false); // previousSeq.push_back(node2); // BumpNode *node3 = new BumpNode(3, &d[5], DirectRoute, false); // previousSeq.push_back(node3); // BumpNode *node7 = new BumpNode(7, &d[7], DirectRoute, false); // previousSeq.push_back(node7); // // // // // BumpNode *node8 = new BumpNode(8, nullptr, DirectRoute, false); // currentSeq.push_back(node8); // // // BumpNode *node4 = new BumpNode(4, &d[3], UnDirectRoute, false); // currentSeq.push_back(node4); // BumpNode* node5 = new BumpNode(5, &d[2], DirectRoute, false); // currentSeq.push_back(node5); // // BumpNode *node12 = new BumpNode(12, nullptr, DirectRoute, false); // currentSeq.push_back(node12); // BumpNode *node13 = new BumpNode(13, nullptr, DirectRoute, false); // currentSeq.push_back(node13); // BumpNode *node14 = new BumpNode(14, nullptr, DirectRoute, false); // currentSeq.push_back(node14); // BumpNode *node15 = new BumpNode(15, nullptr, DirectRoute, false); // currentSeq.push_back(node15); // BumpNode *node16 = new BumpNode(16, nullptr, DirectRoute, false); // currentSeq.push_back(node16); // // BumpNode* node6 = new BumpNode(6, &d[9], DirectRoute, false); // currentSeq.push_back(node6); // BumpNode *node11 = new BumpNode(11, nullptr, DirectRoute, false); // currentSeq.push_back(node11); // BumpNode *node10 = new BumpNode(10, nullptr, DirectRoute, false); // currentSeq.push_back(node10); // // // BumpNode *node9 = new BumpNode(9, nullptr, DirectRoute, false); // currentSeq.push_back(node9); // // // // node4->relativeX = 1; // node4->relativeY = 0; // node5->relativeX = 2; // node5->relativeY = 0; // node6->relativeX = 1; // node6->relativeY = 3; // node1->relativeX = 1; // node1->relativeY = 1; // node2->relativeX = 2; // node2->relativeY = 1; // node3->relativeX = 2; // node3->relativeY = 2; // RoutingMap *routingMap = new RoutingMap(4,4); // // routingMap->nodeInserttoMap(1, 1, node8); // routingMap->nodeInserttoMap(1, 2, node4); // routingMap->nodeInserttoMap(1, 3, node5); // routingMap->nodeInserttoMap(1, 4, node12); // routingMap->nodeInserttoMap(2, 1, node9); // routingMap->nodeInserttoMap(2, 2, node1); // routingMap->nodeInserttoMap(2, 3, node2); // routingMap->nodeInserttoMap(2, 4, node13); // routingMap->nodeInserttoMap(3, 1, node10); // routingMap->nodeInserttoMap(3, 2, node7); // routingMap->nodeInserttoMap(3, 3, node3); // routingMap->nodeInserttoMap(3, 4, node14); // routingMap->nodeInserttoMap(4, 1, node11); // routingMap->nodeInserttoMap(4, 2, node6); // routingMap->nodeInserttoMap(4, 3, node16); // routingMap->nodeInserttoMap(4, 4, node15); //read file ReadFile *readFile = new ReadFile(); int k = readFile->numBvec - 1; while (k >= 0) { readFile->LCS(readFile->driver, &readFile->bvec[0], readFile->driver.size(), readFile->bvec[k].size()); for (int i = 0; i < readFile->bvec[k].size(); ++i) { currentSeq.push_back(&readFile->bvec[k][i]); } printf("LCS Sequence result : "); for (int i = 0; i < currentSeq.size(); ++i) { if (currentSeq[i]->wireId) { if (currentSeq[i]->isVirtual) { printf("%d' ", *currentSeq[i]->wireId); } else { printf("%d ", *currentSeq[i]->wireId); } } else { printf("x "); } } printf("\n"); MPSC *mpsc = new MPSC(&previousSeq, ¤tSeq); mpsc->compute(); delete mpsc; routingMap->initMapinLayer(readFile->numBvec - k - 1, readFile->numBvec - k - 1, readFile->numBvec - k - 1, currentSeq); mapping *maping = new mapping(routingMap->mapRowNum, routingMap->mapColNum, readFile->w, readFile->s); maping->mapping_incircle(routingMap->map); // maping->mapping_outcircle(routingMap->map); maping->route_output(routingMap->map); k--; } //// algorithm ///////////////////////////////////////// // MPSC *mpsc = new MPSC(&previousSeq, ¤tSeq); // mpsc->compute(); // delete mpsc; // routingMap->initMapinLayer(0, 2, 2, previousSeq); // routingMap->initMapinLayer(1, 1, 1, currentSeq); //// print the result////////////////////////////////// printf("current Sequence : "); for (int i = 0; i < currentSeq.size(); ++i) { if (currentSeq[i]->wireId) { if (currentSeq[i]->isVirtual) { printf("%d' ", *currentSeq[i]->wireId); } else { printf("%d ", *currentSeq[i]->wireId); } } else { printf("x "); } } printf("\n"); printf("previous Sequence : "); for (int i = 0; i < previousSeq.size(); ++i) { if (previousSeq[i]->wireId) { if (previousSeq[i]->isVirtual) { printf("%d' ", *previousSeq[i]->wireId); } else { printf("%d ", *previousSeq[i]->wireId); } } else { printf("x "); } } printf("\n"); routingMap->ringMaping(1, 1, 1); routingMap->printBox(1, 1); routingMap->printBox(1, 2); routingMap->printBox(1, 3); // routingMap->printBox(0, 3); routingMap->printBox(2, 1); routingMap->printBox(2, 2); routingMap->printBox(2, 3); // routingMap->printBox(1, 3); routingMap->printBox(3, 1); routingMap->printBox(3, 2); routingMap->printBox(3, 3); //////////////////////////////////////////////////////// delete routingMap; return 0; }
void GameConfig::loadConfig() { ReadFile* file = FileSystem::openRead(configfile.c_str()); // XXX loadin/saving would be nicer in human readable form (XML?) int configversion = file->readSLE16(); if(configversion != CONFIG_VERSION) throw Exception("wrong config file version"); UnitColor = file->read8(); GameMode = file->read8(); GameType = file->read8(); NumberPlayers = file->readSLE16(); NumberUnits = file->readSLE16(); NumberInitialUnits = file->readSLE16(); // TODO lots of other stuff :) screen_resolution = file->readSLE32(); screen_fullscreen = file->read8(); display_shadows_flag = file->read8(); display_unit_flags = file->read8(); // TODO lots of other stuff :) delete file; }
void SDLSound::nextSong() { static Mix_Music *music = 0; if (music != 0) { Mix_HaltMusic(); Mix_FreeMusic(music); music = 0; } if(currentsong == musicfiles.end()) { // create a new random playlist std::random_shuffle(musicfiles.begin(), musicfiles.end()); currentsong = musicfiles.begin(); } musics_t::iterator lastsong = currentsong; do { const char* toplay = currentsong->c_str(); currentsong++; #if 0 /* * SDL_Mixer has not Mix_LoadMUS_RW */ try { ReadFile *file = FileSystem::openRead(toplay); music = Mix_LoadMUS_RW(file->getSDLRWOps(), 1); if (music) { if (Mix_PlayMusic(music, 1) == 0) { LOG (("Start playing song '%s'", toplay)); break; // break while cycle } else { LOG (("Failed to play song '%s': %s", toplay, Mix_GetError())); } } else { LOG (("Failed to load mus_rw '%s': %s", toplay, Mix_GetError())); } } catch (Exception &e) { LOG (("Failed to load song '%s': %s", toplay, e.getMessage())); } #else music = Mix_LoadMUS(toplay); if (music) { if (Mix_PlayMusic(music, 1) == 0) { LOG (("Start playing song '%s'", toplay)); break; // break while cycle } else { LOG (("Failed to play song '%s': %s", toplay, Mix_GetError())); } } else { LOG (("Failed to load song '%s': %s", toplay, Mix_GetError())); } #endif if(currentsong == musicfiles.end()) { currentsong = musicfiles.begin(); } } while(currentsong != lastsong); }