IBR-DTNSuite  0.10
appstreambuf.h
Go to the documentation of this file.
1 /*
2  * appstreambuf.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef IBRCOMMON_APPSTREAMBUF_H_
23 #define IBRCOMMON_APPSTREAMBUF_H_
24 
25 #include <streambuf>
26 #include <vector>
27 #include <string>
28 #include <stdio.h>
29 
30 namespace ibrcommon
31 {
43  class appstreambuf : public std::basic_streambuf<char, std::char_traits<char> >
44  {
45  public:
46  enum { BUF_SIZE = 512 };
47 
48  enum Mode
49  {
50  MODE_READ = 0,
52  };
53 
59  appstreambuf(std::string command, appstreambuf::Mode mode);
60  virtual ~appstreambuf();
61 
62  protected:
63  virtual std::char_traits<char>::int_type underflow();
64  virtual int sync();
65  virtual std::char_traits<char>::int_type overflow( std::char_traits<char>::int_type m = traits_type::eof() );
66 
67  private:
68  std::vector< char_type > m_buf;
69  FILE *_handle;
70  };
71 }
72 
73 #endif /* APPSTREAMBUF_H_ */