| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // A ZeroCopyInputStream which reads from a C++ istream. | 211 // A ZeroCopyInputStream which reads from a C++ istream. |
| 212 // | 212 // |
| 213 // Note that for reading files (or anything represented by a file descriptor), | 213 // Note that for reading files (or anything represented by a file descriptor), |
| 214 // FileInputStream is more efficient. | 214 // FileInputStream is more efficient. |
| 215 class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { | 215 class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { |
| 216 public: | 216 public: |
| 217 // Creates a stream that reads from the given C++ istream. | 217 // Creates a stream that reads from the given C++ istream. |
| 218 // If a block_size is given, it specifies the number of bytes that | 218 // If a block_size is given, it specifies the number of bytes that |
| 219 // should be read and returned with each call to Next(). Otherwise, | 219 // should be read and returned with each call to Next(). Otherwise, |
| 220 // a reasonable default is used. | 220 // a reasonable default is used. |
| 221 explicit IstreamInputStream(istream* stream, int block_size = -1); | 221 explicit IstreamInputStream(std::istream* stream, int block_size = -1); |
| 222 ~IstreamInputStream(); | 222 ~IstreamInputStream(); |
| 223 | 223 |
| 224 // implements ZeroCopyInputStream ---------------------------------- | 224 // implements ZeroCopyInputStream ---------------------------------- |
| 225 bool Next(const void** data, int* size); | 225 bool Next(const void** data, int* size); |
| 226 void BackUp(int count); | 226 void BackUp(int count); |
| 227 bool Skip(int count); | 227 bool Skip(int count); |
| 228 int64 ByteCount() const; | 228 int64 ByteCount() const; |
| 229 | 229 |
| 230 private: | 230 private: |
| 231 class LIBPROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream
{ | 231 class LIBPROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream
{ |
| 232 public: | 232 public: |
| 233 CopyingIstreamInputStream(istream* input); | 233 CopyingIstreamInputStream(std::istream* input); |
| 234 ~CopyingIstreamInputStream(); | 234 ~CopyingIstreamInputStream(); |
| 235 | 235 |
| 236 // implements CopyingInputStream --------------------------------- | 236 // implements CopyingInputStream --------------------------------- |
| 237 int Read(void* buffer, int size); | 237 int Read(void* buffer, int size); |
| 238 // (We use the default implementation of Skip().) | 238 // (We use the default implementation of Skip().) |
| 239 | 239 |
| 240 private: | 240 private: |
| 241 // The stream. | 241 // The stream. |
| 242 istream* input_; | 242 std::istream* input_; |
| 243 | 243 |
| 244 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream); | 244 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream); |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 CopyingIstreamInputStream copying_input_; | 247 CopyingIstreamInputStream copying_input_; |
| 248 CopyingInputStreamAdaptor impl_; | 248 CopyingInputStreamAdaptor impl_; |
| 249 | 249 |
| 250 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(IstreamInputStream); | 250 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(IstreamInputStream); |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 // =================================================================== | 253 // =================================================================== |
| 254 | 254 |
| 255 // A ZeroCopyOutputStream which writes to a C++ ostream. | 255 // A ZeroCopyOutputStream which writes to a C++ ostream. |
| 256 // | 256 // |
| 257 // Note that for writing files (or anything represented by a file descriptor), | 257 // Note that for writing files (or anything represented by a file descriptor), |
| 258 // FileOutputStream is more efficient. | 258 // FileOutputStream is more efficient. |
| 259 class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { | 259 class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { |
| 260 public: | 260 public: |
| 261 // Creates a stream that writes to the given C++ ostream. | 261 // Creates a stream that writes to the given C++ ostream. |
| 262 // If a block_size is given, it specifies the size of the buffers | 262 // If a block_size is given, it specifies the size of the buffers |
| 263 // that should be returned by Next(). Otherwise, a reasonable default | 263 // that should be returned by Next(). Otherwise, a reasonable default |
| 264 // is used. | 264 // is used. |
| 265 explicit OstreamOutputStream(ostream* stream, int block_size = -1); | 265 explicit OstreamOutputStream(std::ostream* stream, int block_size = -1); |
| 266 ~OstreamOutputStream(); | 266 ~OstreamOutputStream(); |
| 267 | 267 |
| 268 // implements ZeroCopyOutputStream --------------------------------- | 268 // implements ZeroCopyOutputStream --------------------------------- |
| 269 bool Next(void** data, int* size); | 269 bool Next(void** data, int* size); |
| 270 void BackUp(int count); | 270 void BackUp(int count); |
| 271 int64 ByteCount() const; | 271 int64 ByteCount() const; |
| 272 | 272 |
| 273 private: | 273 private: |
| 274 class LIBPROTOBUF_EXPORT CopyingOstreamOutputStream : public CopyingOutputStre
am { | 274 class LIBPROTOBUF_EXPORT CopyingOstreamOutputStream : public CopyingOutputStre
am { |
| 275 public: | 275 public: |
| 276 CopyingOstreamOutputStream(ostream* output); | 276 CopyingOstreamOutputStream(std::ostream* output); |
| 277 ~CopyingOstreamOutputStream(); | 277 ~CopyingOstreamOutputStream(); |
| 278 | 278 |
| 279 // implements CopyingOutputStream -------------------------------- | 279 // implements CopyingOutputStream -------------------------------- |
| 280 bool Write(const void* buffer, int size); | 280 bool Write(const void* buffer, int size); |
| 281 | 281 |
| 282 private: | 282 private: |
| 283 // The stream. | 283 // The stream. |
| 284 ostream* output_; | 284 std::ostream* output_; |
| 285 | 285 |
| 286 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream); | 286 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream); |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 CopyingOstreamOutputStream copying_output_; | 289 CopyingOstreamOutputStream copying_output_; |
| 290 CopyingOutputStreamAdaptor impl_; | 290 CopyingOutputStreamAdaptor impl_; |
| 291 | 291 |
| 292 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OstreamOutputStream); | 292 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OstreamOutputStream); |
| 293 }; | 293 }; |
| 294 | 294 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream); | 349 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream); |
| 350 }; | 350 }; |
| 351 | 351 |
| 352 // =================================================================== | 352 // =================================================================== |
| 353 | 353 |
| 354 } // namespace io | 354 } // namespace io |
| 355 } // namespace protobuf | 355 } // namespace protobuf |
| 356 | 356 |
| 357 } // namespace google | 357 } // namespace google |
| 358 #endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ | 358 #endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ |
| OLD | NEW |