libDwm-0.9.45
DwmStreamIOCapable.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2020, 2024
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
42//---------------------------------------------------------------------------
43
44#ifndef _DWMSTREAMIOCAPABLE_HH_
45#define _DWMSTREAMIOCAPABLE_HH_
46
47#include <iostream>
48
49namespace Dwm {
50
51 //--------------------------------------------------------------------------
54 //--------------------------------------------------------------------------
55 template <typename T>
56 concept HasStreamRead = requires(T & t, std::istream & is) {
57 { t.Read(is) } -> std::same_as<std::istream &>;
58 };
59
60 //--------------------------------------------------------------------------
63 //--------------------------------------------------------------------------
64 template <typename T>
65 concept HasStreamWrite = requires(const T & t, std::ostream & os) {
66 { t.Write(os) } -> std::same_as<std::ostream &>;
67 };
68
69 //--------------------------------------------------------------------------
72 //--------------------------------------------------------------------------
74 {
75 public:
76 //------------------------------------------------------------------------
78 //------------------------------------------------------------------------
79 virtual ~StreamReadable() { }
80
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 virtual std::istream & Read(std::istream & is) = 0;
85 };
86
87 //--------------------------------------------------------------------------
90 //--------------------------------------------------------------------------
92 {
93 public:
94 //------------------------------------------------------------------------
96 //------------------------------------------------------------------------
97 virtual ~StreamWritable() { }
98
99 //------------------------------------------------------------------------
101 //------------------------------------------------------------------------
102 virtual std::ostream & Write(std::ostream & os) const = 0;
103 };
104
105 //--------------------------------------------------------------------------
107 //--------------------------------------------------------------------------
109 : public StreamReadable, public StreamWritable
110 {};
111
112} // namespace Dwm
113
114#endif // _DWMSTREAMIOCAPABLE_HH_
115
116
117//---------------------------- emacs settings -----------------------------
118// Local Variables:
119// mode: C++
120// tab-width: 2
121// indent-tabs-mode: nil
122// c-basic-offset: 2
123// End:
124//-------------------------------------------------------------------------
Interface for classes with iostream read and write capabilities.
Definition DwmStreamIOCapable.hh:110
This class defines an interface for classes that can read their contents from an istream.
Definition DwmStreamIOCapable.hh:74
virtual ~StreamReadable()
destructor
Definition DwmStreamIOCapable.hh:79
virtual std::istream & Read(std::istream &is)=0
Read from an istream. Return the istream.
This class defines an interface for classes that can write their contents to an ostream.
Definition DwmStreamIOCapable.hh:92
virtual ~StreamWritable()
Destructor.
Definition DwmStreamIOCapable.hh:97
virtual std::ostream & Write(std::ostream &os) const =0
Write to an ostream. Return the ostream.
T has a Read(std::istream &) method that returns the std::istream reference that was passed in as its...
Definition DwmStreamIOCapable.hh:56
T has a Write(std::ostream &) const method that returns the std::ostream reference that was passed in...
Definition DwmStreamIOCapable.hh:65