Panda3D
Loading...
Searching...
No Matches
pfstreamBuf.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file pfstreamBuf.h
10 * @author cary
11 * @date 2000-12-12
12 */
13
14#ifndef __PFSTREAMBUF_H__
15#define __PFSTREAMBUF_H__
16
17#include "dtoolbase.h"
18#include <string>
19#include <stdio.h>
20
21// By default, we'll use the Windows flavor of pipe functions if we're
22// compiling under Windows. Turn this off to use popen(), even on Windows.
23// (popen() doesn't seem to work on Win9x, although it does work on NT-based
24// variants.)
25#ifdef WIN32_VC
26#define WIN_PIPE_CALLS 1
27#endif
28
29#ifdef WIN_PIPE_CALLS
30#ifndef WIN32_LEAN_AND_MEAN
31#define WIN32_LEAN_AND_MEAN 1
32#endif
33#include <windows.h>
34
35#else // WIN_PIPE_CALLS
36
37#ifdef WIN32_VC
38#define popen _popen
39#define pclose _pclose
40#endif
41
42#endif // WIN_PIPE_CALLS
43
44class EXPCL_DTOOL_DTOOLUTIL PipeStreamBuf : public std::streambuf {
45public:
46 enum Direction { Input, Output };
47
48 PipeStreamBuf(Direction);
49 virtual ~PipeStreamBuf(void);
50
51 void flush();
52 void command(const std::string);
53
54protected:
55 virtual int overflow(int c);
56 virtual int sync(void);
57 virtual int underflow(void);
58private:
59 void init_pipe();
60 bool is_open() const;
61 bool eof_pipe() const;
62 bool open_pipe(const std::string &cmd);
63 void close_pipe();
64 size_t write_pipe(const char *data, size_t len);
65 size_t read_pipe(char *data, size_t len);
66
67 Direction _dir;
68 std::string _line_buffer;
69
70#ifndef WIN_PIPE_CALLS
71 FILE *_pipe;
72
73#else // WIN_PIPE_CALLS
74 HANDLE _child_out;
75#endif // WIN_PIPE_CALLS
76
77 void write_chars(const char*, int, bool);
78};
79
80#endif /* __PFSTREAMBUF_H__ */
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.