Created
April 13, 2018 07:19
-
-
Save benjaminalt/af3e2a4b3dc5ecef34bf2a40b7bfa01f to your computer and use it in GitHub Desktop.
Print a boost::property_tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::string indent(int level) | |
| { | |
| std::string s; | |
| for (int i = 0; i<level; i++) s += " "; | |
| return s; | |
| } | |
| void printTree(boost::property_tree::ptree &pt, int level) | |
| { | |
| if (pt.empty()) | |
| { | |
| std::cout << "\"" << pt.data() << "\""; | |
| } | |
| else | |
| { | |
| if (level) std::cout << std::endl; | |
| std::cout << indent(level) << "{" << std::endl; | |
| for (boost::property_tree::ptree::iterator pos = pt.begin(); pos != pt.end();) | |
| { | |
| std::cout << indent(level + 1) << "\"" << pos->first << "\": "; | |
| printTree(pos->second, level + 1); | |
| ++pos; | |
| if (pos != pt.end()) | |
| { | |
| std::cout << ","; | |
| } | |
| std::cout << std::endl; | |
| } | |
| std::cout << indent(level) << " }"; | |
| } | |
| std::cout << std::endl; | |
| return; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment