From 1626fde0d0b75f65d36869855eb65b7fc69831de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 3 Nov 2023 22:51:41 +0100 Subject: [PATCH] Move container info classes to separate file --- nano/lib/CMakeLists.txt | 2 ++ nano/lib/container_info.cpp | 41 ++++++++++++++++++++++++++++++ nano/lib/container_info.hpp | 50 +++++++++++++++++++++++++++++++++++++ nano/lib/utility.cpp | 40 ----------------------------- nano/lib/utility.hpp | 44 +------------------------------- 5 files changed, 94 insertions(+), 83 deletions(-) create mode 100644 nano/lib/container_info.cpp create mode 100644 nano/lib/container_info.hpp diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 934cd1452a..71d10a90c5 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -31,6 +31,8 @@ add_library( config.hpp config.cpp configbase.hpp + container_info.hpp + container_info.cpp diagnosticsconfig.hpp diagnosticsconfig.cpp epoch.hpp diff --git a/nano/lib/container_info.cpp b/nano/lib/container_info.cpp new file mode 100644 index 0000000000..1302b3503a --- /dev/null +++ b/nano/lib/container_info.cpp @@ -0,0 +1,41 @@ +#include + +nano::container_info_composite::container_info_composite (std::string const & name) : + name (name) +{ +} + +bool nano::container_info_composite::is_composite () const +{ + return true; +} + +void nano::container_info_composite::add_component (std::unique_ptr child) +{ + children.push_back (std::move (child)); +} + +std::vector> const & nano::container_info_composite::get_children () const +{ + return children; +} + +std::string const & nano::container_info_composite::get_name () const +{ + return name; +} + +nano::container_info_leaf::container_info_leaf (const container_info & info) : + info (info) +{ +} + +bool nano::container_info_leaf::is_composite () const +{ + return false; +} + +nano::container_info const & nano::container_info_leaf::get_info () const +{ + return info; +} \ No newline at end of file diff --git a/nano/lib/container_info.hpp b/nano/lib/container_info.hpp new file mode 100644 index 0000000000..d2974f36a6 --- /dev/null +++ b/nano/lib/container_info.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include + +namespace nano +{ +/* These containers are used to collect information about sequence containers. + * It makes use of the composite design pattern to collect information + * from sequence containers and sequence containers inside member variables. + */ +struct container_info +{ + std::string name; + size_t count; + size_t sizeof_element; +}; + +class container_info_component +{ +public: + virtual ~container_info_component () = default; + virtual bool is_composite () const = 0; +}; + +class container_info_composite : public container_info_component +{ +public: + container_info_composite (std::string const & name); + bool is_composite () const override; + void add_component (std::unique_ptr child); + std::vector> const & get_children () const; + std::string const & get_name () const; + +private: + std::string name; + std::vector> children; +}; + +class container_info_leaf : public container_info_component +{ +public: + container_info_leaf (container_info const & info); + bool is_composite () const override; + container_info const & get_info () const; + +private: + container_info info; +}; +} \ No newline at end of file diff --git a/nano/lib/utility.cpp b/nano/lib/utility.cpp index 869828bd04..7034a865f3 100644 --- a/nano/lib/utility.cpp +++ b/nano/lib/utility.cpp @@ -53,46 +53,6 @@ void nano::set_file_descriptor_limit (std::size_t limit) #endif } -nano::container_info_composite::container_info_composite (std::string const & name) : - name (name) -{ -} - -bool nano::container_info_composite::is_composite () const -{ - return true; -} - -void nano::container_info_composite::add_component (std::unique_ptr child) -{ - children.push_back (std::move (child)); -} - -std::vector> const & nano::container_info_composite::get_children () const -{ - return children; -} - -std::string const & nano::container_info_composite::get_name () const -{ - return name; -} - -nano::container_info_leaf::container_info_leaf (const container_info & info) : - info (info) -{ -} - -bool nano::container_info_leaf::is_composite () const -{ - return false; -} - -nano::container_info const & nano::container_info_leaf::get_info () const -{ - return info; -} - void nano::remove_all_files_in_dir (std::filesystem::path const & dir) { for (auto & p : std::filesystem::directory_iterator (dir)) diff --git a/nano/lib/utility.hpp b/nano/lib/utility.hpp index 7155ca4760..fe47c0aab8 100644 --- a/nano/lib/utility.hpp +++ b/nano/lib/utility.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -61,49 +62,6 @@ namespace nano template using enum_array = magic_enum::containers::array; -/* These containers are used to collect information about sequence containers. - * It makes use of the composite design pattern to collect information - * from sequence containers and sequence containers inside member variables. - */ -struct container_info -{ - std::string name; - size_t count; - size_t sizeof_element; -}; - -class container_info_component -{ -public: - virtual ~container_info_component () = default; - virtual bool is_composite () const = 0; -}; - -class container_info_composite : public container_info_component -{ -public: - container_info_composite (std::string const & name); - bool is_composite () const override; - void add_component (std::unique_ptr child); - std::vector> const & get_children () const; - std::string const & get_name () const; - -private: - std::string name; - std::vector> children; -}; - -class container_info_leaf : public container_info_component -{ -public: - container_info_leaf (container_info const & info); - bool is_composite () const override; - container_info const & get_info () const; - -private: - container_info info; -}; - // Lower priority of calling work generating thread void work_thread_reprioritize ();