Casio ClassPad 300 Programming Manual page 119

Sdk programming guide
Hide thumbs Also See for ClassPad 300:
Table of Contents

Advertisement

int i = f.ReadWord();
}
While this would work fine if your application only saved integers, how do you read data
types that do not have a function in CPReadFile? For the most part, all data types define
their own Read() function to support being read from MCS.
For example, let's assume a class foo with the following:
class Foo
{
...
void Read(CPReadMCSFile& f);
}
We'll also say that foo's data members that will be read from a file are an int count and a
CPString string. Then foo's Read function would look something like this:
void Foo::Read(CPReadFile& f)
{
i = f.ReadInt();
string.Read(f);
}
Just like class foo has its own Read() function, so does class CPString. So to read a
CPString, we just call its Read() function. In the same manner, if we had a class that had
a foo as a data member we would just call foo.Read(f) in that class's Read() function.
This means that any class that you create and want to read from MCS must have its own
read function. Conisder the ContactArray class in the AddressBook example. Remember
that the ContactArray is an array of Contact objects. The ContactArray's Read function
first reads in an integer that represents the number of contacts saved to the file. It then
loops that many times and calls the Contact class's read function to read in each contact:
void ContactArray::Read(CPReadFile& f)
{
//first read in how many contacts are saved
int count = f.ReadWord();
// loop that many times
for(int i=0;i<count;i++)
{
//create a contact
Contact* c = new Contact();
// Call that contact's read function
c->Read(f);
Add(c);
}
//makes sure the array is in order
sort();
}
119

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents