Caffe2 - C++ API
A deep learning, cross platform ML framework
istream_adapter.cc
1 #include "caffe2/serialize/istream_adapter.h"
2 #include <c10/util/Exception.h>
3 
4 namespace caffe2 {
5 namespace serialize {
6 
7 IStreamAdapter::IStreamAdapter(std::istream* istream) : istream_(istream) {}
8 
9 size_t IStreamAdapter::size() const {
10  auto prev_pos = istream_->tellg();
11  validate("getting the current position");
12  istream_->seekg(0, istream_->end);
13  validate("seeking to end");
14  auto result = istream_->tellg();
15  validate("getting size");
16  istream_->seekg(prev_pos);
17  validate("seeking to the original position");
18  return result;
19 }
20 
21 size_t IStreamAdapter::read(uint64_t pos, void* buf, size_t n, const char* what)
22  const {
23  istream_->seekg(pos);
24  validate(what);
25  istream_->read(static_cast<char*>(buf), n);
26  validate(what);
27  return n;
28 }
29 
30 void IStreamAdapter::validate(const char* what) const {
31  if (!*istream_) {
32  AT_ERROR("istream reader failed: ", what, ".");
33  }
34 }
35 
36 IStreamAdapter::~IStreamAdapter() {}
37 
38 } // namespace serialize
39 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13