aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/common')
-rw-r--r--include/cru/common/Event.h1
-rw-r--r--include/cru/common/Format.h2
-rw-r--r--include/cru/common/Range.h21
-rw-r--r--include/cru/common/SelfResolvable.h1
-rw-r--r--include/cru/common/SubProcess.h54
5 files changed, 65 insertions, 14 deletions
diff --git a/include/cru/common/Event.h b/include/cru/common/Event.h
index 564afc40..14d68833 100644
--- a/include/cru/common/Event.h
+++ b/include/cru/common/Event.h
@@ -5,7 +5,6 @@
#include <algorithm>
#include <functional>
-#include <initializer_list>
#include <memory>
#include <utility>
#include <vector>
diff --git a/include/cru/common/Format.h b/include/cru/common/Format.h
index a15e7ce7..e6935343 100644
--- a/include/cru/common/Format.h
+++ b/include/cru/common/Format.h
@@ -1,9 +1,9 @@
#pragma once
-#include <double-conversion/double-conversion.h>
#include "Exception.h"
#include "String.h"
+#include <double-conversion/double-conversion.h>
#include <charconv>
namespace cru {
diff --git a/include/cru/common/Range.h b/include/cru/common/Range.h
index e61d90ca..edc2ec55 100644
--- a/include/cru/common/Range.h
+++ b/include/cru/common/Range.h
@@ -3,23 +3,22 @@
namespace cru {
struct Range final {
- constexpr static Range FromTwoSides(gsl::index start, gsl::index end) {
+ constexpr static Range FromTwoSides(Index start, Index end) {
return Range(start, end - start);
}
- constexpr static Range FromTwoSides(gsl::index start, gsl::index end,
- gsl::index offset) {
+ constexpr static Range FromTwoSides(Index start, Index end, Index offset) {
return Range(start + offset, end - start);
}
constexpr Range() = default;
- constexpr Range(const gsl::index position, const gsl::index count = 0)
+ constexpr Range(const Index position, const Index count = 0)
: position(position), count(count) {}
- gsl::index GetStart() const { return position; }
- gsl::index GetEnd() const { return position + count; }
+ Index GetStart() const { return position; }
+ Index GetEnd() const { return position + count; }
- void ChangeEnd(gsl::index new_end) { count = new_end - position; }
+ void ChangeEnd(Index new_end) { count = new_end - position; }
Range Normalize() const {
auto result = *this;
@@ -30,14 +29,14 @@ struct Range final {
return result;
}
- Range CoerceInto(gsl::index min, gsl::index max) const {
- auto coerce = [min, max](gsl::index index) {
+ Range CoerceInto(Index min, Index max) const {
+ auto coerce = [min, max](Index index) {
return index > max ? max : (index < min ? min : index);
};
return Range::FromTwoSides(coerce(GetStart()), coerce(GetEnd()));
}
- gsl::index position = 0;
- gsl::index count = 0;
+ Index position = 0;
+ Index count = 0;
};
} // namespace cru
diff --git a/include/cru/common/SelfResolvable.h b/include/cru/common/SelfResolvable.h
index c8acd4b9..0cbb35fb 100644
--- a/include/cru/common/SelfResolvable.h
+++ b/include/cru/common/SelfResolvable.h
@@ -2,7 +2,6 @@
#include "PreConfig.h"
#include <memory>
-#include <type_traits>
namespace cru {
template <typename T>
diff --git a/include/cru/common/SubProcess.h b/include/cru/common/SubProcess.h
new file mode 100644
index 00000000..341afc5c
--- /dev/null
+++ b/include/cru/common/SubProcess.h
@@ -0,0 +1,54 @@
+#pragma once
+#include "Base.h"
+#include "String.h"
+
+#include <chrono>
+#include <optional>
+#include <vector>
+
+namespace cru {
+enum class PlatformSubProcessStatus {
+ /**
+ * @brief The process has not been created and started.
+ */
+ Prepare,
+ /**
+ * @brief The process is running now.
+ */
+ Running,
+ /**
+ * @brief The process has been exited.
+ */
+ Exited,
+};
+
+/**
+ * Interface of a platform process. It is one-time, which means it starts and
+ * exits and can't start again.
+ */
+struct IPlatformSubProcess : virtual Interface {
+ /**
+ * Create and start a real process.
+ */
+ void Start(String program, std::vector<String> arguments,
+ std::vector<String> environments);
+ void Wait(std::optional<std::chrono::milliseconds> wait_time);
+ void Reap();
+ PlatformSubProcessStatus GetStatus() const;
+ int GetExitCode() const;
+};
+
+class CRU_BASE_API SubProcess : public Object {
+ public:
+ SubProcess();
+
+ CRU_DELETE_COPY(SubProcess)
+
+ SubProcess(SubProcess&& other);
+ SubProcess& operator=(SubProcess&& other);
+
+ ~SubProcess();
+
+ private:
+};
+} // namespace cru