2009-06-25 07:16:22 -07:00
|
|
|
|
/*
|
|
|
|
|
* 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 {
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 固有ID付きのVsqEventのリストを取り扱う
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class VsqEventList {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public List<VsqEvent> Events;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
private List<int> m_ids;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// コンストラクタ
|
|
|
|
|
/// </summary>
|
|
|
|
|
public VsqEventList() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
Events = new List<VsqEvent>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
m_ids = new List<int>();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public void sort() {
|
|
|
|
|
lock ( this ) {
|
|
|
|
|
Events.Sort();
|
|
|
|
|
for ( int i = 0; i < Events.Count; i++ ) {
|
|
|
|
|
m_ids[i] = Events[i].InternalID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
public void clear() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
Events.Clear();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
m_ids.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Iterator iterator() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
updateIDList();
|
|
|
|
|
return new ListIterator<VsqEvent>( Events );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void add( VsqEvent item ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
updateIDList();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int new_id = getNextId( 0 );
|
|
|
|
|
item.InternalID = new_id;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
Events.Add( item );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
m_ids.Add( new_id );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
Events.Sort();
|
|
|
|
|
for ( int i = 0; i < Events.Count; i++ ) {
|
|
|
|
|
m_ids[i] = Events[i].InternalID;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeAt( int index ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
updateIDList();
|
|
|
|
|
Events.RemoveAt( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
m_ids.RemoveAt( index );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getNextId( int next ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
updateIDList();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int index = -1;
|
|
|
|
|
List<int> current = new List<int>( 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() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return Events.Count;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VsqEvent getElement( int index ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return Events[index];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setElement( int index, VsqEvent value ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
Events[index] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateIDList() {
|
|
|
|
|
if ( m_ids.Count != Events.Count ) {
|
|
|
|
|
m_ids.Clear();
|
|
|
|
|
for ( int i = 0; i < Events.Count; i++ ) {
|
|
|
|
|
m_ids.Add( Events[i].InternalID );
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|