예제 #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;
    }
예제 #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;
    }
예제 #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();
 }
예제 #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()));
 }
예제 #5
0
 /**
  * @brief Store content.
  *
  * @param content Content text.
  */
 void setContent(StringView content) noexcept override
 {
     m_node.text().set(content.getData());
 }
예제 #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());
 }
예제 #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();
 }
예제 #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();
 }
예제 #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;
 }
예제 #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();
 }
예제 #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());
}
예제 #12
0
TEST(StringViewTests, arrayConstructor) {
  const char data[] = "ABCD";
  const StringView view = data;
  ASSERT_EQ(data, view.getData());
  ASSERT_EQ(4, view.getSize());
}