libDwm-0.9.45
DwmFileIOCapable.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//---------------------------------------------------------------------------
41//---------------------------------------------------------------------------
42
43#ifndef _DWMFILEIOCAPABLE_HH_
44#define _DWMFILEIOCAPABLE_HH_
45
46#include <cstdio>
47
48namespace Dwm {
49
50 //--------------------------------------------------------------------------
53 //--------------------------------------------------------------------------
54 template <typename T>
55 concept HasFileRead = requires(T & t, FILE *f) {
56 { t.Read(f) } -> std::same_as<size_t>;
57 };
58
59 //--------------------------------------------------------------------------
62 //--------------------------------------------------------------------------
63 template <typename T>
64 concept HasFileWrite = requires(const T & t, FILE *f) {
65 { t.Write(f) } -> std::same_as<size_t>;
66 };
67
68 //--------------------------------------------------------------------------
71 //--------------------------------------------------------------------------
73 {
74 public:
75 //------------------------------------------------------------------------
77 //------------------------------------------------------------------------
78 virtual ~FileReadable() { }
79
80 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 virtual size_t Read(FILE * f) = 0;
85 };
86
87 //--------------------------------------------------------------------------
90 //--------------------------------------------------------------------------
92 {
93 public:
94 //------------------------------------------------------------------------
96 //------------------------------------------------------------------------
97 virtual ~FileWritable() { }
98
99 //------------------------------------------------------------------------
102 //------------------------------------------------------------------------
103 virtual size_t Write(FILE *f) const = 0;
104 };
105
106 //--------------------------------------------------------------------------
108 //--------------------------------------------------------------------------
109 class FileIOCapable : public FileReadable, public FileWritable { };
110
111} // namespace Dwm
112
113#endif // _DWMFILEIOCAPABLE_HH_
114
115
116//---------------------------- emacs settings -----------------------------
117// Local Variables:
118// mode: C++
119// tab-width: 2
120// indent-tabs-mode: nil
121// c-basic-offset: 2
122// End:
123//-------------------------------------------------------------------------
This class defines an interface for classes that can read their contents from a FILE pointer.
Definition DwmFileIOCapable.hh:73
virtual size_t Read(FILE *f)=0
Read from a FILE pointer.
virtual ~FileReadable()
destructor
Definition DwmFileIOCapable.hh:78
This class defines an interface for classes that can write their contents to a FILE pointer.
Definition DwmFileIOCapable.hh:92
virtual size_t Write(FILE *f) const =0
Write to a FILE pointer.
virtual ~FileWritable()
Destructor.
Definition DwmFileIOCapable.hh:97
T has a Read(FILE *) member that returns size_t (1 on success, 0 on failure).
Definition DwmFileIOCapable.hh:55
T has a Write(FILE *) const member that returns size_t (1 on success, 0 on failure).
Definition DwmFileIOCapable.hh:64