diff options
Diffstat (limited to 'cpp/pom.cpp')
-rw-r--r-- | cpp/pom.cpp | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/cpp/pom.cpp b/cpp/pom.cpp index 058040e..29dc7e1 100644 --- a/cpp/pom.cpp +++ b/cpp/pom.cpp @@ -192,30 +192,13 @@ std::vector<std::string> Configuration::keys() const { return keys; } -class ItemImpl: public Item { -public: - ItemImpl(const pom_item *C) { - m_key = C->key; - m_value = C->value; - m_file = C->file; - m_line = C->line; - } - virtual ~ItemImpl() {} - virtual std::string_view key() const noexcept override { return m_key; } - virtual std::string_view value() const noexcept override { return m_value; } - virtual std::string_view file() const noexcept override { return m_file; } - virtual uint64_t line() const noexcept override { return m_line; } - std::string m_key, m_value, m_file; - uint64_t m_line; -}; - -std::vector<std::shared_ptr<Item>> Configuration::items() const { +std::vector<std::unique_ptr<Item>> Configuration::items() const { if (!C) return {}; - std::vector<std::shared_ptr<Item>> items; + std::vector<std::unique_ptr<Item>> items; pom_item_iter *iter = nullptr; const pom_item *item; while ((item = pom_conf_next_item(static_cast<const pom_conf *>(C), &iter))) { - items.push_back(std::shared_ptr<Item>(new ItemImpl(item))); + items.push_back(std::unique_ptr<Item>(new Item(item->key, item->value, item->file, item->line))); } return items; } @@ -314,7 +297,7 @@ Configuration &Configuration::operator=(const Configuration &other) { } std::ostream &operator<<(std::ostream &o, const Configuration &conf) { - for (auto item: conf.items()) + for (const auto &item: conf.items()) o << item->key() << ": " << item->value() << "\n"; return o; } @@ -330,6 +313,12 @@ std::optional<Location> Configuration::location(std::string_view key) const { return {}; } +bool Configuration::has(std::string_view key) const { + if (!C) return false; + std::string key_str(key); + return pom_conf_has(static_cast<const pom_conf *>(C), key_str.c_str()); +} + std::ostream &operator<<(std::ostream &o, const Location &location) { return o << location.file() << ":" << location.line(); } |