| 1 | /*! |
| 2 | * VisualEditor FlatLinearData classes. |
| 3 | * |
| 4 | * Class containing Flat linear data and a hash-value store. |
| 5 | * |
| 6 | * @copyright See AUTHORS.txt |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Flat linear data storage |
| 11 | * |
| 12 | * @class |
| 13 | * @extends ve.dm.LinearData |
| 14 | * @constructor |
| 15 | * @param {ve.dm.HashValueStore} store Hash-value store |
| 16 | * @param {Array} [data] Linear data |
| 17 | */ |
| 18 | ve.dm.FlatLinearData = function VeDmFlatLinearData() { |
| 19 | // Parent constructor |
| 20 | ve.dm.FlatLinearData.super.apply( this, arguments ); |
| 21 | }; |
| 22 | |
| 23 | /* Inheritance */ |
| 24 | |
| 25 | OO.inheritClass( ve.dm.FlatLinearData, ve.dm.LinearData ); |
| 26 | |
| 27 | /* Methods */ |
| 28 | |
| 29 | /** |
| 30 | * Get the type of the element at a specified offset. |
| 31 | * |
| 32 | * @param {number} offset Data offset |
| 33 | * @return {string} Type of the element |
| 34 | */ |
| 35 | ve.dm.FlatLinearData.prototype.getType = function ( offset ) { |
| 36 | return ve.dm.LinearData.static.getType( this.getData( offset ) ); |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * Check if data at a given offset is an element. |
| 41 | * |
| 42 | * @param {number} offset Data offset |
| 43 | * @return {boolean} Data at offset is an element |
| 44 | */ |
| 45 | ve.dm.FlatLinearData.prototype.isElementData = function ( offset ) { |
| 46 | return ve.dm.LinearData.static.isElementData( this.getData( offset ) ); |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * Check for elements in data. |
| 51 | * |
| 52 | * This method assumes that any value that has a type property that's a string is an element object. |
| 53 | * Elements are discovered by iterating through the entire data array (backwards). |
| 54 | * |
| 55 | * @return {boolean} At least one elements exists in data |
| 56 | */ |
| 57 | ve.dm.FlatLinearData.prototype.containsElementData = function () { |
| 58 | let i = this.getLength(); |
| 59 | while ( i-- ) { |
| 60 | if ( this.isElementData( i ) ) { |
| 61 | return true; |
| 62 | } |
| 63 | } |
| 64 | return false; |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * Checks if data at a given offset is an open element. |
| 69 | * |
| 70 | * @param {number} offset Data offset |
| 71 | * @return {boolean} Data at offset is an open element |
| 72 | */ |
| 73 | ve.dm.FlatLinearData.prototype.isOpenElementData = function ( offset ) { |
| 74 | return ve.dm.LinearData.static.isOpenElementData( this.getData( offset ) ); |
| 75 | }; |
| 76 | |
| 77 | /** |
| 78 | * Checks if data at a given offset is a close element. |
| 79 | * |
| 80 | * @param {number} offset Data offset |
| 81 | * @return {boolean} Data at offset is a close element |
| 82 | */ |
| 83 | ve.dm.FlatLinearData.prototype.isCloseElementData = function ( offset ) { |
| 84 | return ve.dm.LinearData.static.isCloseElementData( this.getData( offset ) ); |
| 85 | }; |