KindConfig.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef Kind_CONFIG_H
  2. #define Kind_CONFIG_H
  3. #include <map>
  4. #include <string>
  5. #include "Strings.h"
  6. #include "stringtools.h"
  7. #include "filetools.h"
  8. class KindConfig
  9. {
  10. public:
  11. KindConfig() {}
  12. KindConfig(const std::string& fn);
  13. void addFile(const std::string& fn);
  14. int addOneFile(const std::vector<std::string>& fns);
  15. void addString(const std::string& key, const std::string& value)
  16. {
  17. settings[key].push_back(value);
  18. }
  19. void setBool(const std::string& key, bool value)
  20. {
  21. settings[key].resize(1);
  22. settings[key][0] = value ? "true" : "false";
  23. }
  24. void setString(const std::string& key, const std::string& value)
  25. {
  26. settings[key].resize(1);
  27. settings[key][0] = value;
  28. }
  29. bool hasKey(std::string key) const;
  30. std::string getString(std::string key) const;
  31. Strings getStrings(std::string key) const;
  32. bool getBool(std::string key) const;
  33. void print(const std::string& prefix = "") const;
  34. void warnUnused(const std::string& prefix = "") const;
  35. private:
  36. void split(const std::string& line,
  37. std::string& key,
  38. std::string& del,
  39. std::string& value);
  40. std::map<std::string, Strings> settings;
  41. mutable std::map<std::string, bool> used;
  42. };
  43. #endif