-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfeed.cpp
72 lines (66 loc) · 3.2 KB
/
feed.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Pheniqs : PHilology ENcoder wIth Quality Statistics
Copyright (C) 2018 Lior Galanti
NYU Center for Genetics and System Biology
Author: Lior Galanti <lior.galanti@nyu.edu>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "feed.h"
Value encode_value(const Feed& value, Document& document) {
Value element(kObjectType);
encode_key_value("index", value.index, element, document);
encode_key_value("url", value.url, element, document);
encode_key_value("direction", value.direction, element, document);
encode_key_value("platform", value.platform, element, document);
encode_key_value("capacity", value.capacity(), element, document);
encode_key_value("resolution", value.resolution(), element, document);
encode_key_value("phred offset", value.phred_offset, element, document);
return element;
};
bool encode_key_value(const string& key, const list< Feed* >& value, Value& container, Document& document) {
if(container.IsObject()) {
container.RemoveMember(key.c_str());
if(!value.empty()) {
Value array(kArrayType);
for(auto& feed : value) {
Value element(encode_value(*(feed), document));
array.PushBack(element.Move(), document.GetAllocator());
}
container.AddMember(Value(key.c_str(), key.size(), document.GetAllocator()).Move(), array.Move(), document.GetAllocator());
return true;
}
} else { throw ConfigurationError(string(key) + " container is not a dictionary"); }
return false;
};
bool encode_key_value(const string& key, const vector< Feed* >& value, Value& container, Document& document) {
if(container.IsObject()) {
container.RemoveMember(key.c_str());
if(!value.empty()) {
Value array(kArrayType);
for(auto& feed : value) {
Value element(encode_value(*(feed), document));
array.PushBack(element.Move(), document.GetAllocator());
}
container.AddMember(Value(key.c_str(), key.size(), document.GetAllocator()).Move(), array.Move(), document.GetAllocator());
return true;
}
} else { throw ConfigurationError(string(key) + " container is not a dictionary"); }
return false;
};
template< typename T > ostream& operator<<(ostream& o, const CyclicBuffer< T >& buffer) {
o << "Next: " << buffer._next << endl;
o << "Vacant: " << buffer._vacant << endl;
o << "Capacity: " << buffer._capacity << endl;
o << "Resolution: " << buffer._resolution << endl;
o << "Size: " << buffer.size() << endl;
return o;
};