/****************************************************************************** libx42.net - skinned vertex animation library (.NET API) Copyright (C) 2007 HermitWorks Entertainment Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA. ******************************************************************************/ #pragma once namespace Libx42 { generic< typename T > public ref class BasicCollection abstract : public Collections::Generic::IList< T >, public Collections::IList { public: property T default[int] { [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual T get( int index ) abstract; //protected: //vc05 bug - can't make this private [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void set( int, T ) = Collections::Generic::IList< T >::default::set { throw gcnew NotSupportedException(); } } virtual int IndexOf( T item ) { for( int i = 0; i < Count; i++ ) if( Collections::Generic::Comparer< T >::Default->Compare( this[i], item ) ) return i; return -1; } property int Count { virtual int get( void ) abstract; } virtual bool Contains( T item ) { return IndexOf( item ) != -1; } ref class Enumerator : Collections::Generic::IEnumerator< T > { public: virtual bool MoveNext( void ) sealed { int count = owner->Count; if( index == count ) return false; index++; return index < count; } virtual void Reset( void ) sealed { index = -1; } property T Current { virtual T get( void ) sealed { return owner[index]; } } private: property Object^ Current2 { virtual Object^ get( void ) sealed = Collections::IEnumerator::Current::get { return owner[index]; } } internal: Enumerator( BasicCollection< T > ^owner ) : owner( owner ), index( -1 ) { } private: int index; BasicCollection< T > ^owner; ~Enumerator( void ) { } }; virtual Collections::Generic::IEnumerator< T >^ GetEnumerator( void ) { return gcnew Enumerator( this ); } virtual void CopyTo( array< T >^ array, int arrayIndex ) { for( int i = 0; i < Count; i++ ) array[arrayIndex + i] = this[i]; } virtual array< T >^ ToArray( void ) { array< T >^ ret = gcnew array< T >( Count ); for( int i = 0; i < ret->Length; i++ ) ret[i] = this[i]; return ret; } public: //vc05 bug prevents me from making these truly private... [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual int Add2( Object^ ) sealed = Collections::IList::Add { throw gcnew NotSupportedException; } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void Insert2( int, Object^ ) sealed = Collections::IList::Insert { throw gcnew NotSupportedException; } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual bool Contains2( Object ^item ) sealed = Collections::IList::Contains { try { return Contains( safe_cast< T >( item ) ); } catch( InvalidCastException^ ) { return false; } } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual int IndexOf2( Object ^item ) sealed = Collections::IList::IndexOf { try { return IndexOf( safe_cast< T >( item ) ); } catch( InvalidCastException^ ) { return -1; } } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void Remove( Object^ ) sealed = Collections::IList::Remove { throw gcnew NotSupportedException(); } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual bool get_IsFixedSize2( void ) sealed = Collections::IList::IsFixedSize::get { return true; } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual Object^ get_Item2( int index ) sealed = Collections::IList::default::get { return default[index]; } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void set_Item2( int index, Object ^item ) sealed = Collections::IList::default::set { try { default[index] = safe_cast< T >( item ); } catch( InvalidCastException^ ) { throw gcnew ArgumentException(); } } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void CopyTo2( Array ^array, int index ) sealed = Collections::ICollection::CopyTo { try { CopyTo( safe_cast< cli::array< T >^ >( array ), index ); } catch( InvalidCastException^ ) { throw gcnew InvalidCastException; } } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual Object^ get_SyncRoot2( void ) sealed = Collections::ICollection::SyncRoot::get { return this; } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual bool get_IsSynchronized2( void ) sealed = Collections::ICollection::IsSynchronized::get { return false; } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void Insert( int, T ) sealed = Collections::Generic::IList< T >::Insert { throw gcnew NotSupportedException(); } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void Add( T ) sealed = Collections::Generic::ICollection< T >::Add { throw gcnew NotSupportedException(); } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void Clear( void ) sealed = Collections::Generic::ICollection< T >::Clear { throw gcnew NotSupportedException(); } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual bool Remove( T ) sealed = Collections::Generic::ICollection< T >::Remove { throw gcnew NotSupportedException(); } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] virtual void RemoveAt( int ) sealed = Collections::Generic::IList< T >::RemoveAt, Collections::IList::RemoveAt { throw gcnew NotSupportedException(); } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Never )] property bool IsReadOnly { virtual bool get( void ) sealed = Collections::Generic::ICollection< T >::IsReadOnly::get, Collections::IList::IsReadOnly::get { return true; } } private: virtual Collections::IEnumerator^ _GetEnumerator( void ) sealed = Collections::IEnumerable::GetEnumerator { return GetEnumerator(); } internal: BasicCollection( void ) { } }; };