config_file.h 725 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef __CONFIG_FILE_HPP_
  2. #define __CONFIG_FILE_HPP_
  3. #include <iostream>
  4. #include <map>
  5. #include <set>
  6. #include <vector>
  7. #include <string.h>
  8. struct cchar_cmp
  9. {
  10. bool operator()(const char*l,const char*r)const
  11. {
  12. return strcmp(l,r)<0;
  13. }
  14. };
  15. struct config_file
  16. {
  17. private:
  18. std::vector<char> _buf;
  19. std::map<const char*,const char*,cchar_cmp> _map;
  20. config_file(const config_file&)=delete;
  21. public:
  22. config_file (){}
  23. ~config_file(){}
  24. int open(const char*fname);
  25. const char* get(const char*key,const char*v);
  26. const char* get(const char*sec,const char*key,const char*v);
  27. std::set<const char*> keys();
  28. bool contains(const char*k);
  29. bool contains(const char*sec,const char*k);
  30. void print(std::ostream&o);
  31. };
  32. #endif