FINAL CUT
pipedata.h
1 /***********************************************************************
2 * pipedata.h - Provides a pipe array to hold the file descriptors *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2023 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Standalone class
24  * ════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▔▏
27  * ▕ PipeData ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef PIPEDATA_H
32 #define PIPEDATA_H
33 
34 #include <array>
35 #include <type_traits>
36 
37 namespace finalcut
38 {
39 
40 // class forward declaration
41 class FString;
42 
43 //----------------------------------------------------------------------
44 // class PipeData
45 //----------------------------------------------------------------------
46 
47 class PipeData final
48 {
49  public:
50  // Constructor
51  PipeData() = default;
52 
53  explicit PipeData (int read_fd, int write_fd)
54  : pipe_fd{{read_fd, write_fd}}
55  { }
56 
57  // Accessors
58  auto getClassName() const -> FString;
59  auto getArrayData() const -> const int*;
60  auto getArrayData() -> int*;
61  auto getReadFd() const -> int;
62  auto getWriteFd() const -> int;
63 
64  private:
65  // Enumeration
66  enum class Array
67  {
68  Read = 0, // Read end of pipe
69  Write = 1, // Write end of pipe
70  Size = 2 // Size of pipe array
71  };
72 
73  // Using-declaration
74  using ArrayT = std::underlying_type_t<Array>;
75 
76  // Data member
77  std::array<int, static_cast<ArrayT>(Array::Size)> pipe_fd{};
78 };
79 
80 //----------------------------------------------------------------------
81 inline auto PipeData::getArrayData() const -> const int*
82 {
83  return pipe_fd.data();
84 }
85 
86 //----------------------------------------------------------------------
87 inline auto PipeData::getArrayData() -> int*
88 {
89  return pipe_fd.data();
90 }
91 
92 //----------------------------------------------------------------------
93 inline auto PipeData::getReadFd() const -> int
94 {
95  return pipe_fd[static_cast<ArrayT>(Array::Read)];
96 }
97 
98 //----------------------------------------------------------------------
99 inline auto PipeData::getWriteFd() const -> int
100 {
101  return pipe_fd[static_cast<ArrayT>(Array::Write)];
102 }
103 
104 } // namespace finalcut
105 
106 #endif // PIPEDATA_H
Definition: class_template.cpp:25
Definition: fstring.h:79
Definition: pipedata.h:47