/* Gamelon(tm) File I/O Library Sample Code  C++ Language */

/* (C)1994 Menai Corporation(tm)  Released for public use */

 

/* Example 9a. How to read the contents of stored objects */

/* when structure of the file is known.                   */

 

/* When the program knows the structure of the file, the  */

/* program may simply move from object to object within   */

/* the file, reading the contents of each object using    */

/* datatypespecific read calls. For example, if the      */

/* contents of a particular file (or of an aggregate      */

/* within a file) are an integer value 14, a character    */

/* value 'F' and a string value "Wherefore art thou,      */

/* Romeo?", the function calls to read such a file could  */

/* be as follows:                                         */

 

/* Beginning file layout:                     */

/*  {                                       } */

/*   [14]['F']["Wherefore art thou, Romeo?"]  */

 

#include <stdlib.h>

#include <iostream.h>

#include "gfcursor.hpp"

 

int main(void) {

int valid;

short i;

char ch;

char *strptr;

size_t strsize;

 

CURSOR *c = new CURSOR("newfile");

c>eCursorQueryValid(&valid);

if (!valid)

exit(1);

c>eCursorMoveIn();

c>eObjRead(&i);

c>eCursorMoveNext();

c>eObjRead(&ch);

c>eCursorMoveNext();

c>eObjQueryDataSize(&strsize);

strptr = new char[strsize];

c>eObjRead(strptr, strsize);

cout << "i = " << i << endl;

cout << "ch = " << ch << endl;

cout << "strptr = " << strptr << endl;

delete (strptr);

delete c;

return 0;

}

 

/* Program output:                     */

/* i = 14                              */

/* ch = F                              */

/* strptr = Wherefore art thou, Romeo? */

 

/* The ObjRead functions are overloaded; as a result, */

/* all the ObjRead calls look similar. The parameters */

/* of each function call distinguish the exact        */

/* function called to read information from the       */

/* object. Note that in order to properly read the    */

/* object containing the string value, the programmer */

/* must first query the object for its datasize, in   */

/* order to allocate enough memory for the string, or */

/* the programmer can just use a large preallocated  */

/* block of memory. The size of the block of memory   */

/* is then passed to the ObjRead function.            */

Download this sample source code

Return to Samples List

 Home | Product | Consulting | Programming | Reviews | Company | Site Map | Guest Book

 Menai Corporation, 1010 El Camino Real, Suite 300, Menlo Park, California 94025-4335
 800-GAMELON (800-426-3566) (US only), 650-853-6450 (voice), 650-853-6453 (fax)
 Questions about our products and services:
info@menai.com.
 Comments about this web site:
webmaster@menai.com.

Copyright © 1996-98 Menai Corporation. All Rights Reserved. Menai, Gamelon and gamelon(stylized) are worldwide trademarks of Menai Corporation, registered in the United States of America, and the .[g] logo is a worldwide trademark of Menai Corporation. All other trademarks are owned by their respective owners.