Skip to content

Commit 2810ac0

Browse files
committed
abstract-tree: adopt findChildOf() and valueOf()
... from json-parser
1 parent 7b18ec4 commit 2810ac0

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/abstract-tree.hh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,21 @@ class AbstractTreeDecoder {
3535
virtual void readNode(Defect *def, const pt::ptree &node) = 0;
3636
};
3737

38+
template <typename TNode>
39+
bool findChildOf(TNode **pDst, TNode &node, const char *key)
40+
{
41+
if (node.not_found() == node.find(key))
42+
return false;
43+
44+
*pDst = &node.get_child(key);
45+
return true;
46+
}
47+
48+
template <typename T>
49+
inline T valueOf(const pt::ptree &node, const char *path, const T &defVal)
50+
{
51+
const boost::optional<T> &opt = node.get_optional<T>(path);
52+
return opt.get_value_or(defVal);
53+
}
54+
3855
#endif /* H_GUARD_ABSTRACT_TREE_H */

src/json-parser.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,6 @@ void JsonParser::Private::dataError(const std::string &msg)
9797
<< this->defNumber << ": " << msg << "\n";
9898
}
9999

100-
template <typename TNode>
101-
bool findChildOf(TNode **pDst, TNode &node, const char *key)
102-
{
103-
if (node.not_found() == node.find(key))
104-
return false;
105-
106-
*pDst = &node.get_child(key);
107-
return true;
108-
}
109-
110100
JsonParser::JsonParser(InStream &input):
111101
d(new Private(input))
112102
{
@@ -157,13 +147,6 @@ const TScanProps& JsonParser::getScanProps() const
157147
return d->scanProps;
158148
}
159149

160-
template <typename T>
161-
inline T valueOf(const pt::ptree &node, const char *path, const T &defVal)
162-
{
163-
const boost::optional<T> &opt = node.get_optional<T>(path);
164-
return opt.get_value_or(defVal);
165-
}
166-
167150
bool JsonParser::Private::readNext(Defect *def)
168151
{
169152
try {

0 commit comments

Comments
 (0)