/** * @brief Returns all sub-configuration with given name. * * @param name Sub-configuration name. * * @return */ DynamicArray<UniquePtr<config::Implementation>> getSubs(StringView name) const noexcept override { DynamicArray<UniquePtr<config::Implementation>> res; // Foreach children for (const auto& node : m_node.children(name.getData())) res.push_back(makeUnique<ConfigImplementation>(node.internal_object())); return res; }
/** * @brief Add molecules of given name. * * @param name Molecule name. * @param diff Number of molecules. */ void changeMoleculeCount(const StringView& name, MoleculeCountDifference diff) noexcept { // Get mutable reference auto& value = m_molecules[name.getData()]; // We need to compare signed versions. // If not, this condition is always true. if (MoleculeCountDifference(value) + diff < 0) value = MoleculeCount(0); else value += diff; }
/** * @brief Check if value with given name exists. * * @param name Value name. * * @return */ bool has(StringView name) const noexcept override { return !m_node.attribute(name.getData()).empty(); }
/** * @brief Create new sub-configuration. * * @param name Sub-configuration name. * * @return */ UniquePtr<config::Implementation> addSub(StringView name) noexcept override { return makeUnique<ConfigImplementation>(m_node.append_child(name.getData())); }
/** * @brief Store content. * * @param content Content text. */ void setContent(StringView content) noexcept override { m_node.text().set(content.getData()); }
/** * @brief Set string value. * * @param name Value name. * @param value Value to store. * * @return */ void set(StringView name, StringView value) noexcept override { m_node.attribute(name.getData()).set_value(value.getData()); }
/** * @brief Returns if sub-configuration exists. * * @param name Sub-configuration name. * * @return */ bool hasSubs(StringView name) const noexcept override { auto rng = m_node.children(name.getData()); return rng.begin() != rng.end(); }
/** * @brief Returns string value. * * @param name Value name. * * @return */ String get(StringView name) const noexcept override { return m_node.attribute(name.getData()).value(); }
/** * @brief Set a number of molecules of given name. * * @param name Molecule name. * @param count Number of molecules. */ void setMoleculeCount(const StringView& name, MoleculeCount count) noexcept { m_molecules[name.getData()] = count; }
/** * @brief Returns a number moulecules of given name. * * @param name Molecule name. * * @return Number of molecules. */ MoleculeCount getMoleculeCount(const StringView& name) const noexcept { auto it = m_molecules.find(name.getData()); return it != m_molecules.end() ? it->second : MoleculeCount(); }
TEST(StringViewTests, stdStringConstructor) { std::string string("ABCD"); const StringView view = string; ASSERT_EQ(string.data(), view.getData()); ASSERT_EQ(string.size(), view.getSize()); }
TEST(StringViewTests, arrayConstructor) { const char data[] = "ABCD"; const StringView view = data; ASSERT_EQ(data, view.getData()); ASSERT_EQ(4, view.getSize()); }