20typedef unsigned __int64 uint64_t;
38 virtual size_t Read(
void *ptr,
size_t size) = 0;
44 virtual void Write(
const void *ptr,
size_t size) = 0;
58 const char*
const flag,
59 bool allow_null =
false);
74 inline void Write(
const T &data);
88 inline bool Read(T *out_data);
96 inline void WriteArray(
const T* data,
size_t num_elems);
105 inline bool ReadArray(T* data,
size_t num_elems);
114 virtual void Seek(
size_t pos) = 0;
128 bool allow_null =
false);
290 const char *index_uri,
294 const bool shuffle =
false,
296 const size_t batch_size = 256,
297 const bool recurse_directories =
false);
300#ifndef _LIBCPP_SGX_NO_IOSTREAMS
314class ostream :
public std::basic_ostream<char> {
322 size_t buffer_size = (1 << 10))
323 :
std::basic_ostream<char>(NULL), buf_(buffer_size) {
327 virtual ~ostream() DMLC_NO_EXCEPTION {
335 buf_.set_stream(stream);
341 return buf_.bytes_out();
346 class OutBuf :
public std::streambuf {
348 explicit OutBuf(
size_t buffer_size)
349 : stream_(NULL), buffer_(buffer_size), bytes_out_(0) {
350 if (buffer_size == 0) buffer_.resize(2);
353 inline void set_stream(Stream *stream);
355 inline size_t bytes_out()
const {
return bytes_out_; }
360 std::vector<char> buffer_;
364 inline int_type sync(
void);
366 inline int_type overflow(
int c);
385class istream :
public std::basic_istream<char> {
393 size_t buffer_size = (1 << 10))
394 :
std::basic_istream<char>(NULL), buf_(buffer_size) {
397 virtual ~istream() DMLC_NO_EXCEPTION {}
403 buf_.set_stream(stream);
408 return buf_.bytes_read();
413 class InBuf :
public std::streambuf {
415 explicit InBuf(
size_t buffer_size)
416 : stream_(NULL), bytes_read_(0),
417 buffer_(buffer_size) {
418 if (buffer_size == 0) buffer_.resize(2);
421 inline void set_stream(Stream *stream);
423 inline size_t bytes_read(
void)
const {
432 std::vector<char> buffer_;
434 inline int_type underflow();
457 for (
size_t i = 0; i < num_elems; ++i) {
458 this->Write<T>(data[i]);
464 for (
size_t i = 0; i < num_elems; ++i) {
465 if (!this->Read<T>(data + i))
return false;
470#ifndef _LIBCPP_SGX_NO_IOSTREAMS
472inline void ostream::OutBuf::set_stream(
Stream *stream) {
473 if (stream_ != NULL) this->pubsync();
474 this->stream_ = stream;
475 this->setp(&buffer_[0], &buffer_[0] + buffer_.size() - 1);
477inline int ostream::OutBuf::sync(
void) {
478 if (stream_ == NULL)
return -1;
479 std::ptrdiff_t n = pptr() - pbase();
480 stream_->Write(pbase(), n);
481 this->pbump(-
static_cast<int>(n));
485inline int ostream::OutBuf::overflow(
int c) {
487 std::ptrdiff_t n = pptr() - pbase();
488 this->pbump(-
static_cast<int>(n));
490 stream_->Write(pbase(), n);
493 stream_->Write(pbase(), n + 1);
500inline void istream::InBuf::set_stream(Stream *stream) {
502 this->setg(&buffer_[0], &buffer_[0], &buffer_[0]);
504inline int istream::InBuf::underflow() {
505 char *bhead = &buffer_[0];
506 if (this->gptr() == this->egptr()) {
507 size_t sz = stream_->Read(bhead, buffer_.size());
508 this->setg(bhead, bhead, bhead + sz);
511 if (this->gptr() == this->egptr()) {
512 return traits_type::eof();
514 return traits_type::to_int_type(*gptr());
523 std::string protocol;
535 explicit URI(
const char *uri) {
536 const char *p = std::strstr(uri,
"://");
540 protocol = std::string(uri, p - uri + 3);
542 p = std::strchr(uri,
'/');
544 host = uri; name =
'/';
546 host = std::string(uri, p - uri);
552 inline std::string str(
void)
const {
553 return protocol + host + name;
574 FileInfo() : size(0), type(kFile) {}
587 static FileSystem *GetInstance(
const URI &path);
589 virtual ~FileSystem() {}
595 virtual FileInfo GetPathInfo(
const URI &path) = 0;
601 virtual void ListDirectory(
const URI &path, std::vector<FileInfo> *out_list) = 0;
607 virtual void ListDirectoryRecursive(
const URI &path,
608 std::vector<FileInfo> *out_list);
616 virtual Stream *Open(
const URI &path,
617 const char*
const flag,
618 bool allow_null =
false) = 0;
625 virtual SeekStream *OpenForRead(
const URI &path,
626 bool allow_null =
false) = 0;
interface of i/o stream that support seek
Definition io.h:109
virtual void Seek(size_t pos)=0
seek to certain position of the file
virtual size_t Tell(void)=0
tell the position of the stream
static SeekStream * CreateForRead(const char *uri, bool allow_null=false)
generic factory function create an SeekStream for read only, the stream will close the underlying fil...
Definition io.cc:140
interface for serializable objects
Definition io.h:132
virtual void Load(Stream *fi)=0
load the model from a stream
virtual void Save(Stream *fo) const =0
saves the model to a stream
virtual ~Serializable()
virtual destructor
Definition io.h:135
interface of stream I/O for serialization
Definition io.h:30
void WriteArray(const T *data, size_t num_elems)
Endian aware write array of data.
Definition io.h:456
virtual ~Stream(void)
virtual destructor
Definition io.h:46
virtual void Write(const void *ptr, size_t size)=0
writes data to a stream
virtual size_t Read(void *ptr, size_t size)=0
reads data from a stream
bool ReadArray(T *data, size_t num_elems)
Endian aware read array of data.
Definition io.h:463
static Stream * Create(const char *uri, const char *const flag, bool allow_null=false)
generic factory function create an stream, the stream will close the underlying files upon deletion
Definition io.cc:132
a std::istream class that can can wrap Stream objects, can use istream with that output to underlying...
Definition io.h:385
size_t bytes_read(void) const
Definition io.h:407
void set_stream(Stream *stream)
set internal stream to be stream, reset states
Definition io.h:402
istream(Stream *stream, size_t buffer_size=(1<< 10))
construct std::ostream type
Definition io.h:392
a std::ostream class that can can wrap Stream objects, can use ostream with that output to underlying...
Definition io.h:314
void set_stream(Stream *stream)
set internal stream to be stream, reset states
Definition io.h:334
ostream(Stream *stream, size_t buffer_size=(1<< 10))
construct std::ostream type
Definition io.h:321
size_t bytes_written(void) const
Definition io.h:340
defines console logging options for xgboost. Use to enforce unified print behavior.
namespace for dmlc
Definition array_view.h:12
dmlc::SeekStream SeekStream
re-use definition of dmlc::SeekStream
Definition io.h:24
dmlc::Stream Stream
defines stream used in rabit see definition of Stream in dmlc/io.h
Definition rabit.h:27
serializer template class that helps serialization. This file do not need to be directly used by most...
static void Write(Stream *strm, const T &data)
write data to stream
Definition serializer.h:265
static bool Read(Stream *strm, T *data)
read data to stream
Definition serializer.h:283