FINAL CUT
fstringstream.h
1 /***********************************************************************
2 * fstringstream.h - I/O operations on FString based streams *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2020-2022 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 /* Inheritance diagram
24  * ═══════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
27  * ▕ std::wiostream ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
29  * ▲
30  * │
31  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
32  * ▕ FStringStream ▏
33  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
34  */
35 
36 #ifndef FSTRINGSTREAM_H
37 #define FSTRINGSTREAM_H
38 
39 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
40  #error "Only <final/final.h> can be included directly."
41 #endif
42 
43 #include <iostream>
44 #include <istream>
45 #include <sstream>
46 
47 #include "final/util/fstring.h"
48 
49 namespace finalcut
50 {
51 
52 //----------------------------------------------------------------------
53 // class FStringStream
54 //----------------------------------------------------------------------
55 
56 class FStringStream : public std::wiostream
57 {
58  public:
59  using std::ios_base::openmode;
60  static constexpr openmode in_out = std::ios_base::out
61  | std::ios_base::in;
62 
63  // Constructors
64  explicit FStringStream (openmode = in_out);
65  explicit FStringStream (const FString&, openmode = in_out);
66 
67  // Disable copy constructor
68  FStringStream (const FStringStream&) = delete;
69 
70  // Move constructor
71  FStringStream (FStringStream&&) noexcept;
72 
73  // Destructor
74  ~FStringStream() noexcept override;
75 
76  // Disable copy assignment operator (=)
77  auto operator = (const FStringStream&) -> FStringStream& = delete;
78 
79  // Move assignment operator (=)
80  auto operator = (FStringStream&&) noexcept -> FStringStream&;
81 
82  virtual auto getClassName() const -> FString;
83  void swap (FStringStream&) noexcept;
84  void clear();
85  auto rdbuf() -> std::wstringbuf*;
86  auto str() const -> FString;
87 
88  private:
89  std::wstringbuf buffer{in_out};
90 };
91 
92 
93 // FStringStream inline functions
94 //----------------------------------------------------------------------
95 inline auto FStringStream::getClassName() const -> FString
96 { return "FStringStream"; }
97 
98 //----------------------------------------------------------------------
99 inline void FStringStream::clear()
100 { buffer.str(L""); }
101 
102 //----------------------------------------------------------------------
103 inline auto FStringStream::rdbuf() -> std::wstringbuf*
104 { return &buffer; }
105 
106 //----------------------------------------------------------------------
107 inline auto FStringStream::str() const -> FString
108 { return FString{buffer.str()}; }
109 
110 
111 // FStringStream non-member function
112 //----------------------------------------------------------------------
113 inline void swap (FStringStream& a, FStringStream& b) noexcept
114 { a.swap(b); }
115 
116 
117 } // namespace finalcut
118 
119 #endif // FSTRINGSTREAM_H
Definition: class_template.cpp:25
Definition: fstring.h:79
Definition: fstringstream.h:56