diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2010-01-16 18:51:57 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-05 17:17:44 +0100 |
commit | 4949504dfaa79e32b9dc24c2937fdad63c8fcff5 (patch) | |
tree | 99992af7f1884f3ee5761e15040f4c7bf87609c3 | |
parent | 4608cae0351df026900be5301a26f7e833d4449c (diff) | |
download | usdx-4949504dfaa79e32b9dc24c2937fdad63c8fcff5.tar.gz usdx-4949504dfaa79e32b9dc24c2937fdad63c8fcff5.tar.xz usdx-4949504dfaa79e32b9dc24c2937fdad63c8fcff5.zip |
cut big function for parsing song lines in some smaller
Diffstat (limited to '')
-rw-r--r-- | src/base/songloading/songloading_strategy_txt.cpp | 154 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_txt.hpp | 7 |
2 files changed, 91 insertions, 70 deletions
diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp index 6b9a03b7..5f2017a6 100644 --- a/src/base/songloading/songloading_strategy_txt.cpp +++ b/src/base/songloading/songloading_strategy_txt.cpp @@ -105,90 +105,104 @@ namespace usdx LOG4CXX_DEBUG(log, "Starting loading song from file: " << song->get_filename()); File file(song->get_filename()); - std::string line; - char type; - int line_number = 0;; + int line_number = 0; + while (file.stream().good() && parse_line(song, file, ++line_number)); - while (file.stream().good()) { - std::getline(file.stream(), line); - ++line_number; + // fill song - std::istringstream linestream(line); - linestream >> std::skipws >> type; + return song; + } - if (type == '#') { - // ignore, header already read - } - else if (type == 'E') { - // song end - if (file.stream().eof()) { - LOG4CXX_WARN(log, "End marker found in line " << line_number << - " before end of file: '" << song->get_filename() << "'."); - } + bool SongloadingStrategyTxt::parse_line(Song* song, File& file, const int line_number) + { + std::string line; + std::getline(file.stream(), line); - break; - } - else if (type == '-') { - // line break - int line_out, line_in = -1; - - linestream >> line_out; - if (linestream.good()) { - linestream >> line_in; - LOG4CXX_DEBUG(log, "Found newline in line " << - line_number << " with out of last line with " - << line_out << " and in of next line " << line_in); - } - else { - LOG4CXX_DEBUG(log, "Found newline in line " << - line_number << " with out of last line with " - << line_out); - } + char type; + std::istringstream linestream(line); + linestream >> std::skipws >> type; -// song.new_line(line_out, line_in); - } - else if (type == 'B') { - // new bpm - int beat; - LocaleIndependentFloat new_bpm; - - linestream >> beat >> new_bpm; - LOG4CXX_DEBUG(log, "Found new bpm in line " << - line_number << " starting at beat: " << - beat << " and new bpm of " << new_bpm.get_value()); -// song.new_bpm(new_beat, new_bpm); - } - else if (type == ':' || type == 'F' || type == '*') { - // normal line - int beat, length, height; - std::string lyric; - - linestream >> beat >> length >> height >> std::noskipws; - linestream.ignore(); - getline(linestream, lyric); - - LOG4CXX_DEBUG(log, "Found lyric: '" << lyric << "' at line: " << line_number << - " at beat: " << beat << " with length: " << length << - " at height: " << height); -// song.new_note(beat, length, height, lyric); - } - else { - LOG4CXX_WARN(log, "Unknown line in song: '" << line << - "' in file: " << song->get_filename() << - " at line " << line_number); + if (type == '#') { + // ignore, header already read + } + else if (type == 'E') { + // song end + if (file.stream().eof()) { + LOG4CXX_WARN(log, "End marker found in line " << line_number << + " before end of file: '" << song->get_filename() << "'."); } + + return false; + } + else if (type == '-') { + parse_newline(song, linestream, line_number); + } + else if (type == 'B') { + parse_bpm(song, linestream, line_number); + } + else if (type == ':' || type == 'F' || type == '*') { + parse_note(song, type, linestream, line_number); + } + else { + LOG4CXX_WARN(log, "Unknown line in song: '" << line << + "' in file: " << song->get_filename() << + " at line " << line_number); } - // fill song + return true; + } - return song; + void SongloadingStrategyTxt::parse_newline(Song *song, std::istringstream& linestream, const int line_number) + { + // line break + int line_out, line_in = -1; + + linestream >> line_out; + if (linestream.good()) { + linestream >> line_in; + LOG4CXX_DEBUG(log, "Found newline in line " << + line_number << " with out of last line with " + << line_out << " and in of next line " << line_in); + } + else { + LOG4CXX_DEBUG(log, "Found newline in line " << + line_number << " with out of last line with " + << line_out); + } + + // song.new_line(line_out, line_in); } -/* void SongloadingStrategyTxt::parse_line(const std::string& line, const int line_num) + void SongloadingStrategyTxt::parse_bpm(Song *song, std::istringstream& linestream, const int line_number) { + // new bpm + int beat; + LocaleIndependentFloat new_bpm; + + linestream >> beat >> new_bpm; + LOG4CXX_DEBUG(log, "Found new bpm in line " << + line_number << " starting at beat: " << + beat << " and new bpm of " << new_bpm.get_value()); + // song.new_bpm(new_beat, new_bpm); } -*/ + + void SongloadingStrategyTxt::parse_note(Song *song, char type, std::istringstream& linestream, const int line_number) + { + // normal line + int beat, length, height; + std::string lyric; + + linestream >> beat >> length >> height >> std::noskipws; + linestream.ignore(); + getline(linestream, lyric); + + LOG4CXX_DEBUG(log, "Found lyric: '" << lyric << "' at line: " << line_number << + " at beat: " << beat << " with length: " << length << + " at height: " << height); + // song.new_note(beat, length, height, lyric); + } + Song* SongloadingStrategyTxt::load_header(const std::string& filename) { File file(filename); diff --git a/src/base/songloading/songloading_strategy_txt.hpp b/src/base/songloading/songloading_strategy_txt.hpp index 31a9815a..b397d2f7 100644 --- a/src/base/songloading/songloading_strategy_txt.hpp +++ b/src/base/songloading/songloading_strategy_txt.hpp @@ -30,6 +30,7 @@ #include <string> #include <log4cxx/logger.h> #include "songloading_strategy.hpp" +#include "utils/file.hpp" namespace usdx { @@ -58,6 +59,12 @@ namespace usdx */ std::string& trim(std::string& line); + bool parse_line(Song* song, File& file, const int line_number); + void parse_newline(Song* song, std::istringstream& linestream, const int line_number); + void parse_bpm(Song* song, std::istringstream& linestream, const int line_number); + void parse_note(Song* song, char type, std::istringstream& linestream, const int line_number); + + public: SongloadingStrategyTxt(); virtual ~SongloadingStrategyTxt(); |