add method
Makes compiler the one forBackend answers for its backend, until
the result is cancelled.
Throws a NameTakenException when another compiler for another
backend already writes the same MaterialCompiler.bundleSection: two
backends reading one section would read each other's bytes; for a
section in reservedSections that is not the compiler's backend's;
and for any other section without a dot, which is the engine's to
name later: a compiler from outside writes <package>.<name>.
Implementation
Registration add(MaterialCompiler compiler) {
final section = compiler.bundleSection;
if (reservedSections.containsKey(section) &&
reservedSections[section] != compiler.backend) {
throw NameTakenException(
section,
what: 'the bundle section',
owner: 'the engine',
detail:
'${compiler.backend} names a section of its own; the engine '
'keeps ${reservedSections.keys.join(', ')}',
);
}
if (!reservedSections.containsKey(section) && !section.contains('.')) {
throw NameTakenException(
section,
what: 'the bundle section',
owner: 'the engine',
detail:
'a section without a dot is the engine\'s, now or in a later '
'minor; ${compiler.backend} names its own <package>.<name>',
);
}
for (final other in _compilers) {
if (other.backend != compiler.backend &&
other.bundleSection == compiler.bundleSection) {
throw NameTakenException(
compiler.bundleSection,
what: 'the bundle section',
owner: 'the ${other.backend} compiler',
detail: '${compiler.backend} needs one of its own',
);
}
}
_compilers.add(compiler);
return Registration(() => _compilers.remove(compiler));
}