Tools.h++ Manual
10-4 104011 Tandem Computers Incorporated
10
Here's a line-by-line description of the program:
1. Include the declarations for the class
RWFileManager
.
2. Struct
DiskNode
is a link in the linked-list. It contains:
3. The data (an int), and
4. The offset to the next link.
RWoffset
is typically "typedef'd" to a long
int.
5. This is the constructor for an
RWFileManager
. It will create a new file,
called "
linklist.dat
."
6. Allocate space on the file to store the offset to the first link. This first
allocation is considered "special" and will be saved by the
RWFileManager
. It can be retrieved at any time by using the member
function
start()
.
7. Allocate space to store the first link. The member function
allocate()
returns the offset to this space. Since each
DiskNode
needs the offset to
the next
DiskNode
, space for the next link must be allocated before the
current link is written.
8. Seek to the position to write the offset to the first link. Note that the
offset to this position is returned by the member function
start()
.
Note also that
fm
has access to public member functions of class
RWFile
,
since class
RWFileManager
is derived from class
RWFile
.
9. Write the offset to the first link.
10. A loop to read integers and store them in a linked-list.
11. Allocate space for the next link, storing the offset to it in the
nextNode
field of this link.
12. Seek to the proper offset to store this link
13 Write this link.
fm.Write(n.nextNode);
return 0;
} // 17
Code Example 10-1