|
19 | 19 |
|
20 | 20 | #include "json-writer.hh" |
21 | 21 |
|
| 22 | +#include <queue> |
| 23 | + |
22 | 24 | #include <boost/foreach.hpp> |
23 | 25 | #include <boost/iostreams/filtering_stream.hpp> |
24 | 26 | #include <boost/iostreams/filter/regex.hpp> |
25 | 27 | #include <boost/property_tree/json_parser.hpp> |
26 | 28 |
|
27 | 29 | struct JsonWriter::Private { |
28 | 30 | std::ostream &str; |
29 | | - boost::property_tree::ptree defList; |
| 31 | + std::queue<Defect> defQueue; |
30 | 32 | TScanProps scanProps; |
31 | 33 |
|
32 | 34 | Private(std::ostream &str_): |
@@ -97,7 +99,7 @@ void appendDefectNode(boost::property_tree::ptree &dst, const Defect &def) { |
97 | 99 | } |
98 | 100 |
|
99 | 101 | void JsonWriter::handleDef(const Defect &def) { |
100 | | - appendDefectNode(d->defList, def); |
| 102 | + d->defQueue.push(def); |
101 | 103 | } |
102 | 104 |
|
103 | 105 | void JsonWriter::flush() { |
@@ -130,7 +132,14 @@ void JsonWriter::flush() { |
130 | 132 | root.put_child("scan", scan); |
131 | 133 | } |
132 | 134 |
|
133 | | - // append the list of defects and stream it out |
134 | | - root.put_child("defects", d->defList); |
| 135 | + // node representing the list of defects |
| 136 | + root.put_child("defects", boost::property_tree::ptree()); |
| 137 | + boost::property_tree::ptree &defects = root.get_child("defects"); |
| 138 | + |
| 139 | + // go through the queue and move defects one by one to the property tree |
| 140 | + for (; !d->defQueue.empty(); d->defQueue.pop()) |
| 141 | + appendDefectNode(defects, d->defQueue.front()); |
| 142 | + |
| 143 | + // finally encode the tree as JSON |
135 | 144 | write_json(str, root); |
136 | 145 | } |
0 commit comments