libUTL++
BufferedFDstream.h
1 #pragma once
2 
4 
5 #include <libutl/BufferedStream.h>
6 #include <libutl/FDstream.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
23 
26 {
29 
30 public:
31  BufferedFDstream(FDstream* fdStream)
32  {
33  setStream(fdStream);
34  }
35 
36  BufferedFDstream(int fd, uint_t mode)
37  {
38  setStream(new FDstream(fd, mode));
39  }
40 
41  int
42  fd() const
43  {
44  return pget()->fd();
45  }
46 
47  void
48  setFD(int fd, uint_t mode)
49  {
50  pget()->setFD(fd, mode);
51  }
52 
53 #if UTL_HOST_OS != UTL_OS_MINGW
54  bool
55  isSocket() const
56  {
57  return pget()->isSocket();
58  }
59 #endif
60 
61  bool
62  isTTY() const
63  {
64  return pget()->isTTY();
65  }
66 
67 #if UTL_HOST_OS != UTL_OS_MINGW
68  bool blockRead(uint32_t usec = 0);
69 #endif
70 private:
71  const FDstream*
72  pget() const
73  {
74  ASSERTD(_stream != nullptr);
75  return utl::cast<FDstream>(_stream);
76  }
77  FDstream*
78  pget()
79  {
80  ASSERTD(_stream != nullptr);
81  return utl::cast<FDstream>(_stream);
82  }
83 };
84 
86 
91 extern BufferedFDstream cin;
92 
97 extern BufferedFDstream cout;
98 
103 extern BufferedFDstream cerr;
104 
106 
107 UTL_NS_END;
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
BufferedFDstream cout
Standard output.
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
BufferedFDstream cin
Standard input.
unsigned int uint32_t
Unsigned 32-bit integer.
Definition: types.h:115
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
BufferedFDstream cerr
Standard error.
Stream with file descriptor.
Definition: FDstream.h:35
Buffered stream.
#define ASSERTD
Do an assertion in DEBUG mode only.
Buffered stream with file descriptor.