Windows/MFC

CArray 클래스...

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

///////////////////////////////////////////////////////////////////////////////
CArray < class TYPE, class ARG_TYPE >

    TYPE        Template parameter specifying the type of objects stored in the array.
                TYPE is a parameter that is returned by CArray.

    ARG_TYPE    Template parameter specifying the argument type used to access
                objects stored in the array. Often a reference to TYPE.
                ARG_TYPE is a parameter that is passed to CArray.

    The CArray class supports arrays that are are similar to C arrays, but can
    dynamically shrink and grow as necessary


    ==================================================
    Class Members
    ==================================================
    Add
        int Add( ARG_TYPE newElement );
            throw( CMemoryException );
    Append
        int Append( const CArray& src );
    Copy
        void Copy( const CArray& src );
    ElementAt
        TYPE& ElementAt( int nIndex );
    FreeExtra
        void FreeExtra( );
    GetAt
        TYPE GetAt( int nIndex ) const;
    GetData
        const TYPE* GetData( ) const;
    GetSize
        int GetSize( ) const;
    GetUpperBound
        int GetUpperBound( ) const;
    InsertAt
        void InsertAt( int nIndex, ARG_TYPE newElement, int nCount = 1 );
            throw( CMemoryException );
        void InsertAt( int nStartIndex, CArray* pNewArray );
            throw( CMemoryException );
                [pNewArray - Another array that contains elements
                 to be added to this array.]
    RemoveAll
        void RemoveAll( );
    RemoveAt
        void RemoveAt( int nIndex, int nCount = 1 );
    SetAt
        void SetAt( int nIndex, ARG_TYPE newElement );
    SetAtGrow
        void SetAtGrow( int nIndex, ARG_TYPE newElement );
            throw( CMemoryException );
    SetSize
        void SetSize( int nNewSize, int nGrowBy = -1 );
            throw( CMemoryException );
    operator[]
        TYPE& operator []( int nIndex );
        TYPE operator []( int nIndex ) const;

    ==================================================
    Create
    ==================================================
    CArray m_ObjectArray;
    m_ObjectArray.SetSize(number_of_elements, elements_to_allocate_if_increased);

    CArray m_PointerArray;
    //Constructs an empty array. The array grows one element at a time


    ==================================================
    Insert
    ==================================================
    CPoint pt(10,10);
    m_ObjectArray.Add(pt);

    ==================================================
    Iterate
    ==================================================
    CArray&ptArray = m_ObjectArray;
    for (int nIndex = 0; nIndex < ptArray.GetSize(); nIndex++)
    {
        CPoint pt = ptArray[nIndex];
    }

    ==================================================
    Find
    ==================================================

    ==================================================
    Update
    ==================================================
    CPoint pt(m_x, m_y);
    m_ObjectArray[nSel] = pt;

    ==================================================
    Delete
    ==================================================
    m_ObjectArray.RemoveAt(nSel);
    m_ObjectArray.RemoveAll();

    int i = 0;
    while (i < m_PointerArray.GetSize() )
    {
        delete m_PointerArray.GetAt( i++ );
    }
    m_PointerArray.RemoveAll();

    ==================================================
    Serialize
    ==================================================
    m_ObjectArray.Serialize( ar );