home *** CD-ROM | disk | FTP | other *** search
- /*
- * Example 7: FileManager. Saves a linked list of ints.
- * This example appears in Section 11.2 of the manual.
- *
- * $Header: E:/vcs/toolexam/example7.cpv 1.1 01 Apr 1992 16:51:12 keffer $
- *
- ****************************************************************************
- *
- * Rogue Wave Software, Inc.
- * P.O. Box 2328
- * Corvallis, OR 97339
- * Voice: (503) 754-2311 FAX: (503) 757-7350
- *
- * Copyright (C) 1989, 1990, 1991. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/toolexam/example7.cpv $
- *
- * Rev 1.1 01 Apr 1992 16:51:12 keffer
- * Now includes <rw/xxx.h>
- *
- */
-
- #include <rw/filemgr.h>
- #include <rw/rstream.h>
-
- struct DiskNode {
- int data;
- RWoffset nextNode;
- };
-
- main()
- {
- cout << "Test of a linked-list on disk, using the RWFileManager.\n";
-
- RWFileManager fm("linklist.dat");
-
- // Allocate space for offset to start of the linked list:
- fm.allocate(sizeof(RWoffset));
- // Allocate space for the first link:
- RWoffset thisNode = fm.allocate(sizeof(DiskNode));
-
- fm.SeekTo(fm.start());
- fm.Write(thisNode);
-
- DiskNode n;
- int temp;
- RWoffset lastNode;
- cout << "Input a series of integers, then EOF to end:\n";
-
- /* Borland bug necessitates explicit test for good. */
- while ( (cin >> temp).good() ){
- n.data = temp;
- n.nextNode = fm.allocate(sizeof(DiskNode));
- fm.SeekTo(thisNode);
- fm.Write(n.data);
- fm.Write(n.nextNode);
- lastNode = thisNode;
- thisNode = n.nextNode;
- }
-
- fm.deallocate(n.nextNode);
- n.nextNode = NIL;
- fm.SeekTo(lastNode);
- fm.Write(n.data);
- fm.Write(n.nextNode);
- cout << "Now run example8 to read them in.\n";
- return 0;
- }
-