0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FixedStream.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
26 #ifndef HYPERTABLE_FIXED_STREAM_H
27 #define HYPERTABLE_FIXED_STREAM_H
28 
29 #include "String.h"
30 #include <streambuf>
31 #include <istream>
32 #include <ostream>
33 
34 namespace Hypertable {
35 
45 class FixedStreamBuf : public std::streambuf {
46 public:
56  FixedStreamBuf(char *buf, size_t len) { setp(buf, buf + len); }
57 
63  FixedStreamBuf(const char *buf, const char *next, const char *end) {
64  setg((char *)buf, (char *)next, (char *)end);
65  }
66 
68  String str() { return String(pbase(), pptr()); }
69 };
70 
74 class FixedOstream : private virtual FixedStreamBuf, public std::ostream {
75 public:
77 
84  FixedOstream(char *buf, size_t len)
85  : FixedStreamBuf(buf, len), std::ostream(static_cast<StreamBuf *>(this)) {
86  }
87 
89  char *output() { return StreamBuf::pbase(); }
90 
92  char *output_ptr() { return StreamBuf::pptr(); }
93 
95  char *output_end() { return StreamBuf::epptr(); }
96 
98  String str() { return StreamBuf::str(); }
99 };
100 
104 class FixedIstream : private virtual FixedStreamBuf, public std::istream {
105 public:
107 
114  FixedIstream(const char *buf, const char *end)
115  : FixedStreamBuf(buf, buf, end),
116  std::istream(static_cast<StreamBuf *>(this)) {
117  }
118 
120  char *input() { return StreamBuf::eback(); }
121 
123  char *input_ptr() { return StreamBuf::gptr(); }
124 
126  char *input_end() { return StreamBuf::egptr(); }
127 };
128 
131 } // namespace Hypertable
132 
133 #endif // HYPERTABLE_FIXED_STREAM_H
A simple streambuf with fixed size buffer.
Definition: FixedStream.h:45
FixedStreamBuf(const char *buf, const char *next, const char *end)
Constructor.
Definition: FixedStream.h:63
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
STL namespace.
FixedStreamBuf StreamBuf
Definition: FixedStream.h:106
FixedOstream(char *buf, size_t len)
Constructs the stream from an existing buffer; all streamed objects are stored in that buffer...
Definition: FixedStream.h:84
char * output()
Returns a pointer to the output buffer.
Definition: FixedStream.h:89
Output stream using a fixed buffer.
Definition: FixedStream.h:74
char * output_ptr()
Returns a pointer to the current position in the output buffer.
Definition: FixedStream.h:92
String str()
Returns a String object from the output buffer.
Definition: FixedStream.h:98
String str()
Returns a String object from the output buffer.
Definition: FixedStream.h:68
char * input()
Returns a pointer to the beginning of the input buffer.
Definition: FixedStream.h:120
FixedStreamBuf StreamBuf
Definition: FixedStream.h:76
Hypertable definitions
FixedIstream(const char *buf, const char *end)
Constructs the input stream from an existing buffer; all streamed objects are read from that buffer...
Definition: FixedStream.h:114
char * input_ptr()
Returns a pointer to the current position in the input buffer.
Definition: FixedStream.h:123
Input stream using a fixed buffer.
Definition: FixedStream.h:104
A String class based on std::string.
char * output_end()
Returns a pointer to the end of the output buffer.
Definition: FixedStream.h:95
FixedStreamBuf(char *buf, size_t len)
Constructor.
Definition: FixedStream.h:56
char * input_end()
Returns a pointer to the end of the input buffer.
Definition: FixedStream.h:126