void BuiltinGenerator::begin(const std::string &ns)
{
- if(!namespc.empty() || !filenames.empty())
+ if(!namespc.empty() || !files.empty())
throw logic_error("BuiltinGenerator::begin");
if(!ns.empty())
IO::BufferedFile in(fn);
string base_fn = FS::basename(fn);
- filenames.push_back(base_fn);
+ files.emplace_back();
+ File &file = files.back();
+ file.filename = base_fn;
out.write(format("\nconst char %s_data[] =\n", mangle_filename(base_fn)));
string line;
out.put(';');
out.put('\n');
}
+ file.size += len;
}
}
void BuiltinGenerator::end(const string &module_name)
{
out.write(format("\nvoid init_%s(DataFile::BuiltinSource &source)\n{\n", module_name));
- for(vector<string>::const_iterator i=filenames.begin(); i!=filenames.end(); ++i)
- out.write(format(" source.add_object(\"%s\", %s_data);\n", *i, mangle_filename(*i)));
+ for(vector<File>::const_iterator i=files.begin(); i!=files.end(); ++i)
+ out.write(format(" source.add_object(\"%s\", %s_data, %d);\n", i->filename, mangle_filename(i->filename), i->size));
out.write("}\n");
if(!namespc.empty())
out.write(format("} // namespace %s\n", *i));
namespc.clear();
- filenames.clear();
+ files.clear();
}
}
class BuiltinGenerator
{
private:
+ struct File
+ {
+ std::string filename;
+ std::size_t size = 0;
+ };
+
Msp::IO::Base &out;
std::vector<std::string> namespc;
- std::vector<std::string> filenames;
+ std::vector<File> files;
public:
BuiltinGenerator(Msp::IO::Base &);