comparison mupdf-source/thirdparty/tesseract/src/ccutil/tesserrstream.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // File: tesserrstream.h
2 // Description: C++ stream which enhances tprintf
3 // Author: Stefan Weil
4 //
5 // (C) Copyright 2024
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 #ifndef TESSERACT_CCUTIL_TESSERRSTREAM_H
17 #define TESSERACT_CCUTIL_TESSERRSTREAM_H
18
19 #include "tprintf.h"
20 #include <tesseract/export.h> // for TESS_API
21
22 #include <ostream> // for std::ostream
23
24 namespace tesseract {
25
26 class TessStreamBuf : public std::streambuf {
27 public:
28 TessStreamBuf() = default;
29
30 protected:
31 virtual int_type overflow(int_type c) override {
32 if (c != EOF) {
33 if (debugfp == nullptr) {
34 debugfp = get_debugfp();
35 }
36 if (fputc(c, debugfp) == EOF) {
37 return EOF;
38 }
39 }
40 return c;
41 }
42
43 virtual std::streamsize xsputn(const char* s, std::streamsize n) override {
44 if (debugfp == nullptr) {
45 debugfp = get_debugfp();
46 }
47 return fwrite(s, 1, n, debugfp);
48 }
49
50 private:
51 FILE *debugfp = nullptr;
52 };
53
54 class TessErrStream : public std::ostream {
55 private:
56 TessStreamBuf buf;
57
58 public:
59 TessErrStream() : std::ostream(nullptr), buf() {
60 rdbuf(&buf);
61 }
62 };
63
64 extern TESS_API TessErrStream tesserr;
65
66 } // namespace tesseract
67
68 #endif // TESSERACT_CCUTIL_TESSERRSTREAM_H