cprover
pipe_stream.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: A stdin/stdout pipe as STL stream
4 
5 Author:
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_UTIL_PIPE_STREAM_H
13 #define CPROVER_UTIL_PIPE_STREAM_H
14 
15 #include <iostream>
16 #include <string>
17 #include <list>
18 
19 #ifdef _WIN32
20 #include <windows.h>
21 #else
22 #include <unistd.h>
23 #include <sys/types.h>
24 #endif
25 
26 // a class much like __gnu_cxx::stdio_filebuf
27 
28 class filedescriptor_streambuft:public std::streambuf
29 {
30 public:
31  #ifndef _WIN32
32  // NOLINTNEXTLINE(readability/identifiers)
33  typedef int HANDLE;
34  #endif
35 
37 
38  // these are closed automatically on destruction
39  void set_in(HANDLE in) { proc_in=in; }
40  void set_out(HANDLE out) { proc_out=out; }
41 
43 
44 protected:
46  char *in_buffer;
47 
48  int_type overflow(int_type);
49  std::streamsize xsputn(const char *, std::streamsize);
50  int_type underflow();
51  std::streamsize xsgetn(char *, std::streamsize);
52  std::streamsize showmanyc();
53 };
54 
55 class pipe_streamt:public std::iostream
56 {
57 public:
59  const std::string &_executable,
60  const std::list<std::string> &_args);
61 
62  int run();
63  int wait();
64 
65 protected:
66  std::string executable;
67  std::list<std::string> args;
68 
69  #ifdef _WIN32
70  PROCESS_INFORMATION pi;
71  #else
72  pid_t pid;
73  #endif
74 
76 };
77 
78 #endif // CPROVER_UTIL_PIPE_STREAM_H
pipe_streamt(const std::string &_executable, const std::list< std::string > &_args)
Constructor for external process.
Definition: pipe_stream.cpp:34
int wait()
Wait for the process to terminate.
int_type overflow(int_type)
write one character to the piped process
int_type underflow()
read a character from the piped process
std::list< std::string > args
Definition: pipe_stream.h:67
std::streamsize xsputn(const char *, std::streamsize)
write a number of character to the piped process
std::streamsize xsgetn(char *, std::streamsize)
read a number of characters from the piped process
filedescriptor_streambuft buffer
Definition: pipe_stream.h:75
filedescriptor_streambuft()
Constructor.
~filedescriptor_streambuft()
Destructor.
std::string executable
Definition: pipe_stream.h:66
void set_in(HANDLE in)
Definition: pipe_stream.h:39
std::streamsize showmanyc()
determine number of available characters in stream
int run()
Starts an external process.
void set_out(HANDLE out)
Definition: pipe_stream.h:40