check in io module

This commit is contained in:
tqchen
2014-08-16 14:06:31 -07:00
parent ac1cc15b90
commit c4acb4fe01
10 changed files with 417 additions and 33 deletions

View File

@@ -42,7 +42,9 @@ class IStream {
inline void Write(const std::vector<T> &vec) {
uint64_t sz = vec.size();
this->Write(&sz, sizeof(sz));
this->Write(&vec[0], sizeof(T) * sz);
if (sz != 0) {
this->Write(&vec[0], sizeof(T) * sz);
}
}
/*!
* \brief binary load a vector
@@ -54,7 +56,9 @@ class IStream {
uint64_t sz;
if (this->Read(&sz, sizeof(sz)) == 0) return false;
out_vec->resize(sz);
if (this->Read(&(*out_vec)[0], sizeof(T) * sz) == 0) return false;
if (sz != 0) {
if (this->Read(&(*out_vec)[0], sizeof(T) * sz) == 0) return false;
}
return true;
}
/*!
@@ -64,7 +68,9 @@ class IStream {
inline void Write(const std::string &str) {
uint64_t sz = str.length();
this->Write(&sz, sizeof(sz));
this->Write(&str[0], sizeof(char) * sz);
if (sz != 0) {
this->Write(&str[0], sizeof(char) * sz);
}
}
/*!
* \brief binary load a string
@@ -75,7 +81,9 @@ class IStream {
uint64_t sz;
if (this->Read(&sz, sizeof(sz)) == 0) return false;
out_str->resize(sz);
if (this->Read(&(*out_str)[0], sizeof(char) * sz) == 0) return false;
if (sz != 0) {
if (this->Read(&(*out_str)[0], sizeof(char) * sz) == 0) return false;
}
return true;
}
};

View File

@@ -18,11 +18,11 @@ class IIterator {
/*!
* \brief set the parameter
* \param name name of parameter
* \param val value of parameter
* \param val value of parameter
*/
virtual void SetParam(const char *name, const char *val) = 0;
virtual void SetParam(const char *name, const char *val) {}
/*! \brief initalize the iterator so that we can use the iterator */
virtual void Init(void) = 0;
virtual void Init(void) {}
/*! \brief set before first of the item */
virtual void BeforeFirst(void) = 0;
/*! \brief move to next item */