Sarafun Behavior Trees package  1
Behavior trees for the SARAFun project
 All Data Structures Namespaces Functions Variables Enumerations Enumerator
parse_tree.h
1 #ifndef __PARSE_TREE__
2 #define __PARSE_TREE__
3 
4 #include <fstream>
5 #include <json/json.hpp>
6 #include <behavior_tree_core/BehaviorTree.h>
7 #include <ros/package.h>
8 
9 using json = nlohmann::json;
10 
11 namespace bt_parser {
12 
17 class Parser {
18 public:
22  Parser(std::string filepath);
23  ~Parser();
24 
25  /*
26  Parses the JSON tree description.
27 
28  @return A pointer to the tree root.
29  @throw logic_error
30  */
31  BT::TreeNode *parseTree();
32 
33 private:
34  std::ifstream file_;
35  json tree_j_;
36  std::string current_id_;
37 
38  /*
39  Parses a subtree of the JSON description.
40 
41  @param node A json node object with a subtree to be parsed.
42  @return A pointer to the subtree root.
43  @throw logic_error
44  */
45  BT::TreeNode *parseTree(json node);
46 
53  void verifyNode(json node);
54 };
55 }
56 #endif
void verifyNode(json node)
Definition: parse_tree.cpp:8
BT::TreeNode * parseTree()
Definition: parse_tree.cpp:29
std::string current_id_
Definition: parse_tree.h:36
std::ifstream file_
Definition: parse_tree.h:34
Parser(std::string filepath)
Definition: parse_tree.cpp:5