X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;ds=sidebyside;f=incbwt%2Fmisc%2Futils.cpp;fp=incbwt%2Fmisc%2Futils.cpp;h=ae4988385911d373e349a13c6c1b1943e49c9fe7;hb=40ddf9aca842bdc081b6350a4ebfe36b066c94c9;hp=0000000000000000000000000000000000000000;hpb=af8938dbee21244687184dd0502a84ce1af70c50;p=SXSI%2FTextCollection.git diff --git a/incbwt/misc/utils.cpp b/incbwt/misc/utils.cpp new file mode 100644 index 0000000..ae49883 --- /dev/null +++ b/incbwt/misc/utils.cpp @@ -0,0 +1,55 @@ +#include "utils.h" + + +namespace CSA +{ + + +std::streamoff +fileSize(std::ifstream& file) +{ + std::streamoff curr = file.tellg(); + + file.seekg(0, std::ios::end); + std::streamoff size = file.tellg(); + file.seekg(0, std::ios::beg); + size -= file.tellg(); + + file.seekg(curr, std::ios::beg); + return size; +} + +std::streamoff +fileSize(std::ofstream& file) +{ + std::streamoff curr = file.tellp(); + + file.seekp(0, std::ios::end); + std::streamoff size = file.tellp(); + file.seekp(0, std::ios::beg); + size -= file.tellp(); + + file.seekp(curr, std::ios::beg); + return size; +} + +std::ostream& +operator<<(std::ostream& stream, pair_type data) +{ + return stream << "(" << data.first << ", " << data.second << ")"; +} + +void +readRows(std::ifstream& file, std::list& rows, bool skipEmptyRows) +{ + while(file) + { + std::string buf; + std::getline(file, buf); + if(skipEmptyRows && buf.length() == 0) { continue; } + rows.push_back(buf); + } +} + + +} // namespace CSA