You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CFGFileParser.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ©2008-2017 despair <despair@netrunner.cc>
  2. #ifndef __CFGFILEPARSER_H__
  3. #define __CFGFILEPARSER_H__
  4. #include "netrunner.h"
  5. #include <sys/stat.h>
  6. #include <cstdint>
  7. // Class which holds the parsed configuration options after
  8. // being processed by CFGFileParser. No longer a "trivial class"
  9. // just select by cfg->GlobalSettings....
  10. struct BrowserConfiguration{
  11. ntr::stringmap Settings;
  12. // fast allocation!
  13. static void* operator new(std::size_t n){
  14. if (void *mem = tlsf_malloc(n)) {
  15. return mem;
  16. } throw std::bad_alloc {};
  17. }
  18. static void operator delete(void *p) {
  19. tlsf_free(p);
  20. }
  21. void clear();
  22. };
  23. class CFGFileParser {
  24. public:
  25. // Opens config from external file.
  26. CFGFileParser(const char* filename);
  27. // Opens config from memory.
  28. CFGFileParser(ntr::fast_string in_buf);
  29. ~CFGFileParser();
  30. bool ParseText();
  31. void WriteConfig(BrowserConfiguration &config);
  32. static void* operator new(std::size_t n) {
  33. if (void *mem = tlsf_malloc(n)){
  34. return mem;
  35. } throw std::bad_alloc {};
  36. }
  37. static void operator delete(void *p) {
  38. tlsf_free(p);
  39. }
  40. private:
  41. FILE *cfg_file;
  42. char *buffer;
  43. struct stat *cfg_fileinfo = reinterpret_cast<struct stat*>(tlsf_malloc(sizeof(struct stat)));
  44. BrowserConfiguration *cfg = new BrowserConfiguration();
  45. size_t bytesRead;
  46. };
  47. #endif // __CFGFILEPARSER_H__