Jouni's Incremental BWT integrated into TextCollection
[SXSI/TextCollection.git] / incbwt / misc / utils.cpp
1 #include "utils.h"
2
3
4 namespace CSA
5 {
6
7
8 std::streamoff
9 fileSize(std::ifstream& file)
10 {
11   std::streamoff curr = file.tellg();
12
13   file.seekg(0, std::ios::end);
14   std::streamoff size = file.tellg();
15   file.seekg(0, std::ios::beg);
16   size -= file.tellg();
17
18   file.seekg(curr, std::ios::beg);
19   return size;
20 }
21
22 std::streamoff
23 fileSize(std::ofstream& file)
24 {
25   std::streamoff curr = file.tellp();
26
27   file.seekp(0, std::ios::end);
28   std::streamoff size = file.tellp();
29   file.seekp(0, std::ios::beg);
30   size -= file.tellp();
31
32   file.seekp(curr, std::ios::beg);
33   return size;
34 }
35
36 std::ostream&
37 operator<<(std::ostream& stream, pair_type data)
38 {
39   return stream << "(" << data.first << ", " << data.second << ")";
40 }
41
42 void
43 readRows(std::ifstream& file, std::list<std::string>& rows, bool skipEmptyRows)
44 {
45   while(file)
46   {
47     std::string buf;
48     std::getline(file, buf);
49     if(skipEmptyRows && buf.length() == 0) { continue; }
50     rows.push_back(buf);
51   }
52 }
53
54
55 } // namespace CSA