diff options
Diffstat (limited to 'src/base/songloading')
-rw-r--r-- | src/base/songloading/songloader.cpp | 12 | ||||
-rw-r--r-- | src/base/songloading/songloader.hpp | 2 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_base_factory.cpp | 4 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_base_factory.hpp | 6 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_txt.cpp | 93 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_txt.hpp | 16 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_xml.hpp | 2 |
7 files changed, 67 insertions, 68 deletions
diff --git a/src/base/songloading/songloader.cpp b/src/base/songloading/songloader.cpp index 0524d18c..5562bdc7 100644 --- a/src/base/songloading/songloader.cpp +++ b/src/base/songloading/songloader.cpp @@ -58,10 +58,10 @@ namespace usdx Song *Songloader::load_header(const boost::filesystem::wpath& filename) { - std::wstring ext = extension(filename); - std::map<std::wstring, SongloadingStrategyBaseFactory*>::iterator it = strategies.find(ext); + std::string ext = extension(filename); + std::map<std::string, SongloadingStrategyBaseFactory*>::iterator it = strategies.find(ext); if (it == strategies.end()) { - LOG4CXX_WARN(log, L"No SongloadingStrategy found for file extension: '" << ext << L"'"); + LOG4CXX_WARN(log, "No SongloadingStrategy found for file extension: '" << ext << "'"); throw NoStrategyException("Unknown file format."); } @@ -70,10 +70,10 @@ namespace usdx Song* Songloader::load_song(Song* song) { - std::wstring ext = extension(song->get_filename()); - std::map<std::wstring, SongloadingStrategyBaseFactory*>::iterator it = strategies.find(ext); + std::string ext = extension(song->get_filename()); + std::map<std::string, SongloadingStrategyBaseFactory*>::iterator it = strategies.find(ext); if (it == strategies.end()) { - LOG4CXX_WARN(log, L"No SongloadingStrategy found for file extension: '" << ext << L"'"); + LOG4CXX_WARN(log, "No SongloadingStrategy found for file extension: '" << ext << "'"); throw NoStrategyException("Unknown file format."); } diff --git a/src/base/songloading/songloader.hpp b/src/base/songloading/songloader.hpp index ac18f41d..4b7150ab 100644 --- a/src/base/songloading/songloader.hpp +++ b/src/base/songloading/songloader.hpp @@ -50,7 +50,7 @@ namespace usdx Songloader(void); - std::map<std::wstring, SongloadingStrategyBaseFactory*> strategies; + std::map<std::string, SongloadingStrategyBaseFactory*> strategies; /** * Singleton diff --git a/src/base/songloading/songloading_strategy_base_factory.cpp b/src/base/songloading/songloading_strategy_base_factory.cpp index 9f8333b4..7b61ce9c 100644 --- a/src/base/songloading/songloading_strategy_base_factory.cpp +++ b/src/base/songloading/songloading_strategy_base_factory.cpp @@ -29,12 +29,12 @@ namespace usdx { - SongloadingStrategyBaseFactory::SongloadingStrategyBaseFactory(std::wstring fileextension) : fileextension(fileextension) + SongloadingStrategyBaseFactory::SongloadingStrategyBaseFactory(std::string fileextension) : fileextension(fileextension) { Songloader::get_instance()->add_strategy(this); } - std::wstring SongloadingStrategyBaseFactory::get_fileextension(void) + std::string SongloadingStrategyBaseFactory::get_fileextension(void) { return fileextension; } diff --git a/src/base/songloading/songloading_strategy_base_factory.hpp b/src/base/songloading/songloading_strategy_base_factory.hpp index ae20b1ce..57eff0fb 100644 --- a/src/base/songloading/songloading_strategy_base_factory.hpp +++ b/src/base/songloading/songloading_strategy_base_factory.hpp @@ -41,14 +41,14 @@ namespace usdx /// no copy void operator=(SongloadingStrategyBaseFactory&) {}; - std::wstring fileextension; + std::string fileextension; public: - SongloadingStrategyBaseFactory(std::wstring fileextension); + SongloadingStrategyBaseFactory(std::string fileextension); virtual ~SongloadingStrategyBaseFactory(void) {}; virtual SongloadingStrategy *get_songloader(void) = 0; - std::wstring get_fileextension(void); + std::string get_fileextension(void); }; }; diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp index b80289ee..a7d296a5 100644 --- a/src/base/songloading/songloading_strategy_txt.cpp +++ b/src/base/songloading/songloading_strategy_txt.cpp @@ -32,7 +32,6 @@ #include <boost/algorithm/string.hpp> #include "songloading_strategy_txt.hpp" -#include "utils/unicode_file.hpp" #include "utils/locale_independent_float.hpp" namespace usdx @@ -49,16 +48,16 @@ namespace usdx { } - std::pair<std::wstring, std::wstring> SongloadingStrategyTxt::split_header_field(std::wstring &line) + std::pair<std::string, std::string> SongloadingStrategyTxt::split_header_field(std::string &line) { - std::size_t pos = line.find(L':'); + std::size_t pos = line.find(':'); - if (line[0] != L'#' || pos == std::wstring::npos) { - LOG4CXX_DEBUG(log, L"Tried to parse invalid header line: '" << line << L"'"); + if (line[0] != '#' || pos == std::string::npos) { + LOG4CXX_DEBUG(log, "Tried to parse invalid header line: '" << line << "'"); throw "Invalid header!"; } - std::pair<std::wstring, std::wstring> result; + std::pair<std::string, std::string> result; // copy the substring until ':', without # to result.first and // transform to upper case @@ -74,16 +73,16 @@ namespace usdx // line is already rtrimmed boost::trim_left(result.second); - LOG4CXX_DEBUG(log, L"Found header: '" << result.first << L"' with value '" << result.second << L"'"); + LOG4CXX_DEBUG(log, "Found header: '" << result.first << "' with value '" << result.second << "'"); return result; } Song* SongloadingStrategyTxt::load_song(Song *song) { - LOG4CXX_DEBUG(log, L"Starting loading song from file: " << song->get_filename()); + LOG4CXX_DEBUG(log, "Starting loading song from file: " << song->get_filename()); - UnicodeFile file(song->get_filename()); + TextFile file(song->get_filename()); int line_number = 0; while (file.stream().good() && parse_line(song, file, ++line_number)); @@ -93,52 +92,52 @@ namespace usdx return song; } - bool SongloadingStrategyTxt::parse_line(Song* song, UnicodeFile& file, const int line_number) + bool SongloadingStrategyTxt::parse_line(Song* song, TextFile& file, const int line_number) { try { - std::wstring line; + std::string line; std::getline(file.stream(), line); - wchar_t type; - std::wistringstream linestream(line); + char type; + std::istringstream linestream(line); linestream >> std::skipws >> type; - if (type == L'#') { + if (type == '#') { // ignore, header already read } - else if (type == L'E') { + else if (type == 'E') { // song end if (file.stream().eof()) { - LOG4CXX_WARN(log, L"End marker found in line " << line_number << - L" before end of file: '" << song->get_filename() << L"'."); + LOG4CXX_WARN(log, "End marker found in line " << line_number << + " before end of file: '" << song->get_filename() << "'."); } return false; } - else if (type == L'-') { + else if (type == '-') { parse_newline(song, linestream, line_number); } - else if (type == L'B') { + else if (type == 'B') { parse_bpm(song, linestream, line_number); } - else if (type == L':' || type == L'F' || type == L'*') { + else if (type == ':' || type == 'F' || type == '*') { parse_note(song, type, linestream, line_number); } else { - LOG4CXX_WARN(log, L"Unknown line in song: '" << line << - L"' in file: " << song->get_filename() << - L" at line " << line_number); + LOG4CXX_WARN(log, "Unknown line in song: '" << line << + "' in file: " << song->get_filename() << + " at line " << line_number); } } catch (std::exception &e) { - LOG4CXX_WARN(log, L"Error in song file at line " << - line_number << L": " << e.what()); + LOG4CXX_WARN(log, "Error in song file at line " << + line_number << ": " << e.what()); } return true; } - void SongloadingStrategyTxt::parse_newline(Song *song, std::wistringstream& linestream, const int line_number) + void SongloadingStrategyTxt::parse_newline(Song *song, std::istringstream& linestream, const int line_number) { // line break int line_out, line_in = -1; @@ -146,54 +145,54 @@ namespace usdx linestream >> line_out; if (linestream.good()) { linestream >> line_in; - LOG4CXX_DEBUG(log, L"Found newline in line " << - line_number << L" with out of last line with " << - line_out << L" and in of next line " << 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, L"Found newline in line " << - line_number << L" with out of last line with " << + 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_bpm(Song *song, std::wistringstream& linestream, const int line_number) + 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, L"Found new bpm in line " << - line_number << L" starting at beat: " << - beat << L" and new bpm of " << new_bpm.get_value()); + 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(beat, new_bpm.get_value()); } - void SongloadingStrategyTxt::parse_note(Song *song, wchar_t type, std::wistringstream& linestream, const int line_number) + void SongloadingStrategyTxt::parse_note(Song *song, char type, std::istringstream& linestream, const int line_number) { // normal line int beat, length, height; - std::wstring lyric; + std::string lyric; linestream >> beat >> length >> height >> std::noskipws; linestream.ignore(); getline(linestream, lyric); boost::trim_right_if(lyric, boost::is_cntrl()); - LOG4CXX_DEBUG(log, L"Found lyric: '" << lyric << L"' at line: " << line_number << - L" at beat: " << beat << L" with length: " << length << - L" at height: " << height); + LOG4CXX_DEBUG(log, "Found lyric: '" << lyric << "' at line: " << line_number << + " at beat: " << beat << " with length: " << length << + " at height: " << height); song->new_note(type, beat, length, height, lyric); } Song* SongloadingStrategyTxt::load_header(const boost::filesystem::wpath& filename) { - UnicodeFile file(filename); - std::wstring line; - std::map<std::wstring, std::wstring> header_fields; + TextFile file(filename); + std::string line; + std::map<std::string, std::string> header_fields; bool header = true, notes_found = false; while (file.stream().good()) { @@ -201,9 +200,9 @@ namespace usdx boost::trim(line); boost::trim_if(line, boost::is_cntrl()); - LOG4CXX_DEBUG(log, L"Line: " << line); + LOG4CXX_DEBUG(log, "Line: " << line); - if (header && line[0] == L'#') { + if (header && line[0] == '#') { // header header_fields.insert(split_header_field(line)); @@ -214,7 +213,7 @@ namespace usdx header = false; } - if (line[0] == L':' || line[0] == L'*' || line[0] == L'F') { + if (line[0] == ':' || line[0] == '*' || line[0] == 'F') { notes_found = true; break; } @@ -222,7 +221,7 @@ namespace usdx } if (! notes_found) { - LOG4CXX_WARN(log, L"Song: '" << filename << L"' has no notes. Ignoring!"); + LOG4CXX_WARN(log, "Song: '" << filename << "' has no notes. Ignoring!"); throw "No notes."; } diff --git a/src/base/songloading/songloading_strategy_txt.hpp b/src/base/songloading/songloading_strategy_txt.hpp index 6177a5d3..293c65e6 100644 --- a/src/base/songloading/songloading_strategy_txt.hpp +++ b/src/base/songloading/songloading_strategy_txt.hpp @@ -32,7 +32,7 @@ #include <log4cxx/logger.h> #include "songloading_strategy.hpp" #include "songloading_strategy_factory.hpp" -#include "utils/unicode_file.hpp" +#include "utils/text_file.hpp" namespace usdx { @@ -44,21 +44,21 @@ namespace usdx /** * Split the header field in name and value. */ - std::pair<std::wstring, std::wstring> split_header_field(std::wstring &line); + std::pair<std::string, std::string> split_header_field(std::string &line); - bool parse_line(Song* song, UnicodeFile& file, const int line_number); - void parse_newline(Song* song, std::wistringstream& linestream, const int line_number); - void parse_bpm(Song* song, std::wistringstream& linestream, const int line_number); - void parse_note(Song* song, wchar_t type, std::wistringstream& linestream, const int line_number); + bool parse_line(Song* song, TextFile& 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(); virtual Song* load_song(Song* song); - virtual Song* load_header(const boost::filesystem::wpath& filename); + virtual Song* load_header(const boost::filesystem::path& filename); - static std::wstring get_fileextension(void) { return L".txt"; }; + static std::string get_fileextension(void) { return ".txt"; }; }; REGISTER_SONGLOADING_STRATEGY(SongloadingStrategyTxt); diff --git a/src/base/songloading/songloading_strategy_xml.hpp b/src/base/songloading/songloading_strategy_xml.hpp index 38637646..17ccd034 100644 --- a/src/base/songloading/songloading_strategy_xml.hpp +++ b/src/base/songloading/songloading_strategy_xml.hpp @@ -42,7 +42,7 @@ namespace usdx virtual Song* load_song(Song* song); virtual Song* load_header(const boost::filesystem::wpath& filename); - static std::wstring get_fileextension(void) { return L".xml"; }; + static std::string get_fileextension(void) { return ".xml"; }; }; REGISTER_SONGLOADING_STRATEGY(SongloadingStrategyXml); |