|
@@ -107,53 +107,71 @@ std::vector<std::string> FileManager::listFiles() {
|
|
|
}
|
|
|
|
|
|
int FileManager::openList() {
|
|
|
- list = listFiles();
|
|
|
- int chunks = 0;
|
|
|
+ std::vector<std::string> fullList = listFiles();
|
|
|
+
|
|
|
+ if (fullList.size() == 0) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // add empty chunk vector
|
|
|
+ this->list.push_back(std::vector<std::string>());
|
|
|
+
|
|
|
int cursize = 0;
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- if (list.at(i).length() > max_data_length)
|
|
|
+ for (const std::string &s : fullList) {
|
|
|
+ if (s.length() > max_data_length)
|
|
|
return -1;
|
|
|
- cursize += list.at(i).length();
|
|
|
+ cursize += s.length() + 3;
|
|
|
if (cursize > max_data_length) {
|
|
|
- chunks++;
|
|
|
- i--;
|
|
|
+ this->list.push_back(std::vector<std::string>());
|
|
|
cursize = 0;
|
|
|
}
|
|
|
+
|
|
|
+ // add string to its chunk
|
|
|
+ this->list.back().push_back(s);
|
|
|
}
|
|
|
- if (list.size() > 0)
|
|
|
+
|
|
|
+ return this->list.size();
|
|
|
+
|
|
|
+ /*
|
|
|
+if (fullList.size() > 0)
|
|
|
chunks++;
|
|
|
remainingListChunks = chunks;
|
|
|
return chunks;
|
|
|
+ */
|
|
|
+
|
|
|
+ /*
|
|
|
+ int cursize = 0;
|
|
|
+ while (!list.empty()) {
|
|
|
+ std::string tmp = list.back();
|
|
|
+ cursize += tmp.length() + 3; // +3 because two '"' and one ',' per file entry
|
|
|
+ if (cursize > max_data_length) {
|
|
|
+ break;
|
|
|
+} else {
|
|
|
+ ret.push_back(tmp);
|
|
|
+ list.pop_back();
|
|
|
+}
|
|
|
+}*/
|
|
|
}
|
|
|
|
|
|
-int FileManager::getRemainingListChunks() { return remainingListChunks; }
|
|
|
+int FileManager::getRemainingListChunks() { return this->list.size(); }
|
|
|
|
|
|
-int FileManager::getListSize() { return list.size(); }
|
|
|
+int FileManager::getListSize() {
|
|
|
+ int size = 0;
|
|
|
+ for (const std::vector<std::string> &l : this->list) {
|
|
|
+ size += l.size();
|
|
|
+ }
|
|
|
+ return size;
|
|
|
+}
|
|
|
|
|
|
std::vector<std::string> FileManager::getNextChunkFromList() {
|
|
|
- if (remainingListChunks == 0) { // This should never happen!!!
|
|
|
+ if (getRemainingListChunks() == 0) { // This should never happen!!!
|
|
|
return std::vector<std::string>();
|
|
|
}
|
|
|
|
|
|
- std::vector<std::string> ret;
|
|
|
- int cursize = 0;
|
|
|
- std::string tmp;
|
|
|
- while (!list.empty()) {
|
|
|
- tmp = list.back();
|
|
|
- cursize += tmp.length();
|
|
|
- if (cursize > max_data_length) {
|
|
|
- break;
|
|
|
- } else {
|
|
|
- ret.push_back(tmp);
|
|
|
- list.pop_back();
|
|
|
- }
|
|
|
- }
|
|
|
+ std::vector<std::string> ret = this->list.back();
|
|
|
+ this->list.pop_back();
|
|
|
|
|
|
- remainingListChunks--;
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-void FileManager::cancelList() {
|
|
|
- remainingListChunks = 0;
|
|
|
- list.clear();
|
|
|
-}
|
|
|
+void FileManager::cancelList() { this->list.clear(); }
|