import { CommandInterface } from '../Commands' ; import * as Constants from '../Constants' ; import { Variables } from './Variables' ; import { Variable } from './Variable' ; import { Matrix } from './Matrix' ; export class Cell extends Matrix { private static CELL_TYPENAME : string = 'cell' ; param name param value param freeIndices param fixedIndices constructor ( name = '' , value = '' , freeIndices = [ ] , fixedIndices = [ ] ) { super ( name , value , freeIndices , fixedIndices , false , Cell . CELL_TYPENAME ) ; } public typename ( ) { return Cell . CELL_TYPENAME ; } public loads ( type ) { return type === this . typename ( ) ; } public createConcreteType ( name , value , freeIndices , fixedIndices , validValue , type ) { return new Cell ( name , value , freeIndices , fixedIndices ) ; } public loadNew ( name , type , runtime , callback ) { Variables . getSize ( name , runtime , ( size ) => { const value = size . join ( Constants . SIZE_SEPARATOR ) ; const cell = this . createConcreteType ( name , value , size , [ ] , false , type ) ; callback ( cell ) ; } ) ; } public loacChild ( runtime , freeIndices , fixedIndices , callback ) { if ( freeIndices . length === 0 ) { const name = this . makeName ( this . basename ( ) , freeIndices , fixedIndices , Constants . CELL_LEFT , Constants . CELL_RIGHT ) ; Variables . loadVariable ( name , runtime , callback ) ; } else { const cell = this . createConcreteType ( this . basename ( ) , '' , freeIndices , fixedIndices , false , Cell . CELL_TYPENAME ) ; callback ( cell ) ; } } public loadChildrenRange ( runtime , offset , count , callback ) { const vars = new Array < Variable > ( ) ; const freeIndices = this . freeIndices ( ) ; const fixedIndices = this . fixedIndices ( ) ; const childrenFreeIndices = freeIndices . slice ( 0 , freeIndices . length - 1 ) ; for ( let i = 0 ; i !== count ; ++ i ) { const childFixedIndices = [ i + offset + 1 ] . concat ( fixedIndices ) ; this . loacChild ( runtime , childrenFreeIndices , childFixedIndices , ( v ) => { vars . push ( v ) ; if ( vars . length === count ) { callback ( vars ) ; } } ) ; } } }