Skip to content

Commit 6f2454a

Browse files
committed
abstract-tree: make AbstractTreeDecoder more generic
1 parent 2810ac0 commit 6f2454a

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

src/abstract-tree.hh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ class AbstractTreeDecoder {
3131
public:
3232
virtual ~AbstractTreeDecoder() { }
3333

34+
virtual void readRoot(
35+
const pt::ptree **pDefList,
36+
const pt::ptree *root)
37+
{
38+
*pDefList = root;
39+
}
40+
3441
/// read the given ptree node, decode, and store the result into def
35-
virtual void readNode(Defect *def, const pt::ptree &node) = 0;
42+
virtual bool readNode(Defect *def, pt::ptree::const_iterator defIter)
43+
= 0;
3644
};
3745

3846
template <typename TNode>

src/json-parser.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class SimpleTreeDecoder: public AbstractTreeDecoder {
3131
public:
3232
SimpleTreeDecoder(InStream &input);
33-
virtual void readNode(Defect *def, const pt::ptree &node);
33+
virtual bool readNode(Defect *def, pt::ptree::const_iterator defIter);
3434

3535
private:
3636
enum ENodeKind {
@@ -53,7 +53,7 @@ class SimpleTreeDecoder: public AbstractTreeDecoder {
5353
/// tree decoder of the Coverity JSON format
5454
class CovTreeDecoder: public AbstractTreeDecoder {
5555
public:
56-
virtual void readNode(Defect *def, const pt::ptree &node);
56+
virtual bool readNode(Defect *def, pt::ptree::const_iterator defIter);
5757

5858
private:
5959
KeyEventDigger keDigger;
@@ -150,13 +150,12 @@ const TScanProps& JsonParser::getScanProps() const
150150
bool JsonParser::Private::readNext(Defect *def)
151151
{
152152
try {
153-
// get the current node and move to the next one
154-
const pt::ptree &defNode = this->defIter->second;
155-
this->defIter++;
156-
this->defNumber++;
153+
// make sure the Defect structure is properly initialized
154+
(*def) = Defect();
157155

158-
// read the current node
159-
this->decoder->readNode(def, defNode);
156+
// read the current node and move to the next one
157+
this->defNumber++;
158+
this->decoder->readNode(def, this->defIter++);
160159
return true;
161160
}
162161
catch (pt::ptree_error &e) {
@@ -231,12 +230,11 @@ void SimpleTreeDecoder::reportUnknownNodes(ENodeKind nk, const pt::ptree &node)
231230
}
232231
}
233232

234-
void SimpleTreeDecoder::readNode(
233+
bool SimpleTreeDecoder::readNode(
235234
Defect *def,
236-
const pt::ptree &defNode)
235+
pt::ptree::const_iterator defIter)
237236
{
238-
// make sure the Defect structure is properly initialized
239-
(*def) = Defect();
237+
const pt::ptree &defNode = defIter->second;
240238

241239
this->reportUnknownNodes(NK_DEFECT, defNode);
242240

@@ -293,14 +291,15 @@ void SimpleTreeDecoder::readNode(
293291

294292
// read annotation if available
295293
def->annotation = valueOf<std::string>(defNode, "annotation", "");
294+
295+
return true;
296296
}
297297

298-
void CovTreeDecoder::readNode(
298+
bool CovTreeDecoder::readNode(
299299
Defect *def,
300-
const pt::ptree &defNode)
300+
pt::ptree::const_iterator defIter)
301301
{
302-
// make sure the Defect structure is properly initialized
303-
(*def) = Defect();
302+
const pt::ptree &defNode = defIter->second;
304303

305304
// read per-defect properties
306305
def->checker = defNode.get<std::string>("checkerName");
@@ -337,4 +336,6 @@ void CovTreeDecoder::readNode(
337336

338337
// initialize verbosity level of all events
339338
this->keDigger.initVerbosity(def);
339+
340+
return true;
340341
}

0 commit comments

Comments
 (0)