Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Improve code style by putting private after public #17

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/spider/core/Data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,8 @@
#include <string>
#include <utility>

namespace spider::core {
class Data {
private:
boost::uuids::uuid m_id;
std::optional<std::string> m_key;
std::string m_value;

void init_id() {
boost::uuids::random_generator gen;
m_id = gen();
}

public:
explicit Data(std::string value) : m_value(std::move(value)) { init_id(); }

Expand All @@ -30,6 +21,17 @@ class Data {
[[nodiscard]] auto get_key() const -> std::optional<std::string> { return m_key; }

[[nodiscard]] auto get_value() const -> std::string { return m_value; }

private:
boost::uuids::uuid m_id;
std::optional<std::string> m_key;
std::string m_value;

void init_id() {
boost::uuids::random_generator gen;
m_id = gen();
}
};
} // namespace spider::core

#endif // SPIDER_CORE_DATA_HPP
37 changes: 18 additions & 19 deletions src/spider/core/Task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@
#include <vector>

namespace spider::core {

class TaskInput {
private:
std::optional<std::tuple<boost::uuids::uuid, std::uint8_t>> m_task_output;
std::optional<std::string> m_value;
std::optional<boost::uuids::uuid> m_data_id;
std::string m_type;

public:
TaskInput(boost::uuids::uuid output_task_id, std::uint8_t position, std::string type)
: m_task_output({output_task_id, position}),
Expand All @@ -43,14 +36,15 @@ class TaskInput {
}

[[nodiscard]] auto get_type() const -> std::string { return m_type; }
};

class TaskOutput {
private:
std::optional<std::tuple<boost::uuids::uuid, std::uint8_t>> m_task_output;
std::optional<std::string> m_value;
std::optional<boost::uuids::uuid> m_data_id;
std::string m_type;
};

class TaskOutput {
public:
TaskOutput(std::string value, std::string type)
: m_value(std::move(value)),
Expand All @@ -67,6 +61,11 @@ class TaskOutput {
}

[[nodiscard]] auto get_type() const -> std::string { return m_type; }

private:
std::optional<std::string> m_value;
std::optional<boost::uuids::uuid> m_data_id;
std::string m_type;
};

class TaskInstance {};
Expand All @@ -86,16 +85,6 @@ enum class TaskCreatorType : std::uint8_t {
};

class Task {
private:
boost::uuids::uuid m_id;
std::string m_function_name;
TaskState m_state = TaskState::Pending;
TaskCreatorType m_creator_type;
boost::uuids::uuid m_creator_id;
float m_timeout = 0;
std::vector<TaskInput> m_inputs;
std::vector<TaskOutput> m_outputs;

public:
Task(std::string function_name, TaskCreatorType creator_type, boost::uuids::uuid creator_id)
: m_function_name(std::move(function_name)),
Expand Down Expand Up @@ -128,6 +117,16 @@ class Task {
[[nodiscard]] auto get_input(uint64_t index) const -> TaskInput { return m_inputs[index]; }

[[nodiscard]] auto get_output(uint64_t index) const -> TaskOutput { return m_outputs[index]; }

private:
boost::uuids::uuid m_id;
std::string m_function_name;
TaskState m_state = TaskState::Pending;
TaskCreatorType m_creator_type;
boost::uuids::uuid m_creator_id;
float m_timeout = 0;
std::vector<TaskInput> m_inputs;
std::vector<TaskOutput> m_outputs;
};

} // namespace spider::core
Expand Down
9 changes: 4 additions & 5 deletions src/spider/core/TaskGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
#include "Task.hpp"

namespace spider::core {

class TaskGraph {
private:
absl::flat_hash_map<boost::uuids::uuid, Task> m_tasks;
std::vector<std::pair<boost::uuids::uuid, boost::uuids::uuid>> m_dependencies;

public:
auto add_child_task(Task const& task, std::vector<boost::uuids::uuid> const& parents) -> bool {
boost::uuids::uuid const task_id = task.get_id();
Expand Down Expand Up @@ -73,6 +68,10 @@ class TaskGraph {
) const -> std::vector<std::pair<boost::uuids::uuid, boost::uuids::uuid>> const& {
return m_dependencies;
}

private:
absl::flat_hash_map<boost::uuids::uuid, Task> m_tasks;
std::vector<std::pair<boost::uuids::uuid, boost::uuids::uuid>> m_dependencies;
};
} // namespace spider::core

Expand Down
Loading