pass solaris compile
This commit is contained in:
parent
52fe528615
commit
8437e43afc
@ -19,6 +19,7 @@ class FileStream : public utils::ISeekStream {
|
|||||||
public:
|
public:
|
||||||
explicit FileStream(const char *fname, const char *mode)
|
explicit FileStream(const char *fname, const char *mode)
|
||||||
: use_stdio(false) {
|
: use_stdio(false) {
|
||||||
|
using namespace std;
|
||||||
#ifndef RABIT_STRICT_CXX98_
|
#ifndef RABIT_STRICT_CXX98_
|
||||||
if (!strcmp(fname, "stdin")) {
|
if (!strcmp(fname, "stdin")) {
|
||||||
use_stdio = true; fp = stdin;
|
use_stdio = true; fp = stdin;
|
||||||
@ -51,7 +52,7 @@ class FileStream : public utils::ISeekStream {
|
|||||||
return std::ftell(fp);
|
return std::ftell(fp);
|
||||||
}
|
}
|
||||||
virtual bool AtEnd(void) const {
|
virtual bool AtEnd(void) const {
|
||||||
return feof(fp) != 0;
|
return std::feof(fp) != 0;
|
||||||
}
|
}
|
||||||
inline void Close(void) {
|
inline void Close(void) {
|
||||||
if (fp != NULL && !use_stdio) {
|
if (fp != NULL && !use_stdio) {
|
||||||
@ -60,7 +61,7 @@ class FileStream : public utils::ISeekStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE *fp;
|
std::FILE *fp;
|
||||||
bool use_stdio;
|
bool use_stdio;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ class FileSplit : public LineSplitBase {
|
|||||||
LineSplitBase::SplitNames(&fnames_, uri, "#");
|
LineSplitBase::SplitNames(&fnames_, uri, "#");
|
||||||
std::vector<size_t> fsize;
|
std::vector<size_t> fsize;
|
||||||
for (size_t i = 0; i < fnames_.size(); ++i) {
|
for (size_t i = 0; i < fnames_.size(); ++i) {
|
||||||
if (!strncmp(fnames_[i].c_str(), "file://", 7)) {
|
if (!std::strncmp(fnames_[i].c_str(), "file://", 7)) {
|
||||||
std::string tmp = fnames_[i].c_str() + 7;
|
std::string tmp = fnames_[i].c_str() + 7;
|
||||||
fnames_[i] = tmp;
|
fnames_[i] = tmp;
|
||||||
}
|
}
|
||||||
@ -88,11 +89,11 @@ class FileSplit : public LineSplitBase {
|
|||||||
}
|
}
|
||||||
// get file size
|
// get file size
|
||||||
inline static size_t GetFileSize(const char *fname) {
|
inline static size_t GetFileSize(const char *fname) {
|
||||||
FILE *fp = utils::FopenCheck(fname, "rb");
|
std::FILE *fp = utils::FopenCheck(fname, "rb");
|
||||||
// NOTE: fseek may not be good, but serves as ok solution
|
// NOTE: fseek may not be good, but serves as ok solution
|
||||||
fseek(fp, 0, SEEK_END);
|
std::fseek(fp, 0, SEEK_END);
|
||||||
size_t fsize = static_cast<size_t>(ftell(fp));
|
size_t fsize = static_cast<size_t>(std::ftell(fp));
|
||||||
fclose(fp);
|
std::fclose(fp);
|
||||||
return fsize;
|
return fsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ namespace io {
|
|||||||
inline InputSplit *CreateInputSplit(const char *uri,
|
inline InputSplit *CreateInputSplit(const char *uri,
|
||||||
unsigned part,
|
unsigned part,
|
||||||
unsigned nsplit) {
|
unsigned nsplit) {
|
||||||
|
using namespace std;
|
||||||
if (!strcmp(uri, "stdin")) {
|
if (!strcmp(uri, "stdin")) {
|
||||||
return new SingleFileSplit(uri);
|
return new SingleFileSplit(uri);
|
||||||
}
|
}
|
||||||
@ -48,6 +49,7 @@ inline InputSplit *CreateInputSplit(const char *uri,
|
|||||||
* \param mode can be 'w' or 'r' for read or write
|
* \param mode can be 'w' or 'r' for read or write
|
||||||
*/
|
*/
|
||||||
inline IStream *CreateStream(const char *uri, const char *mode) {
|
inline IStream *CreateStream(const char *uri, const char *mode) {
|
||||||
|
using namespace std;
|
||||||
if (!strncmp(uri, "file://", 7)) {
|
if (!strncmp(uri, "file://", 7)) {
|
||||||
return new FileStream(uri + 7, mode);
|
return new FileStream(uri + 7, mode);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#ifndef RABIT_LEARN_IO_LINE_SPLIT_INL_H_
|
#ifndef RABIT_LEARN_IO_LINE_SPLIT_INL_H_
|
||||||
#define RABIT_LEARN_IO_LINE_SPLIT_INL_H_
|
#define RABIT_LEARN_IO_LINE_SPLIT_INL_H_
|
||||||
/*!
|
/*!
|
||||||
* \file line_split-inl.h
|
* \std::FILE line_split-inl.h
|
||||||
* \brief base implementation of line-spliter
|
* \brief base implementation of line-spliter
|
||||||
* \author Tianqi Chen
|
* \author Tianqi Chen
|
||||||
*/
|
*/
|
||||||
@ -30,7 +30,7 @@ class LineSplitBase : public InputSplit {
|
|||||||
if (out_data->length() != 0) return true;
|
if (out_data->length() != 0) return true;
|
||||||
file_ptr_ += 1;
|
file_ptr_ += 1;
|
||||||
if (offset_curr_ != file_offset_[file_ptr_]) {
|
if (offset_curr_ != file_offset_[file_ptr_]) {
|
||||||
utils::Error("warning:file size not calculated correctly\n");
|
utils::Error("warning:std::FILE size not calculated correctly\n");
|
||||||
offset_curr_ = file_offset_[file_ptr_];
|
offset_curr_ = file_offset_[file_ptr_];
|
||||||
}
|
}
|
||||||
if (offset_curr_ >= offset_end_) return false;
|
if (offset_curr_ >= offset_end_) return false;
|
||||||
@ -59,7 +59,7 @@ class LineSplitBase : public InputSplit {
|
|||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
* \brief initialize the line spliter,
|
* \brief initialize the line spliter,
|
||||||
* \param file_size, size of each files
|
* \param file_size, size of each std::FILEs
|
||||||
* \param rank the current rank of the data
|
* \param rank the current rank of the data
|
||||||
* \param nsplit number of split we will divide the data into
|
* \param nsplit number of split we will divide the data into
|
||||||
*/
|
*/
|
||||||
@ -96,31 +96,31 @@ class LineSplitBase : public InputSplit {
|
|||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
* \brief get the seek stream of given file_index
|
* \brief get the seek stream of given file_index
|
||||||
* \return the corresponding seek stream at head of file
|
* \return the corresponding seek stream at head of std::FILE
|
||||||
*/
|
*/
|
||||||
virtual utils::ISeekStream *GetFile(size_t file_index) = 0;
|
virtual utils::ISeekStream *GetFile(size_t file_index) = 0;
|
||||||
/*!
|
/*!
|
||||||
* \brief split names given
|
* \brief split names given
|
||||||
* \param out_fname output file names
|
* \param out_fname output std::FILE names
|
||||||
* \param uri_ the iput uri file
|
* \param uri_ the iput uri std::FILE
|
||||||
* \param dlm deliminetr
|
* \param dlm deliminetr
|
||||||
*/
|
*/
|
||||||
inline static void SplitNames(std::vector<std::string> *out_fname,
|
inline static void SplitNames(std::vector<std::string> *out_fname,
|
||||||
const char *uri_,
|
const char *uri_,
|
||||||
const char *dlm) {
|
const char *dlm) {
|
||||||
std::string uri = uri_;
|
std::string uri = uri_;
|
||||||
char *p = strtok(BeginPtr(uri), dlm);
|
char *p = std::strtok(BeginPtr(uri), dlm);
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
out_fname->push_back(std::string(p));
|
out_fname->push_back(std::string(p));
|
||||||
p = strtok(NULL, dlm);
|
p = std::strtok(NULL, dlm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
/*! \brief current input stream */
|
/*! \brief current input stream */
|
||||||
utils::ISeekStream *fs_;
|
utils::ISeekStream *fs_;
|
||||||
/*! \brief file pointer of which file to read on */
|
/*! \brief std::FILE pointer of which std::FILE to read on */
|
||||||
size_t file_ptr_;
|
size_t file_ptr_;
|
||||||
/*! \brief file pointer where the end of file lies */
|
/*! \brief std::FILE pointer where the end of std::FILE lies */
|
||||||
size_t file_ptr_end_;
|
size_t file_ptr_end_;
|
||||||
/*! \brief get the current offset */
|
/*! \brief get the current offset */
|
||||||
size_t offset_curr_;
|
size_t offset_curr_;
|
||||||
@ -128,7 +128,7 @@ class LineSplitBase : public InputSplit {
|
|||||||
size_t offset_begin_;
|
size_t offset_begin_;
|
||||||
/*! \brief end of the offset */
|
/*! \brief end of the offset */
|
||||||
size_t offset_end_;
|
size_t offset_end_;
|
||||||
/*! \brief byte-offset of each file */
|
/*! \brief byte-offset of each std::FILE */
|
||||||
std::vector<size_t> file_offset_;
|
std::vector<size_t> file_offset_;
|
||||||
/*! \brief buffer reader */
|
/*! \brief buffer reader */
|
||||||
StreamBufferReader reader_;
|
StreamBufferReader reader_;
|
||||||
@ -136,11 +136,11 @@ class LineSplitBase : public InputSplit {
|
|||||||
const static size_t kBufferSize = 256;
|
const static size_t kBufferSize = 256;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \brief line split from single file */
|
/*! \brief line split from single std::FILE */
|
||||||
class SingleFileSplit : public InputSplit {
|
class SingleFileSplit : public InputSplit {
|
||||||
public:
|
public:
|
||||||
explicit SingleFileSplit(const char *fname) {
|
explicit SingleFileSplit(const char *fname) {
|
||||||
if (!strcmp(fname, "stdin")) {
|
if (!std::strcmp(fname, "stdin")) {
|
||||||
#ifndef RABIT_STRICT_CXX98_
|
#ifndef RABIT_STRICT_CXX98_
|
||||||
use_stdin_ = true; fp_ = stdin;
|
use_stdin_ = true; fp_ = stdin;
|
||||||
#endif
|
#endif
|
||||||
@ -151,13 +151,13 @@ class SingleFileSplit : public InputSplit {
|
|||||||
end_of_file_ = false;
|
end_of_file_ = false;
|
||||||
}
|
}
|
||||||
virtual ~SingleFileSplit(void) {
|
virtual ~SingleFileSplit(void) {
|
||||||
if (!use_stdin_) fclose(fp_);
|
if (!use_stdin_) std::fclose(fp_);
|
||||||
}
|
}
|
||||||
virtual bool NextLine(std::string *out_data) {
|
virtual bool NextLine(std::string *out_data) {
|
||||||
if (end_of_file_) return false;
|
if (end_of_file_) return false;
|
||||||
out_data->clear();
|
out_data->clear();
|
||||||
while (true) {
|
while (true) {
|
||||||
char c = fgetc(fp_);
|
char c = std::fgetc(fp_);
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
end_of_file_ = true;
|
end_of_file_ = true;
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ class SingleFileSplit : public InputSplit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE *fp_;
|
std::FILE *fp_;
|
||||||
bool use_stdin_;
|
bool use_stdin_;
|
||||||
bool end_of_file_;
|
bool end_of_file_;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user