/*
* VsqEventList.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.Vsq.
*
* Boare.Lib.Vsq is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.Vsq is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Collections.Generic;
namespace Boare.Lib.Vsq {
///
/// 固有ID付きのVsqEventのリストを取り扱う
///
[Serializable]
public class VsqEventList {
private List m_list;
private List m_ids;
///
/// コンストラクタ
///
public VsqEventList() {
m_list = new List();
m_ids = new List();
}
public void clear() {
m_list.Clear();
m_ids.Clear();
}
public Iterator iterator() {
return new ListIterator( m_list );
}
public void add( VsqEvent item ) {
int new_id = getNextId( 0 );
item.InternalID = new_id;
m_list.Add( item );
m_ids.Add( new_id );
m_list.Sort();
for ( int i = 0; i < m_list.Count; i++ ) {
m_ids[i] = m_list[i].InternalID;
}
}
public void removeAt( int index ) {
m_list.RemoveAt( index );
m_ids.RemoveAt( index );
}
private int getNextId( int next ) {
int index = -1;
List current = new List( m_ids );
int nfound = 0;
while ( true ) {
index++;
if ( !current.Contains( index ) ) {
nfound++;
if ( nfound == next + 1 ) {
return index;
} else {
current.Add( index );
}
}
}
}
public int getCount() {
return m_list.Count;
}
public VsqEvent getElement( int index ) {
return m_list[index];
}
public void setElement( int index, VsqEvent value ) {
m_list[index] = value;
}
}
}