Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

LibraryList.h

Go to the documentation of this file.
00001 //
00002 // LibraryList.h
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #if !defined(AFX_LIBRARYLIST_H__C045FFC3_F813_4962_94D0_FC5E9E4A7BA3__INCLUDED_)
00023 #define AFX_LIBRARYLIST_H__C045FFC3_F813_4962_94D0_FC5E9E4A7BA3__INCLUDED_
00024 
00025 #pragma once
00026 
00027 class CLibraryFile;
00028 
00029 
00030 class CLibraryList : public CComObject
00031 {
00032 // Construction
00033 public:
00034         CLibraryList(int nBlockSize = 16);
00035         virtual ~CLibraryList();
00036 
00037 // Attributes
00038 protected:
00039         DWORD*  m_pList;
00040         int             m_nCount;
00041         int             m_nBuffer;
00042         int             m_nBlock;
00043 
00044 // Operations
00045 public:
00046         inline int GetCount() const
00047         {
00048                 return m_nCount;
00049         }
00050 
00051         inline BOOL IsEmpty() const
00052         {
00053                 return m_nCount == 0;
00054         }
00055 
00056         inline DWORD GetHead() const
00057         {
00058                 ASSERT( m_nCount > 0 );
00059                 return m_pList[ 0 ];
00060         }
00061 
00062         inline DWORD GetTail() const
00063         {
00064                 ASSERT( m_nCount > 0 );
00065                 return m_pList[ m_nCount - 1 ];
00066         }
00067 
00068         inline POSITION GetIterator() const
00069         {
00070                 return m_nCount ? (POSITION)1 : NULL;
00071         }
00072 
00073         inline POSITION GetHeadPosition() const
00074         {
00075                 return m_nCount ? (POSITION)1 : NULL;
00076         }
00077 
00078         inline POSITION GetTailPosition() const
00079         {
00080                 return m_nCount ? (POSITION)m_nCount : NULL;
00081         }
00082 
00083         inline DWORD GetPrev(POSITION& pos) const
00084         {
00085                 ASSERT( (int)pos > 0 && (int)pos <= m_nCount );
00086                 DWORD nItem = m_pList[ (int)pos-- - 1 ];
00087                 if ( (int)pos < 1 || (int)pos > m_nCount ) pos = NULL;
00088                 return nItem;
00089         }
00090 
00091         inline DWORD GetNext(POSITION& pos) const
00092         {
00093                 ASSERT( (int)pos > 0 && (int)pos <= m_nCount );
00094                 DWORD nItem = m_pList[ (int)pos++ - 1 ];
00095                 if ( (int)pos < 1 || (int)pos > m_nCount ) pos = NULL;
00096                 return nItem;
00097         }
00098 
00099         inline POSITION AddHead(DWORD nItem)
00100         {
00101                 if ( m_nCount == m_nBuffer )
00102                 {
00103                         m_nBuffer += m_nBlock;
00104                         m_pList = (DWORD*)realloc( m_pList, sizeof(DWORD) * m_nBuffer );
00105                 }
00106                 MoveMemory( m_pList + 1, m_pList, sizeof(DWORD) * m_nCount );
00107                 m_pList[ 0 ] = nItem;
00108                 m_nCount++;
00109                 return (POSITION)1;
00110         }
00111 
00112         inline POSITION AddTail(DWORD nItem)
00113         {
00114                 if ( m_nCount == m_nBuffer )
00115                 {
00116                         m_nBuffer += m_nBlock;
00117                         m_pList = (DWORD*)realloc( m_pList, sizeof(DWORD) * m_nBuffer );
00118                 }
00119                 m_pList[ m_nCount++ ] = nItem;
00120                 return (POSITION)m_nCount;
00121         }
00122 
00123         inline POSITION CheckAndAdd(DWORD nItem)
00124         {
00125                 return ( Find( nItem ) == NULL ) ? AddTail( nItem ) : NULL;
00126         }
00127 
00128         inline DWORD RemoveHead()
00129         {
00130                 ASSERT( m_nCount > 0 );
00131                 DWORD nItem = m_pList[ 0 ];
00132                 m_nCount--;
00133                 MoveMemory( m_pList, m_pList + 1, sizeof(DWORD) * m_nCount );
00134                 return nItem;
00135         }
00136 
00137         inline DWORD RemoveTail()
00138         {
00139                 ASSERT( m_nCount > 0 );
00140                 return m_pList[ --m_nCount ];
00141         }
00142 
00143         inline void RemoveAt(POSITION pos)
00144         {
00145                 int nPos = (int)pos;
00146                 ASSERT( nPos > 0 && nPos <= m_nCount );
00147                 MoveMemory( m_pList + nPos - 1, m_pList + nPos, sizeof(DWORD) * ( m_nCount - nPos ) );
00148                 m_nCount--;
00149         }
00150 
00151         inline void RemoveAll()
00152         {
00153                 m_nCount = 0;
00154         }
00155 
00156         inline POSITION Find(DWORD nItem) const
00157         {
00158                 DWORD* pSeek = m_pList;
00159                 for ( int nCount = m_nCount ; nCount ; nCount--, pSeek++ )
00160                 {
00161                         if ( *pSeek == nItem ) return (POSITION)( m_nCount - nCount + 1 );
00162                 }
00163                 return NULL;
00164         }
00165 
00166 // Operations
00167 public:
00168         CLibraryFile*   GetNextFile(POSITION& pos) const;
00169         int                             Merge(CLibraryList* pList);
00170 
00171 
00172 // Automation
00173 protected:
00174         BEGIN_INTERFACE_PART(GenericView, IGenericView)
00175                 DECLARE_DISPATCH()
00176                 STDMETHOD(get_Name)(BSTR FAR* psName);
00177                 STDMETHOD(get_Unknown)(IUnknown FAR* FAR* ppUnknown);
00178                 STDMETHOD(get_Param)(LONG FAR* pnParam);
00179                 STDMETHOD(get_Count)(LONG FAR* pnCount);
00180                 STDMETHOD(get_Item)(VARIANT vIndex, VARIANT FAR* pvItem);
00181                 STDMETHOD(get__NewEnum)(IUnknown FAR* FAR* ppEnum);
00182         END_INTERFACE_PART(GenericView)
00183 
00184         BEGIN_INTERFACE_PART(EnumVARIANT, IEnumVARIANT)
00185                 STDMETHOD(Next)(THIS_ DWORD celt, VARIANT FAR* rgvar, DWORD FAR* pceltFetched);
00186                 STDMETHOD(Skip)(THIS_ DWORD celt);
00187                 STDMETHOD(Reset)(THIS);
00188                 STDMETHOD(Clone)(THIS_ IEnumVARIANT FAR* FAR* ppenum);
00189                 POSITION m_pos;
00190         END_INTERFACE_PART(EnumVARIANT)
00191 
00192         DECLARE_INTERFACE_MAP()
00193 
00194 };
00195 
00196 #endif // !defined(AFX_LIBRARYLIST_H__C045FFC3_F813_4962_94D0_FC5E9E4A7BA3__INCLUDED_)

Generated on Thu Dec 15 10:39:44 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2