IBR-DTNSuite  0.10
iobuffer.h
Go to the documentation of this file.
1 /*
2  * iobuffer.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 IOBUFFER_H_
23 #define IOBUFFER_H_
24 
25 #include "ibrcommon/Exceptions.h"
26 #include <streambuf>
28 #include <vector>
29 
30 namespace ibrcommon
31 {
36  class iobuffer : public std::basic_streambuf<char, std::char_traits<char> >
37  {
38  public:
39  iobuffer(const size_t buffer = 2048);
40  virtual ~iobuffer();
41 
45  void finalize();
46 
47  protected:
48  virtual int sync();
49  virtual std::char_traits<char>::int_type overflow(std::char_traits<char>::int_type = std::char_traits<char>::eof());
50  virtual std::char_traits<char>::int_type underflow();
51 
52  private:
53  ibrcommon::Conditional _data_cond;
54 
55  bool _eof;
56 
57  size_t _data_size;
58 
59  // length of the data buffer
60  size_t _buf_size;
61 
62  // input buffer
63  std::vector<char> _input_buf;
64 
65  // interim buffer
66  std::vector<char> _interim_buf;
67 
68  // output buffer
69  std::vector<char> _output_buf;
70  };
71 }
72 
73 #endif /* IOBUFFER_H_ */