• Complain

Paul Wolfgang - Integration of the Standard Template Library and the Microsoft Foundation Class

Here you can read online Paul Wolfgang - Integration of the Standard Template Library and the Microsoft Foundation Class full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

No cover
  • Book:
    Integration of the Standard Template Library and the Microsoft Foundation Class
  • Author:
  • Genre:
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

Integration of the Standard Template Library and the Microsoft Foundation Class: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Integration of the Standard Template Library and the Microsoft Foundation Class" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Paul Wolfgang: author's other books


Who wrote Integration of the Standard Template Library and the Microsoft Foundation Class? Find out the surname, the name of the author of the book and a list of all author's works by series.

Integration of the Standard Template Library and the Microsoft Foundation Class — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Integration of the Standard Template Library and the Microsoft Foundation Class" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make

Paul Wolfgang, Yang Song

Integration of the Standard Template Library and the Microsoft Foundation Class

1 Introduction

Both the Microsoft Foundation Class (MFC) [1] and the Standard Template Library (STL) [2] provide generalized containers and a facility to iterate over all of the objects within a container. However, the approach taken is different. Within the MFC the iteration mechanism is dependent upon the container, while in the STL there is a common iteration mechanism so that an algorithm can operate on each element of a container without knowledge of the container's type. The MFC containers support persistent storage, which is not a feature of the STL.

This paper presents a small example of a Windows application using the STL containers in place of the corresponding MFC containers.

2 Example Scribble.

2.1 Description of the Problem

The MFC Tutorial [3] includes a simple graphics application known as Scribble. The purpose of Scribble is to let the user draw a set of strokes with the mouse. The result is saved in a file (called a document) which can be opened and updated by adding additional strokes. (There is no method for deleting a stroke.) The user also has the option of specifying the thickness and color of the pen.

Scribble's data structure consists of one or more strokes. Each stroke is the record of the mouse position from the time when the user clicks on left mouse key to the time when the user releases the mouse button. In MFC approach, a new class CStroke, which is derived from class CObject, is defined. This contains a data member of CArrayCPoint, CPoint with other data members to record and work on each stroke. The document class, CScribbDoc, is derived from CDocument. It contains a list of stokes using the MFC template class CTypedPtrListCObList, CStroke*.

Figure 1 illustrates the document data structure.

Figure 1 Scribble Document Structure 22 Type definitions 221 MFC - photo 1

Figure 1 Scribble Document Structure

2.2 Type definitions

2.2.1 MFC Implementation

In the MFC implementation, the list of strokes is stored in the member m_strokeList which is defined as a CTypedPtrListCObject, CStroke*. The class CStroke, in turn, contains a CArrayCPoint, CPoint to contain the array of points that constitute the stroke.

2.2.2 STL Implementation

The class CStrokeList is defined to replace the CTypedPtrListCObject, CStroke* as follows:

class CStrokeList: public CObject, public std::listCStroke*{

public:

CStrokeList () {}

CStrokeList(const CStrokeList&);

DECLARE_SERIAL(CStrokeList)

public:

virtualvoid Serialize(CArchive& ar);

};

The CArrayCPoint, CPoint in CStroke is replaced by a std::listCPoint.

2.3 Using the STL algorithms and iterators

2.3.1 Inserting points into a stroke

In the original MFC implementation, points were added to a stroke by the following statement:

m_pStrokeCur-m_pointArray.Add(point);

In the STL implementation this becomes:

m_pStrokeCur-m_pointArray.push_back(point);

2.3.2 Drawing all strokes

In the original MFC implementation, the list of strokes was traversed and each stroke drawn by the following code:

POSITION pos = strokeList.front ();

while (pos!= NULL){

CStroke* pStroke =strokeList.GetNext(pos);

pStroke-DrawStroke(pDC);

}

We make two changes. The first obvious change is to replace the MFC list iteration with the corresponding STL iteration. The result is as follows:

for (std::listCStroke*::iterator i = strokeList.begin(); i!= strokeList.end(); ++i)

(*i)-DrawStroke(pDC);

The second change is to apply the for_each algorithm. Unfortunately, the for_each algorithm takes as its third argument a function of one argument, that argument being the type obtained by de-referencing the iterator. Specifically, we must convert the expression:

(*i)-DrawStroke(pDC);

into a call to a function of one argument, where that argument is the dereferenced iterator. Stroustrup[4] shows how to do this using the binders and adapters. The function mem_fun1 is a function of one parameter, the a pointer to member function that takes an arbitrary argument. The result of this function, is a function object that takes two arguments, the first of which is a pointer to a class, and the second is the same arbitrary second argument. Thus, the expression

(*i)-DrawStroke(pDC);

may be replaced by

mem_fun1(&CStroke::DrawStroke)(*i, pDC);

We can now apply the bind2nd binder to convert this expression into a call to a function taking one argument:

bind2nd(mem_fun1(&CStroke::DrawStroke), pDC)(*i);

The loop can now be replaced by a call to the for_each algorithm:

for_each(strokeList.begin(), strokeList.end(), bind2nd(mem_fun1(&CStroke::DrawStroke), pDC));

2.3.3 Drawing a stroke

The original code to draw a stroke was as follows:

pDC-MoveTo(m_pointArray[0]);

for (int i=1; i m_pointArray.GetSize(); i++) {

pDC-LineTo(m_pointArray[i]);

}

We also make two changes. The first is to use the vector iterator as follows:

pDC-MoveTo(m_pointArray.begin());

for (vectorCPoint::iterator i= m_pointArray.begin();i!= m_pointArray.end(); ++i)

pDC-LineTo(*i);

Now the member function we are calling is not a member of the class pointed to by the objects in the container, but rather it is a member of the class CDC, which encapsulates the Windows drawing context. The same mem_fun1 adapter may be used as follows:

mem_fun1(&CDC::LineTo) (pDC, *i);

Since LineTo is an overloaded function, we need to give the compiler some help resolving the ambiguity. This is done as follows:

typedef BOOL(CDC::*ptr_to_fcn_of_POINT) (POINT);

ptr_to_fcn_of_POINT p =&CDC::LineTo;

mem_fun1(p)(pDC, *i)

Since the loop variable is now the second argument, and the pDC is the first, we use bind1st to call the for_each algorithm as follows:

for_each(m_pointArray.begin(), m_pointArray.end(), bind1st(std::mem_fun1(p), pDC));

2.4 Serialization

2.4.1 Brief description of the MFC serialization

MFC provides a method for saving and retrieving a class to/from a file. The general approach is to write/read the raw bytes to the file preceded by some type identification. This is accomplished using the class CObject as an abstract base class, the virtual function serialize, and the class CArchive. CArchive encapsulates the file and provides overloaded insertion () and extraction () operators. These operators are provided for the built-in types, the standard Windows types such as WORD, DWORD, and POINT, and pointers to CObject. The insertion operator for pointers to CObject writes type identification to the file, and then calls the serialize member function. The extraction operator verifies the type identification and then calls the serialize member function.

2.4.2 The serialize function

The generalize scheme for the serialize function is as follows:

void CMyClass::Serialize(CArchive& ar) {

CObject::Serialize(ar);

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Integration of the Standard Template Library and the Microsoft Foundation Class»

Look at similar books to Integration of the Standard Template Library and the Microsoft Foundation Class. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Integration of the Standard Template Library and the Microsoft Foundation Class»

Discussion, reviews of the book Integration of the Standard Template Library and the Microsoft Foundation Class and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.