fork download
  1. #ifndef FileResourceCache_HPP
  2. #define FileResourceCache_HPP
  3.  
  4. #include <map>
  5. #include <string>
  6. #include <memory>
  7. #include <stdexcept>
  8. #include <sstream>
  9.  
  10. template <class T> class FileResourceCache {
  11. public:
  12. FileResourceCache<T>(std::string dir) : base_dir(dir) {
  13. }
  14. T& operator[](std::string name) {
  15. std::string old = name;
  16. std::stringstream new_ss;
  17. new_ss << base_dir;
  18. new_ss << name;
  19. name = new_ss.string();
  20. if(resources.find(name) == resources.end()) {
  21. T* i = load_from_file(name);
  22. if(i) {
  23. resources[name].reset(i);
  24. return *resources[name];
  25. else {
  26. std::stringstream ss;
  27. ss << "Resource ";
  28. ss << name;
  29. ss << " does not exist in ";
  30. ss << base_dir;
  31. throw std::runtime_error(ss.string());
  32. }
  33. } else {
  34. return *resources[name];
  35. }
  36. }
  37.  
  38. private:
  39. std::string base_dir;
  40. std::map<std::string, std::unique_ptr<T, decltype(std::bind(&T::drop))>> resources;
  41.  
  42. virtual T* load_from_file(std::string file) = 0;
  43. //return driver->createImageFromFile(name);
  44. //return smgr->getMesh(name);
  45.  
  46. }
  47.  
  48. #endif
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:46:1: error: expected '}' at end of input
prog.cpp: In constructor 'FileResourceCache<T>::FileResourceCache(std::string)':
prog.cpp:12:43: error: class 'FileResourceCache<T>' does not have any field named 'base_dir'
prog.cpp: In member function 'T& FileResourceCache<T>::operator[](std::string)':
prog.cpp:17:14: error: 'base_dir' was not declared in this scope
prog.cpp:19:18: error: 'struct std::stringstream' has no member named 'string'
prog.cpp:20:7: error: 'resources' was not declared in this scope
prog.cpp:21:31: error: there are no arguments to 'load_from_file' that depend on a template parameter, so a declaration of 'load_from_file' must be available
prog.cpp:21:31: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
prog.cpp:25:5: error: expected '}' before 'else'
prog.cpp:31:34: error: 'struct std::stringstream' has no member named 'string'
prog.cpp: At global scope:
prog.cpp:36:3: error: expected unqualified-id at end of input
stdout
Standard output is empty