int main() { AddStreamRetain as(std::cerr); // *** LOG("start"); std::string logFileName="tmp/messages.log"; std::ofstream logFile(logFileName.c_str()); bool logFileOk = !!logFile; { AddStreamRetain as_if(logFile,logFileOk); // *** LOG("open log file '" << logFileName << "': " << (logFileOk ? "ok" : "failed")); std::string songFileName="tmp/song.out"; std::ofstream songFile(songFileName.c_str()); bool songFileOk = !!songFile; LOG("open song file '" << songFileName << "': " << (songFileOk ? "ok" : "failed")); std::stringstream sout; { NullStreamRetain as; // stop precursion to ancestor retains { AddStreamRetain as_if(songFile,songFileOk); // *** { AddStreamRetain as(sout); // *** sing(); } } } LOG("sung: " << sout.str()); } LOG("finish"); return 0; }
bool LevelWorkerMusic::Load(File* pf) { int numSongs = 0; if (!pf->GetInteger(&numSongs)) { pf->ReportError("Expected number of songs."); return false; } // Get each song file name. Open each file to mark it as used. for (int i = 0; i < numSongs; i++) { std::string songName; if (!pf->GetDataLine(&songName)) { pf->ReportError("Expected song name."); return false; } File songFile(false); // => no version info if (!songFile.OpenRead(songName, File::BINARY)) { std::string err = "Failed to open song file "; err += songName; pf->ReportError(err); return false; } m_songNames.push_back(songName); } return true; }
// Load songs into the song array void gui::load_song_info() { string line; int index = 0; // Build song array line by line ifstream songFile("song_list.txt"); while(getline(songFile, line)) { // Make line into stream (format: index \t name \t artist) stringstream songStream(line); string junk; //index can be predicted so not necessary string name; string artist; // Extract data getline(songStream, junk,'\t'); getline(songStream, name,'\t'); getline(songStream, artist,'\t'); // Update song entry songs_ds[index].name = name; songs_ds[index].artist = artist; songs_ds[index].popularity = 0; songs_ds[index].index = index; for(int i = 0; i < NUM_POPULAR_PLAYLISTS; i++) { songs_ds[index].topPlaylists[i] = NULL; } index++; } }