Good book finishing series - Design mode: can be used for object-oriented software foundation 9

zhaozj2021-02-08  220

Appendix C Basic class This appendix provides the basic classes we used in some modes of C sample code. We strive to make these classes as short as possible. These basic classes include: • List, sequential list of objects. • Iterator, sequentially access the interface of the aggregated object. • Listiterator, the I t e R A T O R of the L i S T is traversed. • Point, a two-dimensional point. • RECT, a rectangle of an axis alignment. In some compilers, some new C standard types may not be implemented. In particular, if your compiler does not define a B O O L type, you can manually define it below: C.1 Listl I S T template class is a basic container for storing an object sequence. L i s t stores the value of the element, which may be an internal type of a built-in type or a class object. For example, L i s t declares an integer sequence. However, it is used in most modes to store object pointers, such as L i s t . This allows the L i s T class to be used for the list of heterogeneous elements. For convenience, the L i s T class also provides operations in the form of stack. This can directly use L i s T directly as a stack without defining a new class.

These operations are discussed in more detail below. Construction, sect, initialization, and assignment list List (long size) initialization list. Parameter S i z e prompts the number of initial elements. L i s t (l i s t &) overloads the default copy constructor to correctly initialize the member data. ~ L i s t () releases the storage space of the internal data structure of the list. But it does not release the data of its element. The designer does not want the user to inherit this class, so the designer function is not empty. List & operator = (const list &) implements the list assignment to correctly assign each member data. Access these operations support basic access to list elements. Long count () const Back to the number of objects in the list. Item & Get (long index) const returns an object to which it is. Item & first () const returns the first object of the list. Item & Last () Const returns the last object of the list. The Bool Includes (Const Item &) Const list contains a given element. This operation requires list element type to support = = operations for comparison. Add Void Append (Const Item &) Add an element at the end of the list. Void Prepend (const item &) inserts an element in the list header. Delete Void Remove (Const Item &)

Remove given elements from the list. This operation requires list element type to support = = operations for comparison. Void RemoveLast () Deletes the last element. Void RemoveFirst () Deletes the first element. Void RemoveAll () Deletes all elements. Stack Interface Item & Top () Const returns the top element (treat the list as a stack). Void Push (const item &) press the element into the stack. Item & Pop () pops up top elements. C.2 Iteratori T E R A T O R is an abstract class that defines an interface that traverses an object collection. Its operation means: Virtual void first () enables the first object in the order collection in the order collection. Virtual void next () enables the I TE E R A T O R to point to the next element of the object sequence. Virtual Bool IsDone () Const This is true when there is no longer reached an object in the sequence. Virtual Item CurrentItem () Const returns the object of the current location in the sequence. C.3 ListiteratorL I S TI T E R A T O R Implements the I T E R A T O R Interface of the Traverse List. Its constructor is parameter with a list of to be traversed. C.4 PointP O I N t represents a point on the two-dimensional card coordinate space. P O i N t supports some of the most basic vector operations. The coordinate value type of P O i N t is defined as: typedef float coord; the operation meaning of P O i N t is self-labeled. Static member Z e R O represents P O i N T (0, 0). C.5 Rectr E C T represents a rectangle of an axis alignment. A rectangle is represented by an origin and a range (length and width). Its operational mean is also self-evident. Static member Z e R O is equal to rectangular RECT (Point (0, 0) Point (0, 0));

转载请注明原文地址:https://www.9cbs.com/read-3347.html

New Post(0)