Windows/MFC
CList
aucd29
2013. 10. 2. 17:55
//코드구루에 올라온 내용을 올리는겁니다..
//해석은 굳이 안해두 간단한 내용인지라... 굳이.... (사실 실력두 안됨 @.@)
Expand the Header Files folder, and open file StdAfx.h.
At the end of the file, type:
#include // MFC templates
///////////////////////////////////////////////////////////////////////////////
CList < class TYPE, class ARG_TYPE >
TYPE Type of object stored in the list.
ARG_TYPE Type used to reference objects stored in the list.
Can be a reference.
The CList class supports ordered lists of nonunique objects accessible
sequentially or by value. CList lists behave like doubly-linked lists.
==================================================
Class Members
==================================================
AddHead
POSITION AddHead( ARG_TYPE newElement );
void AddHead( CList* pNewList );
AddTail
POSITION AddTail( ARG_TYPE newElement );
void AddTail( CList* pNewList );
Find
POSITION Find( ARG_TYPE searchValue, POSITION startAfter = NULL) const;
FindIndex
POSITION FindIndex( int nIndex ) const;
GetAt
TYPE& GetAt( POSITION position );
TYPE GetAt( POSITION position ) const;
GetCount
int GetCount() const;
GetHead
TYPE& GetHead( ); // use on either side, can be modified
TYPE GetHead( ) const; // use only on right side, can not be modified
GetHeadPosition
POSITION GetHeadPosition( ) const;
GetNext
TYPE& GetNext( POSITION& rPosition );
TYPE GetNext( POSITION& rPosition ) const;
GetPrev
TYPE& GetPrev( POSITION& rPosition );
TYPE GetPrev( POSITION& rPosition ) const;
GetTail
TYPE& GetTail( );
TYPE GetTail() const;
GetTailPosition
POSITION GetTailPosition( ) const;
InsertAfter
POSITION InsertAfter( POSITION position, ARG_TYPE newElement );
InsertBefore
POSITION InsertBefore( POSITION position, ARG_TYPE newElement );
IsEmpty
BOOL IsEmpty( ) const;
RemoveAll
void RemoveAll( );
RemoveAt
void RemoveAt( POSITION position );
RemoveHead
TYPE RemoveHead( );
RemoveTail
TYPE RemoveTail( );
SetAt
void SetAt( POSITION pos, ARG_TYPE newElement );
==================================================
Create
==================================================
CList m_intList;
CList m_stringList;
==================================================
Insert
==================================================
m_intList.AddTail(m_int);
POSITION posTemp = m_intList.InsertBefore(pos, m_int);
// Add three elements to the list.
m_stringList.AddTail(CString("XYZ"));
m_stringList.AddTail(CString("ABC"));
m_stringList.AddTail(CString("123"));
==================================================
Iterate
==================================================
POSITION pos = intList.GetHeadPosition();
while (pos != NULL)
{
int n = intList.GetNext(pos);
}
==================================================
Find
==================================================
pos = m_intList.Find(nValue);
// Verify the first element (index 0).
ASSERT(CString("XYZ") == m_stringList.GetAt(m_stringList.FindIndex(0)));
POSITION pos = m_stringList.Find(CString("XYZ"));
ASSERT(CString("XYZ") == m_stringList.GetAt(pos));
==================================================
Update
==================================================
m_intList.SetAt(pos, m_int);
// Replace CString("ABC") with CString("CBA")
POSITION pos = m_stringList.Find(CString("ABC"));
m_stringList.SetAt(pos, CString("CBA"));
// Verify CString("ABC") is not in the list.
ASSERT(m_stringList.Find(CString("ABC")) == NULL);
==================================================
Delete
==================================================
m_intList.RemoveAt(pos);
m_intList.RemoveAll();
POSITION pos = m_stringList.GetHeadPosition();
while (pos != NULL)
{
delete m_stringList.GetNext(pos);
// or use GetNext then RemoveAt(pos);
}
m_stringList.RemoveAll();
==================================================
Serialize
==================================================
m_intList.Serialize(ar);
//해석은 굳이 안해두 간단한 내용인지라... 굳이.... (사실 실력두 안됨 @.@)
Expand the Header Files folder, and open file StdAfx.h.
At the end of the file, type:
#include // MFC templates
///////////////////////////////////////////////////////////////////////////////
CList < class TYPE, class ARG_TYPE >
TYPE Type of object stored in the list.
ARG_TYPE Type used to reference objects stored in the list.
Can be a reference.
The CList class supports ordered lists of nonunique objects accessible
sequentially or by value. CList lists behave like doubly-linked lists.
==================================================
Class Members
==================================================
AddHead
POSITION AddHead( ARG_TYPE newElement );
void AddHead( CList* pNewList );
AddTail
POSITION AddTail( ARG_TYPE newElement );
void AddTail( CList* pNewList );
Find
POSITION Find( ARG_TYPE searchValue, POSITION startAfter = NULL) const;
FindIndex
POSITION FindIndex( int nIndex ) const;
GetAt
TYPE& GetAt( POSITION position );
TYPE GetAt( POSITION position ) const;
GetCount
int GetCount() const;
GetHead
TYPE& GetHead( ); // use on either side, can be modified
TYPE GetHead( ) const; // use only on right side, can not be modified
GetHeadPosition
POSITION GetHeadPosition( ) const;
GetNext
TYPE& GetNext( POSITION& rPosition );
TYPE GetNext( POSITION& rPosition ) const;
GetPrev
TYPE& GetPrev( POSITION& rPosition );
TYPE GetPrev( POSITION& rPosition ) const;
GetTail
TYPE& GetTail( );
TYPE GetTail() const;
GetTailPosition
POSITION GetTailPosition( ) const;
InsertAfter
POSITION InsertAfter( POSITION position, ARG_TYPE newElement );
InsertBefore
POSITION InsertBefore( POSITION position, ARG_TYPE newElement );
IsEmpty
BOOL IsEmpty( ) const;
RemoveAll
void RemoveAll( );
RemoveAt
void RemoveAt( POSITION position );
RemoveHead
TYPE RemoveHead( );
RemoveTail
TYPE RemoveTail( );
SetAt
void SetAt( POSITION pos, ARG_TYPE newElement );
==================================================
Create
==================================================
CList m_intList;
CList m_stringList;
==================================================
Insert
==================================================
m_intList.AddTail(m_int);
POSITION posTemp = m_intList.InsertBefore(pos, m_int);
// Add three elements to the list.
m_stringList.AddTail(CString("XYZ"));
m_stringList.AddTail(CString("ABC"));
m_stringList.AddTail(CString("123"));
==================================================
Iterate
==================================================
POSITION pos = intList.GetHeadPosition();
while (pos != NULL)
{
int n = intList.GetNext(pos);
}
==================================================
Find
==================================================
pos = m_intList.Find(nValue);
// Verify the first element (index 0).
ASSERT(CString("XYZ") == m_stringList.GetAt(m_stringList.FindIndex(0)));
POSITION pos = m_stringList.Find(CString("XYZ"));
ASSERT(CString("XYZ") == m_stringList.GetAt(pos));
==================================================
Update
==================================================
m_intList.SetAt(pos, m_int);
// Replace CString("ABC") with CString("CBA")
POSITION pos = m_stringList.Find(CString("ABC"));
m_stringList.SetAt(pos, CString("CBA"));
// Verify CString("ABC") is not in the list.
ASSERT(m_stringList.Find(CString("ABC")) == NULL);
==================================================
Delete
==================================================
m_intList.RemoveAt(pos);
m_intList.RemoveAll();
POSITION pos = m_stringList.GetHeadPosition();
while (pos != NULL)
{
delete m_stringList.GetNext(pos);
// or use GetNext then RemoveAt(pos);
}
m_stringList.RemoveAll();
==================================================
Serialize
==================================================
m_intList.Serialize(ar);