molstar
Version:
A comprehensive macromolecular library.
137 lines • 5.83 kB
JavaScript
/**
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { BuiltInTrajectoryFormats } from './trajectory';
import { BuiltInVolumeFormats } from './volume';
import { BuiltInShapeFormats } from './shape';
import { BuiltInStructureFormats } from './structure';
var DataFormatRegistry = /** @class */ (function () {
function DataFormatRegistry() {
this._list = [];
this._map = new Map();
this._extensions = undefined;
this._binaryExtensions = undefined;
this._options = undefined;
for (var _i = 0, BuiltInVolumeFormats_1 = BuiltInVolumeFormats; _i < BuiltInVolumeFormats_1.length; _i++) {
var _a = BuiltInVolumeFormats_1[_i], id = _a[0], p = _a[1];
this.add(id, p);
}
for (var _b = 0, BuiltInStructureFormats_1 = BuiltInStructureFormats; _b < BuiltInStructureFormats_1.length; _b++) {
var _c = BuiltInStructureFormats_1[_b], id = _c[0], p = _c[1];
this.add(id, p);
}
for (var _d = 0, BuiltInShapeFormats_1 = BuiltInShapeFormats; _d < BuiltInShapeFormats_1.length; _d++) {
var _e = BuiltInShapeFormats_1[_d], id = _e[0], p = _e[1];
this.add(id, p);
}
for (var _f = 0, BuiltInTrajectoryFormats_1 = BuiltInTrajectoryFormats; _f < BuiltInTrajectoryFormats_1.length; _f++) {
var _g = BuiltInTrajectoryFormats_1[_f], id = _g[0], p = _g[1];
this.add(id, p);
}
}
Object.defineProperty(DataFormatRegistry.prototype, "types", {
get: function () {
return this._list.map(function (e) { return [e.name, e.provider.label]; });
},
enumerable: false,
configurable: true
});
Object.defineProperty(DataFormatRegistry.prototype, "extensions", {
get: function () {
if (this._extensions)
return this._extensions;
var extensions = new Set();
this._list.forEach(function (_a) {
var _b, _c;
var provider = _a.provider;
(_b = provider.stringExtensions) === null || _b === void 0 ? void 0 : _b.forEach(function (ext) { return extensions.add(ext); });
(_c = provider.binaryExtensions) === null || _c === void 0 ? void 0 : _c.forEach(function (ext) { return extensions.add(ext); });
});
this._extensions = extensions;
return extensions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DataFormatRegistry.prototype, "binaryExtensions", {
get: function () {
if (this._binaryExtensions)
return this._binaryExtensions;
var binaryExtensions = new Set();
this._list.forEach(function (_a) {
var _b;
var provider = _a.provider;
return (_b = provider.binaryExtensions) === null || _b === void 0 ? void 0 : _b.forEach(function (ext) { return binaryExtensions.add(ext); });
});
this._binaryExtensions = binaryExtensions;
return binaryExtensions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DataFormatRegistry.prototype, "options", {
get: function () {
if (this._options)
return this._options;
var options = [];
this._list.forEach(function (_a) {
var name = _a.name, provider = _a.provider;
return options.push([name, provider.label, provider.category || '']);
});
this._options = options;
return options;
},
enumerable: false,
configurable: true
});
;
DataFormatRegistry.prototype._clear = function () {
this._extensions = undefined;
this._binaryExtensions = undefined;
this._options = undefined;
};
DataFormatRegistry.prototype.add = function (name, provider) {
this._clear();
this._list.push({ name: name, provider: provider });
this._map.set(name, provider);
};
DataFormatRegistry.prototype.remove = function (name) {
this._clear();
this._list.splice(this._list.findIndex(function (e) { return e.name === name; }), 1);
this._map.delete(name);
};
DataFormatRegistry.prototype.auto = function (info, dataStateObject) {
for (var i = 0, il = this.list.length; i < il; ++i) {
var provider = this._list[i].provider;
var hasExt = false;
if (provider.binaryExtensions && provider.binaryExtensions.indexOf(info.ext) >= 0)
hasExt = true;
else if (provider.stringExtensions && provider.stringExtensions.indexOf(info.ext) >= 0)
hasExt = true;
if (hasExt && (!provider.isApplicable || provider.isApplicable(info, dataStateObject.data)))
return provider;
}
return;
};
DataFormatRegistry.prototype.get = function (name) {
if (this._map.has(name)) {
return this._map.get(name);
}
else {
throw new Error("unknown data format name '" + name + "'");
}
};
Object.defineProperty(DataFormatRegistry.prototype, "list", {
get: function () {
return this._list;
},
enumerable: false,
configurable: true
});
return DataFormatRegistry;
}());
export { DataFormatRegistry };
//# sourceMappingURL=registry.js.map