aboutsummaryrefslogtreecommitdiffstats
path: root/src/base/song.cpp
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-01-18 03:27:27 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:45 +0100
commit6866019fdec1c345d4f626861c640122a90e0ce8 (patch)
treef064c5c59d7bc2963c594553587dd6a4d952cc79 /src/base/song.cpp
parent1d4fd42795331fe1cfb8e404f1784cf20f387649 (diff)
downloadusdx-6866019fdec1c345d4f626861c640122a90e0ce8.tar.gz
usdx-6866019fdec1c345d4f626861c640122a90e0ce8.tar.xz
usdx-6866019fdec1c345d4f626861c640122a90e0ce8.zip
added functions for parsing float, int and bool headers
Diffstat (limited to 'src/base/song.cpp')
-rw-r--r--src/base/song.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/base/song.cpp b/src/base/song.cpp
index f596e480..a12a6657 100644
--- a/src/base/song.cpp
+++ b/src/base/song.cpp
@@ -26,6 +26,7 @@
#include "song.hpp"
#include "lyric_word.hpp"
+#include "utils/locale_independent_float.hpp"
namespace usdx
{
@@ -119,6 +120,62 @@ namespace usdx
return result;
}
+ float Song::get_header_tag_float(const std::string& tag, const bool required)
+ {
+ std::map<std::string, std::string>::iterator it;
+ float result;
+
+ if ((it = custom_header_tags.find(tag)) != custom_header_tags.end()) {
+ result = LocaleIndependentFloat(it->second).get_value();
+ custom_header_tags.erase(it);
+ }
+ else if (required) {
+ LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << get_filename() << "'");
+ throw "Incomplete Song! Missing Tag.";
+ }
+
+ return result;
+ }
+
+ int Song::get_header_tag_int(const std::string& tag, const bool required)
+ {
+ std::map<std::string, std::string>::iterator it;
+ int result;
+
+ if ((it = custom_header_tags.find(tag)) != custom_header_tags.end()) {
+ std::istringstream stream(it->second);
+ custom_header_tags.erase(it);
+ stream >> result;
+ }
+ else if (required) {
+ LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << get_filename() << "'");
+ throw "Incomplete Song! Missing Tag.";
+ }
+
+ return result;
+ }
+
+ bool Song::get_header_tag_bool(const std::string& tag, const bool required)
+ {
+ std::map<std::string, std::string>::iterator it;
+ bool result;
+
+ if ((it = custom_header_tags.find(tag)) != custom_header_tags.end()) {
+ // accept all like (YES, JA, TRUE, 1)
+ result = (it->second[0] == 'j' || it->second[0] == 'J' ||
+ it->second[0] == 'y' || it->second[0] == 'Y' ||
+ it->second[0] == 't' || it->second[0] == 'T' ||
+ it->second[0] == '1');
+ custom_header_tags.erase(it);
+ }
+ else if (required) {
+ LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << get_filename() << "'");
+ throw "Incomplete Song! Missing Tag.";
+ }
+
+ return result;
+ }
+
LyricLine* Song::get_last_lyric_line(void)
{
if (lyrics.size() > 0) {