diff options
-rw-r--r-- | src/base/song.cpp | 13 | ||||
-rw-r--r-- | src/base/song.hpp | 9 | ||||
-rw-r--r-- | src/base/songloading/songloader.cpp | 32 | ||||
-rw-r--r-- | src/base/songloading/songloader.hpp | 5 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy.hpp | 3 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_txt.cpp | 13 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_txt.hpp | 3 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_xml.cpp | 2 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_xml.hpp | 3 | ||||
-rw-r--r-- | test/base/songloading.cpp | 10 |
10 files changed, 44 insertions, 49 deletions
diff --git a/src/base/song.cpp b/src/base/song.cpp index ff00bbed..959102c2 100644 --- a/src/base/song.cpp +++ b/src/base/song.cpp @@ -33,12 +33,13 @@ namespace usdx log4cxx::LoggerPtr Song::log = log4cxx::Logger::getLogger("usdx.base.Song"); - const std::string& Song::get_filename(void) const + const boost::filesystem::wpath& Song::get_filename(void) const { return filename; } - Song::Song(const std::string& filename, const std::map<std::wstring, std::wstring>& header) : + Song::Song(const boost::filesystem::wpath& filename, + const std::map<std::wstring, std::wstring>& header) : filename(filename), custom_header_tags(header) { std::map<std::wstring, std::wstring>::iterator it; @@ -108,7 +109,7 @@ namespace usdx } else if (required) { LOG4CXX_ERROR(log, L"Incomplete Song! Missing '" << tag << L"' Tag in: '" << - std::wstring(get_filename().begin(), get_filename().end()) << L"'"); + get_filename() << L"'"); throw MissingTagException(tag, "Incomplete Song! Missing Tag."); } @@ -126,7 +127,7 @@ namespace usdx } else if (required) { LOG4CXX_ERROR(log, L"Incomplete Song! Missing '" << tag << L"' Tag in: '" << - std::wstring(get_filename().begin(), get_filename().end()) << L"'"); + get_filename() << L"'"); throw MissingTagException(tag, "Incomplete Song! Missing Tag."); } @@ -145,7 +146,7 @@ namespace usdx } else if (required) { LOG4CXX_ERROR(log, L"Incomplete Song! Missing '" << tag << L"' Tag in: '" << - std::wstring(get_filename().begin(), get_filename().end()) << L"'"); + get_filename() << L"'"); throw MissingTagException(tag, "Incomplete Song! Missing Tag."); } @@ -167,7 +168,7 @@ namespace usdx } else if (required) { LOG4CXX_ERROR(log, L"Incomplete Song! Missing '" << tag << L"' Tag in: '" << - std::wstring(get_filename().begin(), get_filename().end()) << L"'"); + get_filename() << L"'"); throw MissingTagException(tag, "Incomplete Song! Missing Tag."); } diff --git a/src/base/song.hpp b/src/base/song.hpp index d9a6271c..2217e244 100644 --- a/src/base/song.hpp +++ b/src/base/song.hpp @@ -30,6 +30,7 @@ #include <string> #include <map> #include <list> +#include <boost/filesystem.hpp> #include <log4cxx/logger.h> #include "bpm.hpp" #include "lyric_line.hpp" @@ -60,7 +61,7 @@ namespace usdx private: static log4cxx::LoggerPtr log; - std::string filename; + boost::filesystem::wpath filename; std::wstring title; std::wstring artist; @@ -114,10 +115,12 @@ namespace usdx // TODO: Encoding: TEncoding; public: - Song(const std::string& filename, const std::map<std::wstring, std::wstring>& header); + Song(const boost::filesystem::wpath& filename, + const std::map<std::wstring, std::wstring>& header); + virtual ~Song(void); - const std::string& get_filename(void) const; + const boost::filesystem::wpath& get_filename(void) const; const std::wstring& get_title(void) const; const std::wstring& get_artist(void) const; diff --git a/src/base/songloading/songloader.cpp b/src/base/songloading/songloader.cpp index 9c1401ec..2f3d3508 100644 --- a/src/base/songloading/songloader.cpp +++ b/src/base/songloading/songloader.cpp @@ -38,11 +38,11 @@ namespace usdx Songloader::Songloader(void) { // add different strategies to map - strategies[".txt"] = new SongloadingStrategyTxt(); - strategies[".xml"] = new SongloadingStrategyXml(); + strategies[L".txt"] = new SongloadingStrategyTxt(); + strategies[L".xml"] = new SongloadingStrategyXml(); } - void remove_element(std::pair<std::string, SongloadingStrategy*> e) + void remove_element(std::pair<std::wstring, SongloadingStrategy*> e) { delete e.second; e.second = NULL; @@ -68,18 +68,12 @@ namespace usdx return instance; } - Song *Songloader::load_header(std::string filename) + Song *Songloader::load_header(const boost::filesystem::wpath& filename) { - std::string extension = ""; - - size_t found = filename.rfind('.'); - if (found != std::string::npos) { - extension = filename.substr(found); - } - - std::map<std::string, SongloadingStrategy*>::iterator it = strategies.find(extension); + std::wstring ext = extension(filename); + std::map<std::wstring, SongloadingStrategy*>::iterator it = strategies.find(ext); if (it == strategies.end()) { - LOG4CXX_WARN(log, "No SongloadingStrategy found for file extension: '" << extension << "'"); + LOG4CXX_WARN(log, L"No SongloadingStrategy found for file extension: '" << ext << L"'"); throw NoStrategyException("Unknown file format."); } @@ -88,16 +82,10 @@ namespace usdx Song* Songloader::load_song(Song* song) { - std::string extension = ""; - - size_t found = song->get_filename().rfind('.'); - if (found != std::string::npos) { - extension = song->get_filename().substr(found); - } - - std::map<std::string, SongloadingStrategy*>::iterator it = strategies.find(extension); + std::wstring ext = extension(song->get_filename()); + std::map<std::wstring, SongloadingStrategy*>::iterator it = strategies.find(ext); if (it == strategies.end()) { - LOG4CXX_WARN(log, "No SongloadingStrategy found for file extension: '" << extension << "'"); + LOG4CXX_WARN(log, L"No SongloadingStrategy found for file extension: '" << ext << L"'"); throw NoStrategyException("Unknown file format."); } diff --git a/src/base/songloading/songloader.hpp b/src/base/songloading/songloader.hpp index 57afdefe..0e8a6bd1 100644 --- a/src/base/songloading/songloader.hpp +++ b/src/base/songloading/songloader.hpp @@ -28,6 +28,7 @@ #define SONGLOADER_HPP #include <map> +#include <boost/filesystem.hpp> #include <log4cxx/logger.h> #include "songloading_strategy.hpp" #include "song.hpp" @@ -49,7 +50,7 @@ namespace usdx Songloader(void); - std::map<std::string, SongloadingStrategy*> strategies; + std::map<std::wstring, SongloadingStrategy*> strategies; /** * Singleton @@ -61,7 +62,7 @@ namespace usdx virtual ~Songloader(void); - Song* load_header(std::string filename); + Song* load_header(const boost::filesystem::wpath& filename); Song* load_song(Song* song); }; }; diff --git a/src/base/songloading/songloading_strategy.hpp b/src/base/songloading/songloading_strategy.hpp index 5cded02d..48e115b7 100644 --- a/src/base/songloading/songloading_strategy.hpp +++ b/src/base/songloading/songloading_strategy.hpp @@ -28,6 +28,7 @@ #define SONGLOADING_STRATEGY_HPP #include <string> +#include <boost/filesystem.hpp> #include "song.hpp" namespace usdx @@ -41,7 +42,7 @@ namespace usdx virtual ~SongloadingStrategy() {}; virtual Song* load_song(Song* song) = 0; - virtual Song* load_header(const std::string& filename) = 0; + virtual Song* load_header(const boost::filesystem::wpath& filename) = 0; }; }; diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp index efcc3740..7560a9c2 100644 --- a/src/base/songloading/songloading_strategy_txt.cpp +++ b/src/base/songloading/songloading_strategy_txt.cpp @@ -81,7 +81,7 @@ namespace usdx Song* SongloadingStrategyTxt::load_song(Song *song) { - LOG4CXX_DEBUG(log, "Starting loading song from file: " << song->get_filename()); + LOG4CXX_DEBUG(log, L"Starting loading song from file: " << song->get_filename()); File file(song->get_filename()); @@ -109,8 +109,8 @@ namespace usdx else if (type == L'E') { // song end if (file.stream().eof()) { - LOG4CXX_WARN(log, "End marker found in line " << line_number << - " before end of file: '" << song->get_filename() << "'."); + LOG4CXX_WARN(log, L"End marker found in line " << line_number << + L" before end of file: '" << song->get_filename() << L"'."); } return false; @@ -126,8 +126,7 @@ namespace usdx } else { LOG4CXX_WARN(log, L"Unknown line in song: '" << line << - L"' in file: " << std::wstring(song->get_filename().begin(), - song->get_filename().end()) << + L"' in file: " << song->get_filename() << L" at line " << line_number); } } @@ -190,7 +189,7 @@ namespace usdx song->new_note(type, beat, length, height, lyric); } - Song* SongloadingStrategyTxt::load_header(const std::string& filename) + Song* SongloadingStrategyTxt::load_header(const boost::filesystem::wpath& filename) { File file(filename); std::wstring line; @@ -223,7 +222,7 @@ namespace usdx } if (! notes_found) { - LOG4CXX_WARN(log, "Song: '" << filename << "' has no notes. Ignoring!"); + LOG4CXX_WARN(log, L"Song: '" << filename << L"' 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 a285042f..13851e6e 100644 --- a/src/base/songloading/songloading_strategy_txt.hpp +++ b/src/base/songloading/songloading_strategy_txt.hpp @@ -28,6 +28,7 @@ #define SONGLOADING_STRATEGY_TXT_HPP #include <string> +#include <boost/filesystem.hpp> #include <log4cxx/logger.h> #include "songloading_strategy.hpp" #include "utils/file.hpp" @@ -55,7 +56,7 @@ namespace usdx virtual ~SongloadingStrategyTxt(); virtual Song* load_song(Song* song); - virtual Song* load_header(const std::string& filename); + virtual Song* load_header(const boost::filesystem::wpath& filename); }; }; diff --git a/src/base/songloading/songloading_strategy_xml.cpp b/src/base/songloading/songloading_strategy_xml.cpp index f7fea886..bae799a7 100644 --- a/src/base/songloading/songloading_strategy_xml.cpp +++ b/src/base/songloading/songloading_strategy_xml.cpp @@ -42,7 +42,7 @@ namespace usdx return song; } - Song* SongloadingStrategyXml::load_header(const std::string& filename) + Song* SongloadingStrategyXml::load_header(const boost::filesystem::wpath& filename) { return NULL; } diff --git a/src/base/songloading/songloading_strategy_xml.hpp b/src/base/songloading/songloading_strategy_xml.hpp index a01f9c11..76e3f76e 100644 --- a/src/base/songloading/songloading_strategy_xml.hpp +++ b/src/base/songloading/songloading_strategy_xml.hpp @@ -27,6 +27,7 @@ #ifndef SONGLOADING_STRATEGY_XML_HPP #define SONGLOADING_STRATEGY_XML_HPP +#include <boost/filesystem.hpp> #include "songloading_strategy.hpp" namespace usdx @@ -38,7 +39,7 @@ namespace usdx virtual ~SongloadingStrategyXml(void); virtual Song* load_song(Song* song); - virtual Song* load_header(const std::string& filename); + virtual Song* load_header(const boost::filesystem::wpath& filename); }; }; diff --git a/test/base/songloading.cpp b/test/base/songloading.cpp index 6b5c3af8..2d5ca19e 100644 --- a/test/base/songloading.cpp +++ b/test/base/songloading.cpp @@ -63,7 +63,7 @@ namespace usdx void testSongloadingTxtHeader() { - Song *song = Songloader::get_instance()->load_header("testdata/testsong_correct.txt"); + Song *song = Songloader::get_instance()->load_header(L"testdata/testsong_correct.txt"); CPPUNIT_ASSERT( L"Test Ă„rtist" == song->get_artist() ); CPPUNIT_ASSERT( 11 == song->get_artist().length() ); @@ -98,7 +98,7 @@ namespace usdx Logger::getRootLogger()->setLevel(Level::getOff()); Songloader::get_instance()-> - load_header("testdata/testsong_missing_artist.txt"); + load_header(L"testdata/testsong_missing_artist.txt"); } void testSongloadingTxtMissingHeaderFieldTitle() @@ -109,7 +109,7 @@ namespace usdx Logger::getRootLogger()->setLevel(Level::getOff()); Songloader::get_instance()-> - load_header("testdata/testsong_missing_title.txt"); + load_header(L"testdata/testsong_missing_title.txt"); } void testSongloadingTxtMissingHeaderFieldMp3() @@ -120,7 +120,7 @@ namespace usdx Logger::getRootLogger()->setLevel(Level::getOff()); Songloader::get_instance()-> - load_header("testdata/testsong_missing_mp3.txt"); + load_header(L"testdata/testsong_missing_mp3.txt"); } @@ -132,7 +132,7 @@ namespace usdx Logger::getRootLogger()->setLevel(Level::getOff()); Songloader::get_instance()-> - load_header("testdata/testsong_missing_bpm.txt"); + load_header(L"testdata/testsong_missing_bpm.txt"); } }; |