1 #include <msp/io/seekable.h>
2 #include "modulecache.h"
12 ModuleCache::ModuleCache(DataFile::Collection *r):
17 ModuleCache::ModuleCache(const ModuleCache &other)
19 for(const auto &kvp: other.modules)
20 modules[kvp.first] = new Module(*kvp.second);
23 ModuleCache &ModuleCache::operator=(const ModuleCache &other)
25 for(auto &kvp: modules)
28 for(const auto &kvp: other.modules)
29 modules[kvp.first] = new Module(*kvp.second);
33 ModuleCache::~ModuleCache()
35 for(auto &kvp: modules)
39 const Module &ModuleCache::add_module(const string &source, const string &src_name)
41 RefPtr<Module> module = new Module;
43 unsigned src_index = next_source++;
44 parser.parse(*module, source, src_name, src_index);
45 return *(modules[src_name] = module.release());
48 const Module &ModuleCache::add_module(IO::Base &io, const string &src_name)
50 RefPtr<Module> module = new Module;
52 unsigned src_index = next_source++;
53 parser.parse(*module, io, src_name, src_index);
54 return *(modules[src_name] = module.release());
57 const Module &ModuleCache::get_module(const string &name)
59 string fn = name+".glsl";
60 auto i = modules.find(fn);
64 RefPtr<IO::Seekable> io = (resources ? resources->open_raw(fn) : Resources::get_builtins().open(fn));
66 throw runtime_error(format("module %s not found", name));
68 return add_module(*io, fn);