Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Json::print(any _data) {
- string type = _data.type().name();
- try {
- if (type == "i") {
- cout << any_cast<int> (_data);
- }
- else if (type == "d") {
- cout << any_cast<double> (_data);
- }
- else if (type == "b") {
- if (any_cast<bool> (_data)) std::cout << "true";
- else cout << "false";
- }
- else if (type == "Ss" || type == "NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE") {
- cout << any_cast<string> (_data);
- }
- else if (type.find("St6vector") < type.length()) {
- std::vector <std::any> vec;
- vec = any_cast<vector<any>>(_data);
- unsigned int count = 0;
- cout << "[ ";
- for (const auto& c : vec) {
- count++;
- if (count > 1) std::cout << " , ";
- print(c);
- }
- cout << " ]";
- }
- else if (type.find("St3map") < type.length()) {
- map <string, any> _map;
- _map = std::any_cast<map <string, any>>(_data);
- cout << "{\n" ;
- unsigned int count = 0;
- for (const auto& c: _map) {
- count++;
- if (count > 1) cout << " ,\n";
- cout << "\t" << c.first << " : ";
- print(c.second);
- }
- cout << "\n\t}";
- }
- }
- catch(const std::bad_any_cast& e) {
- cout << e.what() << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment