config_file.h 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. int get(const char*key,int default_v)const;
  26. int get(const char*sec,const char*key,int default_v)const;
  27. double get(const char*key,double default_v)const;
  28. double get(const char*sec,const char*key,double default_v)const;
  29. const char* get(const char*key,const char*default_v)const;
  30. const char* get(const char*sec,const char*key,const char*default_v)const;
  31. std::set<const char*> keys()const;
  32. bool contains(const char*k)const ;
  33. bool contains(const char*sec,const char*k)const;
  34. void print(std::ostream&o);
  35. };
  36. #endif