blob: 6081f1f23df5e90a31305eeaa6cc0d065735fdfc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/**
** \file task/task.hh
** \brief Declare the task::Task class.
*/
#pragma once
#include <string>
#include <vector>
#include <task/task-register.hh>
namespace task
{
/** \brief A function bound to a command line option.
The purpose of the Task class is to abstract the execution of a module
and the tasks on which its execution depends. This is an implementation
of the Command Design Pattern.
*/
class Task
{
/** \name Ctor & dtor. */
/** \{ */
public:
/** \brief Construct a Task.
\param name name of this task (used for long option)
\param module_name name of the module to which the task belongs.
\param desc description of this task
\param deps optional space separated list of task names
*/
Task(const char* name,
const char* module_name,
const char* desc,
const std::string& deps = "");
/// Destroy this Task.
virtual ~Task() = default;
/** \}*/
/** \name Abstract methods.
** \{ */
public:
/// Execute this task.
virtual void execute() const = 0;
/** \} */
using tasks_list_type = TaskRegister::tasks_list_type;
using deps_type = std::vector<std::string>;
virtual deps_type resolve_dependencies(tasks_list_type& active_tasks) const;
/** \name Accessors.
** \{ */
public:
/** Access to 'name'.
'const char*' is preferred to 'std::string' because TaskRegister
calls function requiring 'const char*'.
The use of 'std::string::c_str()' is so forbidden and a call to
'strdup(std::string::c_str())' would imply dummy memory leaks. */
const char* name_get() const;
/// Access to 'module_name'.
const char* module_name_get() const;
/// Access to 'fullname'.
const char* fullname_get() const;
/// Access to 'desc'.
const char* desc_get() const;
/// Access to tasks dependencies.
const deps_type& dependencies_get() const;
/** \} */
public:
/// Display dependencies of this task .
void print_dependencies() const;
public:
/// Normalize the name of a task.
static std::string normalize(const std::string& task_name);
protected:
/// Task name.
std::string name_;
/// Task name plus short name.
std::string fullname_;
/// Module name to which the task belongs.
const char* module_name_;
/// A short description of this task (displayed in program usage).
const char* desc_;
/// Contains the name of the tasks on which this one depends.
deps_type dependencies_;
};
} // namespace task
#include <task/task.hxx>
|