mfc c ollection c lasses tr ầ n anh tu ấ n a. c ontents ( mfc c ollection c lasses ) array...
TRANSCRIPT
![Page 1: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/1.jpg)
MFC COLLECTION CLASSESTrần Anh Tuấn A
![Page 2: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/2.jpg)
CONTENTS ( MFC COLLECTION CLASSES )
![Page 3: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/3.jpg)
ARRAY
Introduction : MFC Provides an assortment of array classes for
users
![Page 4: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/4.jpg)
ARRAY
Type-Specific MFC Array Classes
![Page 5: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/5.jpg)
ARRAY
Sample : CStringArray
![Page 6: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/6.jpg)
ARRAY
Sample : CStringArray
![Page 7: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/7.jpg)
ARRAY
CStringArray Class Members
![Page 8: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/8.jpg)
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
![Page 9: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/9.jpg)
ARRAY
Example :
![Page 10: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/10.jpg)
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)
![Page 11: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/11.jpg)
EXAMPLE : STEP 2
Class Winzards
Collection Demo Dialog
CollectionDemoDlg.h
CollectionDemoDlg::OnInitDialog()
![Page 12: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/12.jpg)
EXAMPLE : OUTPUT
![Page 13: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/13.jpg)
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
![Page 14: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/14.jpg)
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.
![Page 15: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/15.jpg)
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.
![Page 16: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/16.jpg)
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).
![Page 17: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/17.jpg)
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
![Page 18: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/18.jpg)
LIST
Example :
![Page 19: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/19.jpg)
EXAMPLE :STEP 1
Book.h
Book.cpp
![Page 20: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/20.jpg)
EXAMPLE : STEP 2
Class Winzards
CCObListDemoDlg.h
CCObListDemoDlg::OnInitDialog()
![Page 21: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/21.jpg)
EXAMPLE : OUTPUT
![Page 22: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/22.jpg)
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
![Page 23: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/23.jpg)
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
![Page 24: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/24.jpg)
MAP
Sample : CMapStringToString
![Page 25: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/25.jpg)
MAP
Sample : CMapStringToString (More in MSDN)
![Page 26: MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction](https://reader038.vdocuments.mx/reader038/viewer/2022103101/56649eac5503460f94bb2f1d/html5/thumbnails/26.jpg)
END OF WEEK 4