diff --git a/wxdata/include/scwx/gr/placefile.hpp b/wxdata/include/scwx/gr/placefile.hpp index 2f1c0833..20672008 100644 --- a/wxdata/include/scwx/gr/placefile.hpp +++ b/wxdata/include/scwx/gr/placefile.hpp @@ -84,11 +84,13 @@ public: */ std::vector> GetDrawItems(); + std::string title() const; std::unordered_map> fonts(); std::shared_ptr font(std::size_t i); static std::shared_ptr Load(const std::string& filename); - static std::shared_ptr Load(std::istream& is); + static std::shared_ptr Load(const std::string& name, + std::istream& is); private: class Impl; diff --git a/wxdata/source/scwx/gr/placefile.cpp b/wxdata/source/scwx/gr/placefile.cpp index d35c67d6..a3ef8f16 100644 --- a/wxdata/source/scwx/gr/placefile.cpp +++ b/wxdata/source/scwx/gr/placefile.cpp @@ -51,6 +51,7 @@ public: static void ProcessEscapeCharacters(std::string& s); static void TrimQuotes(std::string& s); + std::string title_ {}; std::chrono::seconds refresh_ {-1}; // Parsing state @@ -84,6 +85,11 @@ std::vector> Placefile::GetDrawItems() return p->drawItems_; } +std::string Placefile::title() const +{ + return p->title_; +} + std::unordered_map> Placefile::fonts() { @@ -104,13 +110,16 @@ std::shared_ptr Placefile::Load(const std::string& filename) { logger_->debug("Loading placefile: {}", filename); std::ifstream f(filename, std::ios_base::in); - return Load(f); + return Load(filename, f); } -std::shared_ptr Placefile::Load(std::istream& is) +std::shared_ptr Placefile::Load(const std::string& name, + std::istream& is) { std::shared_ptr placefile = std::make_shared(); + placefile->p->title_ = name; + std::string line; while (scwx::util::getline(is, line)) { @@ -167,6 +176,7 @@ std::shared_ptr Placefile::Load(std::istream& is) void Placefile::Impl::ProcessLine(const std::string& line) { + static const std::string titleKey_ {"Title:"}; static const std::string thresholdKey_ {"Threshold:"}; static const std::string hsluvKey_ {"HSLuv:"}; static const std::string colorKey_ {"Color:"}; @@ -189,7 +199,13 @@ void Placefile::Impl::ProcessLine(const std::string& line) // When tokenizing, add one additional delimiter to discard unexpected // parameters (where appropriate) - if (boost::istarts_with(line, thresholdKey_)) + if (boost::istarts_with(line, titleKey_)) + { + // Title: title + title_ = line.substr(titleKey_.size()); + boost::trim(title_); + } + else if (boost::istarts_with(line, thresholdKey_)) { // Threshold: nautical_miles std::vector tokenList = @@ -394,10 +410,6 @@ void Placefile::Impl::ProcessLine(const std::string& line) { objectStack_.pop_back(); } - else - { - logger_->warn("End found without Object"); - } } else if (boost::istarts_with(line, lineKey_)) {