/**
 * Copyright(c) Live2D Inc. All rights reserved.
 *
 * Use of this source code is governed by the Live2D Open Software license
 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
 */ import { CubismLogDebug } from '../utils/cubismdebug' ; /**
 * Key-Valueのペアを定義するクラス
 * csmMapクラスの内部データで使用する。
 */ export class csmPair < _KeyT , _ValT > { param key param value public constructor ( key ? , value ? ) { this . first = key == undefined ? null : key ; this . second = value == undefined ? null : value ; } public first : _KeyT ; public second : _ValT ; } /**
 * マップ型
 */ export class csmMap < _KeyT , _ValT > { param size public constructor ( size ? ) { if ( size != undefined ) { if ( size < 1 ) { this . _keyValues = [ ] ; this . _dummyValue = null ; this . _size = 0 ; } else { this . _keyValues = new Array ( size ) ; this . _size = size ; } } else { this . _keyValues = [ ] ; this . _dummyValue = null ; this . _size = 0 ; } } /**
     * デストラクタ
     */ public release ( ) { this . clear ( ) ; } param key public appendKey ( key ) { this . prepareCapacity ( this . _size + 1 , false ) ; this . _keyValues [ this . _size ] = new csmPair < _KeyT , _ValT > ( key ) ; this . _size += 1 ; } param key public getValue ( key ) { let found = - 1 ; for ( let i = 0 ; i < this . _size ; i ++ ) { if ( this . _keyValues [ i ] . first == key ) { found = i ; break ; } } if ( found >= 0 ) { return this . _keyValues [ found ] . second ; } else { this . appendKey ( key ) ; return this . _keyValues [ this . _size - 1 ] . second ; } } param key param value public setValue ( key , value ) { let found = - 1 ; for ( let i = 0 ; i < this . _size ; i ++ ) { if ( this . _keyValues [ i ] . first == key ) { found = i ; break ; } } if ( found >= 0 ) { this . _keyValues [ found ] . second = value ; } else { this . appendKey ( key ) ; this . _keyValues [ this . _size - 1 ] . second = value ; } } param key return return public isExist ( key ) { for ( let i = 0 ; i < this . _size ; i ++ ) { if ( this . _keyValues [ i ] . first == key ) { return true ; } } return false ; } /**
     * keyValueのポインタを全て解放する
     */ public clear ( ) { this . _keyValues = void 0 ; this . _keyValues = null ; this . _keyValues = [ ] ; this . _size = 0 ; } return public getSize ( ) { return this . _size ; } param newSize param fitToSize public prepareCapacity ( newSize , fitToSize ) { if ( newSize > this . _keyValues . length ) { if ( this . _keyValues . length == 0 ) { if ( ! fitToSize && newSize < csmMap . DefaultSize ) newSize = csmMap . DefaultSize ; this . _keyValues . length = newSize ; } else { if ( ! fitToSize && newSize < this . _keyValues . length * 2 ) newSize = this . _keyValues . length * 2 ; this . _keyValues . length = newSize ; } } } /**
     * コンテナの先頭要素を返す
     */ public begin ( ) { const ite = new iterator < _KeyT , _ValT > ( this , 0 ) ; return ite ; } /**
     * コンテナの終端要素を返す
     */ public end ( ) { const ite = new iterator < _KeyT , _ValT > ( this , this . _size ) ; return ite ; } param ite public erase ( ite ) { const index = ite . _index ; if ( index < 0 || this . _size <= index ) { return ite ; } this . _keyValues . splice ( index , 1 ) ; -- this . _size ; const ite2 = new iterator < _KeyT , _ValT > ( this , index ) ; return ite2 ; } /**
     * コンテナの値を32ビット符号付き整数型でダンプする
     */ public dumpAsInt ( ) { for ( let i = 0 ; i < this . _size ; i ++ ) { CubismLogDebug ( '{0} ,' , this . _keyValues [ i ] ) ; CubismLogDebug ( '\n' ) ; } } public static readonly DefaultSize = 10 ; public _keyValues : csmPair < _KeyT , _ValT > [ ] ; public _dummyValue : _ValT ; public _size : number ; } /**
 * csmMap<T>のイテレータ
 */ export class iterator < _KeyT , _ValT > { /**
     * コンストラクタ
     */ constructor ( v ? , idx ? ) { this . _map = v != undefined ? v : new csmMap < _KeyT , _ValT > ( ) ; this . _index = idx != undefined ? idx : 0 ; } /**
     * =演算子のオーバーロード
     */ public set ( ite ) { this . _index = ite . _index ; this . _map = ite . _map ; return this ; } /**
     * 前置き++演算子のオーバーロード
     */ public preIncrement ( ) { ++ this . _index ; return this ; } /**
     * 前置き--演算子のオーバーロード
     */ public preDecrement ( ) { -- this . _index ; return this ; } /**
     * 後置き++演算子のオーバーロード
     */ public increment ( ) { const iteold = new iterator < _KeyT , _ValT > ( this . _map , this . _index ++ ) ; return iteold ; } /**
     * 後置き--演算子のオーバーロード
     */ public decrement ( ) { const iteold = new iterator < _KeyT , _ValT > ( this . _map , this . _index ) ; this . _map = iteold . _map ; this . _index = iteold . _index ; return this ; } /**
     * *演算子のオーバーロード
     */ public ptr ( ) { return this . _map . _keyValues [ this . _index ] ; } /**
     * !=演算
     */ public notEqual ( ite ) { return this . _index != ite . _index || this . _map != ite . _map ; } _index : number ; _map : csmMap < _KeyT , _ValT > ; } import * as $ from './csmmap' ; export namespace Live2DCubismFramework { export const csmMap = $ . csmMap ; export type csmMap < K , V > = $ . csmMap < K , V > ; export const csmPair = $ . csmPair ; export type csmPair < K , V > = $ . csmPair < K , V > ; export const iterator = $ . iterator ; export type iterator < K , V > = $ . iterator < K , V > ; }