-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclosxom_collector.cc
40 lines (35 loc) · 1.34 KB
/
closxom_collector.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <sys/dir.h>
#include <functional>
#include "closxom_collector.h"
class Storage;
namespace closxom {
class EntryDateSorter : public std::binary_function<entry_ptr, entry_ptr, bool> {
public:
bool operator()(const entry_ptr& a, const entry_ptr& b) {
return (a->modified_datetime() < b->modified_datetime());
}
};
void Collector::Init() {
Storage* storage;
if (this->config().storage_type() == "protobuf") {
storage = new StorageProtobuf(this->config().rootpath()+std::string("entries.pb")); // XXX
}else if (this->config().storage_type() == "filesystem") {
storage = new StorageFileSystem(this->config().rootpath()+std::string("test-files/")); // XXX
}
storage->Init();
this->set_storage(storage);
}
const std::vector<entry_ptr> Collector::GetFilteredEntries(const std::string datetime) {
std::vector<entry_ptr> entries;
for (int i = 0; i < this->storage()->EntrySize(); i++) {
Entry* entry = new Entry();
this->storage()->ExtractEntry(i, entry);
// filtering by datetime
if (datetime != "" && entry->modified_datetime().compare(0, datetime.length(), datetime) != 0) continue;
entry_ptr entry_p = entry_ptr(entry);
entries.push_back(entry_p);
}
sort(entries.begin(), entries.end(), EntryDateSorter()); // sort by mtime
return entries;
}
}