mfc c ollection c lasses tr ầ n anh tu ấ n a. c ontents ( mfc c ollection c lasses ) array...

Post on 13-Jan-2016

219 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

MFC COLLECTION CLASSESTrần Anh Tuấn A

CONTENTS ( MFC COLLECTION CLASSES )

ARRAY

Introduction : MFC Provides an assortment of array classes for

users

ARRAY

Type-Specific MFC Array Classes

ARRAY

Sample : CStringArray

ARRAY

Sample : CStringArray

ARRAY

CStringArray Class Members

ARRAY

Generic CArray Class A template class used to build type-safe array classes

for arbitrary data types, such as array of CPoint Users can use data of any kind—even classes of your

own creation—in CArray's template parameters

Example : Create an array of CPoint : CArray <CPoint, CPoints&> array; Create an array of SinhVien :

CArray <SinhVien, SinhVien&> array; array.SetSize(10);Array.Add(SinhVien(“Tran Van Huy”,”0411255”,”Nam”);

CArray <DataType, DataType&> variable

ARRAY

Example :

EXAMPLE : STEP 1SinhVien.h

SinhVien.cpp

Note: must make class Dialog to be a friend of class SinhVien to access SinhVien data (Hoten and MSSV)

EXAMPLE : STEP 2

Class Winzards

Collection Demo Dialog

CollectionDemoDlg.h

CollectionDemoDlg::OnInitDialog()

EXAMPLE : OUTPUT

LIST A linked list is a collection of items that contain

pointers to other items ( Next and Prev pointer). The MFC template class CList implements a generic

linked list that can be customized to work with any data type

POSITION :  A value used to denote the position of an element in a collection; used by MFC collection classes

LIST

Sample : CObList Construction

CObList Constructs an empty list for CObject pointers.Head/Tail Access

GetHead Returns the head element of the list (cannot be empty).

GetTail Returns the tail element of the list (cannot be empty).

Operations RemoveHead Removes the element from the head of the

list. RemoveTail Removes the element from the tail of the

list. AddHead Adds an element (or all the elements in

another list) to the head of the list (makes a new head). AddTail Adds an element (or all the elements in another

list) to the tail of the list (makes a new tail). RemoveAll Removes all the elements from this list.

LIST

Sample : CObList Iteration

GetHeadPosition Returns the position of the head element of the list.

GetTailPosition Returns the position of the tail element of the list.

GetNext Gets the next element for iterating. GetPrev Gets the previous element for iterating.

Retrieval/Modification GetAt Gets the element at a given position. SetAt Sets the element at a given position. RemoveAt Removes an element from this list,

specified by position.

LIST

Sample : CObList Insertion

InsertBefore Inserts a new element before a given position.

InsertAfter Inserts a new element after a given position.

Searching Find Gets the position of an element specified by

pointer value. FindIndex Gets the position of an element specified by

a zero-based index.

Status GetCount Returns the number of elements in this list. IsEmpty Tests for the empty list condition (no

elements).

LIST

Generic CList Class A template class used to build type-safe list

classes for arbitrary data types, such as array of CPoint

Users can use data of any kind—even classes of your own creation—in CList's template parameters

Example : Create a list of CPoint : CList <CPoint, CPoints&> list; Create an list of Book :

CList <Book, Book&> list; list

CList <DataType, DataType&> variable

LIST

Example :

EXAMPLE :STEP 1

Book.h

Book.cpp

EXAMPLE : STEP 2

Class Winzards

CCObListDemoDlg.h

CCObListDemoDlg::OnInitDialog()

EXAMPLE : OUTPUT

MAP

A map, also known as a dictionary, is a table of items keyed by other items

Maps are ideal containers for large amounts of data when lookup performance is of paramount importance

MAP

MFC provides the following type-specific (and non-template-based) map classes

Each class includes member functions for adding and removing items, retrieving items by key, and enumerating all the items in the map

MAP

Sample : CMapStringToString

MAP

Sample : CMapStringToString (More in MSDN)

END OF WEEK 4

top related