forked from geohot/eda-2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StatelessChangelist.cc
66 lines (53 loc) · 1.87 KB
/
StatelessChangelist.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
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
// StatelessChangelist.cc -- May 10, 2009
// by geohot
// part of "The Embedded Disassembler"
// released under GPLv3, see http://gplv3.fsf.org/
//
// StatelessChangelist could conceptually be a base class of Changelist
#include "data_atomic.h"
#include "util.h"
#include <string>
#include "JSON.h"
using namespace std;
using namespace eda;
void StatelessChangelist::add_change(const string& lhs, const string& cond, int bytes, const string& value) {
changes_.insert(make_pair(make_pair(lhs, cond), make_pair(bytes, value)));
}
bool StatelessChangelist::get_first_change(StatelessChangelistIterator* a) {
if(changes_.size() > 0) {
(*a) = changes_.begin();
return true;
}
else
return false;
}
bool StatelessChangelist::get_next_change(StatelessChangelistIterator* a) {
++(*a);
return (*a) != changes_.end();
}
int StatelessChangelist::get_size() {
return changes_.size();
}
void StatelessChangelist::SerializeToXML(ostringstream& out) {
out << "<StatelessChangelist>";
for (StatelessChangelistIterator it = changes_.begin(); it != changes_.end(); ++it) {
out << "<change>";
out << "<target>" << MakeWellFormedXML(it->first.first) << "</target>";
out << "<condition>" << MakeWellFormedXML(it->first.second) << "</condition>";
out << "<bytes>" << it->second.first << "</bytes>";
out << "<value>" << MakeWellFormedXML(it->second.second) << "</value>";
out << "</change>";
}
out << "</StatelessChangelist>";
}
void StatelessChangelist::SerializeToJSON(JSON* json) {
vector<JSON> ret;
for (StatelessChangelistIterator it = changes_.begin(); it != changes_.end(); ++it) {
ret.push_back(JSON());
ret.back().add("target", it->first.first);
ret.back().add("condition", it->first.second);
ret.back().add("bytes", it->second.first);
ret.back().add("value", it->second.second);
}
json->add("StatelessChangelist", ret);
}