#pragma once #ifndef _STLP_USE_NEWALLOC #define _STLP_USE_NEWALLOC #endif #ifndef FOR_STL #define FOR_STL( _class, _pointer, _list ) for( _class _pointer = (_list).GetHead(); !(_list).IsEnd(); _pointer = (_list).GetNext() ) #endif #pragma warning( disable : 4786 ) #ifndef STListH #define STListH #include #include #include //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- using namespace std; /******************************************************************************** * ClassName : STList * »ç¿ëÁÖÀÇ : Multi thread ȯ°æ¿¡¼­´Â µ¿±âÈ­ °´Ã¼¸¦ °É¾îÁÖ¾î¾ß ÇÑ´Ù. * *********************************************************************************/ namespace AdoneLibrary { namespace Common { namespace STL { template< class _T > class STList { protected: typedef std::list< _T > ListObject; public: inline void RemoveAll() { ListObject::const_iterator iter_end( m_ListObject.end() ); for ( ListObject::const_iterator iter = m_ListObject.begin(); iter != iter_end; ++iter ) { _T value = ( *iter ); delete value; } m_ListObject.clear(); }; inline void Clear() { m_ListObject.clear(); }; inline bool IsEmpty() { return ( m_ListObject.empty() ); }; inline int Size() { return ( (int)m_ListObject.size() ); }; inline bool IsExist( _T key ) { ListObject::iterator iter = std::find( m_ListObject.begin(), m_ListObject.end(), key ); return ( iter != m_ListObject.end() ); }; inline _T ReversePop() { ListObject::reverse_iterator pIter = m_ListObject.rbegin(); return *pIter; } inline _T Pop() { const static _T returnValue( 0 ); ListObject::iterator iter = m_ListObject.begin(); if ( iter == m_ListObject.end() ) return ( returnValue ); _T element = ( *iter ); m_ListObject.erase( iter ); return ( element ); }; inline void Push( _T Value ) { m_ListObject.push_back( Value ); }; inline void PushFront( _T Value ) { m_ListObject.push_front( Value ); }; inline void PushBack( _T Value ) { m_ListObject.push_back( Value ); }; inline void PopFront() { m_DequeObject.pop_front(); }; inline void PopBack() { m_DequeObject.pop_back(); }; inline _T GetHead() { const static _T returnValue( 0 ); m_ListPosition = m_ListObject.begin(); if( m_ListPosition != m_ListObject.end() ) return ( *m_ListPosition ); else return ( returnValue ); }; inline _T GetNext() { const static _T returnValue( 0 ); if( m_ListPosition != m_ListObject.end() ) { m_ListPosition++; if( m_ListPosition != m_ListObject.end() ) return ( *m_ListPosition ); } return ( returnValue ); }; inline _T GetTail() { const static _T returnValue( 0 ); m_ListReveres_Position = m_ListObject.rbegin(); if( m_ListReveres_Position != m_ListObject.rend() ) return ( *m_ListReveres_Position ); else return ( returnValue ); } inline _T GetBefore( _T value ) { const static _T returnValue( 0 ); ListObject::iterator iter = find( m_ListObject.begin(), m_ListObject.end(), value ); if( iter == m_ListObject.end() ) return ( returnValue ); if( iter == m_ListObject.begin() ) return ( returnValue ); iter--; return ( *iter ); } inline _T GetAfter( _T value ) { const static _T returnValue( 0 ); ListObject::iterator iter = find( m_ListObject.begin(), m_ListObject.end(), value ); if( iter == m_ListObject.end() ) return ( returnValue ); iter++; // beforeÀÏ°æ¿ì iter--; if( iter == m_ListObject.end() ) return ( returnValue ); return ( *iter ); } inline bool Remove( _T value ) { ListObject::iterator iter = std::find( m_ListObject.begin(), m_ListObject.end(), value ); if( iter != m_ListObject.end() ) { _T value = ( *iter ); m_ListObject.erase( iter ); m_ListPosition = iter; if( value ) delete ( value ); return ( TRUE ); } else return ( FALSE ); } inline bool Erase( _T value ) { ListObject::iterator iter = find( m_ListObject.begin(), m_ListObject.end(), value ); if( iter != m_ListObject.end() ) { m_ListObject.erase( iter ); m_ListPosition = iter; return ( TRUE ); } else return ( FALSE ); } inline bool IsEnd() { return ( m_ListPosition == m_ListObject.end() ); } inline void Assign( STList *pList ) { if( !pList ) return; m_ListObject.assign( pList->m_ListObject.begin(), pList->m_ListObject.end() ); }; inline void RandomShuffle() { random_shuffle( m_ListObject.begin(), m_ListObject.end() ); }; inline _T GetValue( size_t index ) { const static _T returnValue( 0 ); if( ( m_ListObject.size() <= index ) || ( index < 0 ) ) return ( returnValue ); ListObject::iterator iter = ( m_ListObject.begin() + index ); if( iter != m_ListObject.end() ) return ( *iter ); else return ( returnValue ); }; inline _T operator [] ( size_t index ) { return ( GetValue( index ) ); }; // Reverse ÇÔ¼ö Ãß°¡ ½ÃÀÛ [1/13/2012 sooya] inline _T GetRHead() { const static _T returnValue( 0 ); m_ListReveres_Position = m_ListObject.rbegin(); if( m_ListReveres_Position != m_ListObject.rend() ) return ( *m_ListReveres_Position ); return ( returnValue ); }; inline bool IsREnd() { return ( m_ListReveres_Position == m_ListObject.rend() ); } inline _T GetRNext() { const static _T returnValue( 0 ); if( m_ListReveres_Position != m_ListObject.rend() ) { m_ListReveres_Position++; if( m_ListReveres_Position != m_ListObject.rend() ) return ( *m_ListReveres_Position ); } return ( returnValue ); } public: STList() { m_ListObject.clear(); }; virtual ~STList() { Clear(); }; protected: typename ListObject m_ListObject; typename ListObject::iterator m_ListPosition; typename ListObject::reverse_iterator m_ListReveres_Position; }; } } } #define AdoneList AdoneLibrary::Common::STL::STList #endif