JsonParser.h 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #include <boost/algorithm/string/predicate.hpp>
  2. #include <boost/algorithm/string.hpp>
  3. #include <boost/property_tree/ptree.hpp>
  4. #include <boost/property_tree/json_parser.hpp>
  5. #include <iostream>
  6. #include <string>
  7. #include <map>
  8. class JsonParser {
  9. public:
  10. JsonParser(const std::string &filename);
  11. std::string getValue(const std::string &path) const {
  12. auto it = values.find(path);
  13. if (it != values.end()) {
  14. return it->second;
  15. }
  16. return "";
  17. }
  18. static bool convertStringToUnsignedChar(const std::string& str, unsigned char& result);
  19. static bool convertStringToUnsignedShort(const std::string& str, unsigned short& result);
  20. static bool convertStringToUnsignedInt(const std::string& str, unsigned int& result);
  21. static bool convertStringToUnsignedLong(const std::string& str, unsigned long& result);
  22. bool IsLoaded() { return is_loaded; }
  23. private:
  24. boost::property_tree::ptree pt;
  25. std::map<std::string, std::string> values;
  26. void parseTree(const boost::property_tree::ptree &tree, const std::string &path);
  27. bool is_loaded;
  28. };