UNPKG

molstar

Version:

A comprehensive macromolecular library.

52 lines (51 loc) 2.04 kB
"use strict"; /** * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.FixedColumn = exports.FixedColumnProvider = void 0; var db_1 = require("../../../../../mol-data/db"); var tokenizer_1 = require("../tokenizer"); var number_parser_1 = require("../number-parser"); function FixedColumnProvider(lines) { return function (offset, width, type) { return FixedColumn(lines, offset, width, type); }; } exports.FixedColumnProvider = FixedColumnProvider; function FixedColumn(lines, offset, width, schema) { var data = lines.data, indices = lines.indices, rowCount = lines.count; var type = schema.valueType; var value = type === 'str' ? function (row) { var s = indices[2 * row] + offset, le = indices[2 * row + 1]; if (s >= le) return ''; var e = s + width; if (e > le) e = le; return (0, tokenizer_1.trimStr)(data, s, e); } : type === 'int' ? function (row) { var s = indices[2 * row] + offset; if (s > indices[2 * row + 1]) return 0; return (0, number_parser_1.parseIntSkipLeadingWhitespace)(data, s, s + width); } : function (row) { var s = indices[2 * row] + offset; if (s > indices[2 * row + 1]) return 0; return (0, number_parser_1.parseFloatSkipLeadingWhitespace)(data, s, s + width); }; return { schema: schema, __array: void 0, isDefined: true, rowCount: rowCount, value: value, valueKind: function (row) { return 0 /* Column.ValueKind.Present */; }, toArray: function (params) { return db_1.ColumnHelpers.createAndFillArray(rowCount, value, params); }, areValuesEqual: function (rowA, rowB) { return value(rowA) === value(rowB); } }; } exports.FixedColumn = FixedColumn;