aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/include/kernel/filesystem/mount.hpp6
-rw-r--r--kernel/src/filesystem/mount_table.cpp2
-rw-r--r--libs/kstd/kstd/flat_map25
-rw-r--r--libs/kstd/kstd/flat_map.test.cpp27
4 files changed, 56 insertions, 4 deletions
diff --git a/kernel/include/kernel/filesystem/mount.hpp b/kernel/include/kernel/filesystem/mount.hpp
index 53d7f6d..ced4f81 100644
--- a/kernel/include/kernel/filesystem/mount.hpp
+++ b/kernel/include/kernel/filesystem/mount.hpp
@@ -85,12 +85,12 @@ namespace kernel::filesystem
[[nodiscard]] auto ref_count() const -> size_t;
private:
- kstd::shared_ptr<dentry> m_mount_dentry;
- kstd::shared_ptr<dentry> m_root_dentry;
+ kstd::shared_ptr<dentry> m_mount_dentry{};
+ kstd::shared_ptr<dentry> m_root_dentry{};
kstd::shared_ptr<filesystem> m_filesystem{};
kstd::shared_ptr<mount> m_parent_mount{};
kstd::weak_ptr<mount> m_source_mount{};
- std::atomic_size_t m_ref_count;
+ std::atomic_size_t m_ref_count{0};
};
} // namespace kernel::filesystem
diff --git a/kernel/src/filesystem/mount_table.cpp b/kernel/src/filesystem/mount_table.cpp
index af8434b..e4baac7 100644
--- a/kernel/src/filesystem/mount_table.cpp
+++ b/kernel/src/filesystem/mount_table.cpp
@@ -18,7 +18,7 @@ namespace kernel::filesystem
[&parent_mount](auto const & mount) { return mount->parent_mount() == parent_mount; });
}
- void mount_table::add_mount(kstd::shared_ptr<mount> const & mount)
+ auto mount_table::add_mount(kstd::shared_ptr<mount> const & mount) -> void
{
m_mounts.push_back(mount);
diff --git a/libs/kstd/kstd/flat_map b/libs/kstd/kstd/flat_map
index 943e9fc..e51eb91 100644
--- a/libs/kstd/kstd/flat_map
+++ b/libs/kstd/kstd/flat_map
@@ -19,12 +19,24 @@ namespace kstd
typename KeyContainerType = kstd::vector<KeyType>, typename MappedContainerType = kstd::vector<MappedType>>
struct flat_map
{
+ //! The type of container used to store the map keys.
using key_container_type = KeyContainerType;
+
+ //! The type of container used to store the map values.
using mapped_container_type = MappedContainerType;
+
+ //! The type of the map keys.
using key_type = KeyType;
+
+ //! The type of the mappe values.
using mapped_type = MappedType;
+
+ //! The type of a single key-value value in the map.
using value_type = std::pair<key_type, mapped_type>;
+
+ //! The comparator used to sort the keys.
using key_compare = KeyCompare;
+
using reference = std::pair<key_type const &, mapped_type &>;
using const_reference = std::pair<key_type const &, mapped_type const &>;
using size_type = std::size_t;
@@ -64,6 +76,19 @@ namespace kstd
, m_comparator{comparator}
{}
+ //! Replace the contents of this flat map with the one of a different one.
+ //!
+ //! @param other the flat map to copy from.
+ //! @return A reference to this flat map.
+ auto operator=(flat_map const & other) -> flat_map &
+ {
+ if (this != &other)
+ {
+ std::tie(m_containers, m_comparator) = std::tie(other.m_containers, other.m_comparator);
+ }
+ return *this;
+ }
+
//! Get a reference to the mapped value associated with the given key.
//!
//! @warning This function will panic if the key is not found.
diff --git a/libs/kstd/kstd/flat_map.test.cpp b/libs/kstd/kstd/flat_map.test.cpp
index 6c57173..9df03bb 100644
--- a/libs/kstd/kstd/flat_map.test.cpp
+++ b/libs/kstd/kstd/flat_map.test.cpp
@@ -62,6 +62,33 @@ SCENARIO("Flat Map modifiers", "[flat_map]")
REQUIRE(map.contains(1));
}
}
+
+ AND_GIVEN("a populated Flat Map")
+ {
+ auto other = kstd::flat_map<int, int>{};
+ other.emplace(1, 10);
+ other.emplace(2, 20);
+ other.emplace(3, 30);
+
+ WHEN("assigning the populated Flat Map to the empty one")
+ {
+ map = other;
+
+ THEN("the elements are copied")
+ {
+ REQUIRE(map.at(1) == 10);
+ REQUIRE(map.at(2) == 20);
+ REQUIRE(map.at(3) == 30);
+ }
+
+ THEN("the elements are still in the populated Flat Map")
+ {
+ REQUIRE(other.at(1) == 10);
+ REQUIRE(other.at(2) == 20);
+ REQUIRE(other.at(3) == 30);
+ }
+ }
+ }
}
}