forked from nanocurrency/nano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move container info classes to separate file
- Loading branch information
1 parent
0377c4f
commit 1626fde
Showing
5 changed files
with
94 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters