Skip to content

Commit

Permalink
Move container info classes to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 3, 2023
1 parent 0377c4f commit 1626fde
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 83 deletions.
2 changes: 2 additions & 0 deletions nano/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ add_library(
config.hpp
config.cpp
configbase.hpp
container_info.hpp
container_info.cpp
diagnosticsconfig.hpp
diagnosticsconfig.cpp
epoch.hpp
Expand Down
41 changes: 41 additions & 0 deletions nano/lib/container_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <nano/lib/container_info.hpp>

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<container_info_component> child)
{
children.push_back (std::move (child));
}

std::vector<std::unique_ptr<nano::container_info_component>> 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;
}
50 changes: 50 additions & 0 deletions nano/lib/container_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include <string>
#include <vector>

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<container_info_component> child);
std::vector<std::unique_ptr<container_info_component>> const & get_children () const;
std::string const & get_name () const;

private:
std::string name;
std::vector<std::unique_ptr<container_info_component>> 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;
};
}
40 changes: 0 additions & 40 deletions nano/lib/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<container_info_component> child)
{
children.push_back (std::move (child));
}

std::vector<std::unique_ptr<nano::container_info_component>> 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))
Expand Down
44 changes: 1 addition & 43 deletions nano/lib/utility.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <nano/lib/container_info.hpp>
#include <nano/lib/locks.hpp>

#include <boost/current_function.hpp>
Expand Down Expand Up @@ -61,49 +62,6 @@ namespace nano
template <typename Index, typename Value>
using enum_array = magic_enum::containers::array<Index, Value>;

/* 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<container_info_component> child);
std::vector<std::unique_ptr<container_info_component>> const & get_children () const;
std::string const & get_name () const;

private:
std::string name;
std::vector<std::unique_ptr<container_info_component>> 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 ();

Expand Down

0 comments on commit 1626fde

Please sign in to comment.