AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
Pipe.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <AUI/Traits/values.h>
15
16#if AUI_PLATFORM_WIN
17#include <Windows.h>
18#else
19#include <unistd.h>
20#include <sys/types.h>
21#include <sys/wait.h>
22#include <cassert>
23#include <spawn.h>
24#endif
25
26
30class Pipe: public aui::noncopyable {
31public:
32#if AUI_PLATFORM_WIN
33 using pipe_t = HANDLE;
34#else
35 using pipe_t = int;
36#endif
37
38 Pipe();
39 Pipe(Pipe&& rhs) noexcept {
40 operator=(std::move(rhs));
41 }
42 ~Pipe();
43
44 Pipe& operator=(Pipe&& rhs) noexcept {
45 mIn = rhs.mIn;
46 mOut = rhs.mOut;
47 rhs.mIn = rhs.mOut = static_cast<pipe_t>(0);
48 return *this;
49 }
50
51
55 [[nodiscard]]
56 pipe_t out() const noexcept {
57 return mOut;
58 }
59
63 [[nodiscard]]
64 pipe_t in() const noexcept {
65 return mIn;
66 }
67
68 void closeOut() noexcept;
69 void closeIn() noexcept;
70
76 [[nodiscard]]
77 pipe_t stealOut() noexcept {
78 auto copy = mOut;
79 mOut = 0;
80 return copy;
81 }
82
88 [[nodiscard]]
89 pipe_t stealIn() noexcept {
90 auto copy = mIn;
91 mIn = 0;
92 return copy;
93 }
94
95
96private:
100 pipe_t mOut;
101
105 pipe_t mIn;
106};
Unix pipe RAII wrapper.
Definition: Pipe.h:30
pipe_t stealIn() noexcept
Steals ownership of the in pipe outside of the Pipe class.
Definition: Pipe.h:89
pipe_t stealOut() noexcept
Steals ownership of the out pipe outside of the Pipe class.
Definition: Pipe.h:77
pipe_t in() const noexcept
In pipe. Also known as pipe[1].
Definition: Pipe.h:64
pipe_t out() const noexcept
Out pipe. Also known as pipe[0].
Definition: Pipe.h:56
Forbids copy of your class.
Definition: values.h:40