Example #1
0
    /**
     * @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;
    }
Example #2
0
    /**
     * @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;
    }
Example #3
0
 /**
  * @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();
 }
Example #4
0
 /**
  * @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()));
 }
Example #5
0
 /**
  * @brief Store content.
  *
  * @param content Content text.
  */
 void setContent(StringView content) noexcept override
 {
     m_node.text().set(content.getData());
 }
Example #6
0
 /**
  * @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());
 }
Example #7
0
 /**
  * @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();
 }
Example #8
0
 /**
  * @brief Returns string value.
  *
  * @param name Value name.
  *
  * @return
  */
 String get(StringView name) const noexcept override
 {
     return m_node.attribute(name.getData()).value();
 }
Example #9
0
 /**
  * @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;
 }
Example #10
0
 /**
  * @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();
 }
Example #11
0
TEST(StringViewTests, stdStringConstructor) {
  std::string string("ABCD");
  const StringView view = string;
  ASSERT_EQ(string.data(), view.getData());
  ASSERT_EQ(string.size(), view.getSize());
}
Example #12
0
TEST(StringViewTests, arrayConstructor) {
  const char data[] = "ABCD";
  const StringView view = data;
  ASSERT_EQ(data, view.getData());
  ASSERT_EQ(4, view.getSize());
}