1 #include <msp/io/seekable.h>
2 #include "modulecache.h"
12 ModuleCache::ModuleCache(DataFile::Collection *r):
17 ModuleCache::ModuleCache(const ModuleCache &other)
19 for(map<string, Module *>::const_iterator i=other.modules.begin(); i!=other.modules.end(); ++i)
20 modules[i->first] = new Module(*i->second);
23 ModuleCache &ModuleCache::operator=(const ModuleCache &other)
25 for(map<string, Module *>::iterator i=modules.begin(); i!=modules.end(); ++i)
28 for(map<string, Module *>::const_iterator i=other.modules.begin(); i!=other.modules.end(); ++i)
29 modules[i->first] = new Module(*i->second);
33 ModuleCache::~ModuleCache()
35 for(map<string, Module *>::iterator i=modules.begin(); i!=modules.end(); ++i)
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 map<string, Module *>::const_iterator 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);