Beruflich Dokumente
Kultur Dokumente
Base Class
Every class in MarkzFrame is derived from a base class called MZObject. The
purpose of the base class is memory management. Inside the MZObject is a usage
counter, which can be manipulated by the application. This counter can be
incremented and decremented throughout the application, and by doing so,
MarkzFrame knows when it is able to permanently delete the object.
“Retains” the object by incrementing its usage counter. The function returns
“itself”, which can be ignored, or stored somewhere. A newly created object
automatically has its usage counter set to ‘1’.
“Releases” the object be decrementing its usage counter. If the usage counter
decrements to zero, the object is deleted.
Note that by balanced pairs of retain() and release(), there is no need for an
application to ever use the “delete” keyword, as objects are automatically
released when the usage counter goes to zero.
This scheme is highly beneficial in debug mode, as the system will catch an
attempt to release a deleted object, as well as catch memory leaks when the
application quits.
Dictionaries and Arrays
A highlight of MarkzFrame is its high level dictionary and array objects. A
dictionary object presents a value pair collection of objects that can be “looked
up” with a known key. A dictionary object is essentially a database of arbitrary
objects, each with a unique “name” associated to it.
For example, a document reader module would typically create a dictionary of all
elements in a document. The lookup key “fonts” would return an array of all used
fonts; the key “images” would return an array of images, etc.
An array object is dynamic collection of objects that can be accessed via an index.
For instance, an array of images would contain a list of images that can be
randomly accessed, from 0 to n images – 1.
As in all MarkzFrame classes, both MZDictionary and MZArray are derived from
MZObject.
Methods
The “put” function adds any object to the dictionary, associated with the key.
Later, this object can be retrieved by passing the key to the “get” method.
Example:
Methods
Returns the nth element in the array, which is an object that was added earlier.
The index is zero-based.
Removes an object. The first method removes the nth object, while the second
method locates the object that matches obj and removes it.
MZString – constructors
MZString::MZString (MZStr str, long length) – Creates a string from str of length
characters length.
Methods
Returns the position of the first character found (first method) or the string
(second method). If not found, the result is –1. The startPosition parameter is
optional, and can be set to the character to start the search. If the optional
parameter ignoreCase is false, the search is case-sensitive.
Compares for a match (equals), compares a match for the string’s prefix
(startsWith) or its suffix (endsWith). In each method, the ignoreCase is optional,
defaulting to false.
Concatenates (appends) a string to the existing string. Identical functions exist for
Unicode strings.
Inserts a string into the existing string, beginning at position (zero-based). The
second method allows a length parameter.
Returns a numeric value of the string. Decoding occurs until the a non-numeric
character is encountered, or the end of the string, whichever comes first. The
returned value is a double, but can be coerced to an integer if the string value is
known to be a whole number.
Sets the buffer str to the existing string. The first method copies to a c-string, the
second method copies to a pascal string.
File Handling
One of the most problematic areas of portability is file handling. Under Mac OS-9,
for instance, the FSSpec structure is used to identify a file, whereas this is
incompatible with the Windows pathname model. Even the Unix-based OS-X is
somewhat incompatible with Windows since it uses the forward slash (/) and is
unfamiliar with the Windows convention of device notation (e.g., “C:\pathname”).
Additional problems arise if we consider data streams beyond the hard drive, such
as web-based files and internet URL’s.
The MZUrl object contains sufficient information to identify a file location, be it the
hard drive, or an internet file, even a memory-based file, regardless of platform.
The object allows implements constructors, as follows.
MZUrl::MZUrl (MZUrl *basedOn, MZStr path) – Creates a file identifier of a file path,
relative to the basedOn file.
MZUrl::MZUrl (MZStr filename, long dir1, long dir2) – Creates a file based on the
OS-9 “FSSpec” parameters.
MZUrl Methods
Returns TRUE if the file pointed to by the MZUrl exists, FALSE if the file does not
exist.
MZInputStream* openStream (void);
Creates an MZInputStream, an object that can read data from a file stream
(documented below). The stream is based on the file location identified in the
MZUrl. If the stream cannot be created (i.e., the file does not exist), openStream()
returns NULL.
Creates an MZOutputStream, an object that can write data to a file. If the file does
not exist, one is created.
Returns an array of MZUrl’s containing all the files within a directory pointed to by
the MZUrl. If includeSubfolders is TRUE, subfolders within the director are also
iterated. The filter parameter is optional, and contains a special class to examine
each file encountered, accepting or rejecting it to the resulting list. The function
result is an MZArray, which is an object containing an array of other objects
(documented later).
Methods
These three methods read data from the stream, returning non-zero if
unsuccessful. The first two read generic, binary data (fileData is basically an
unsigned char*). The third method loads a string object with byteSize bytes.
Methods
Sets a file extension to be accepted in the file list (such as “.txt”, “.gif”, etc.). You
can set as many extensions as you want. Setting none results in the acceptance
of all file types.
Sets a file (Mac) type to be accepted in the file list. On the PC, this value is
ignored. You can set as many file types as you want. Setting none results in the
acceptable of all types.
Invokes the “getFile” dialog, native to the OS. The prompt is displayed in the
appropriate place (e.g., “Open Document”, “Locate File…”, etc.). The filter
parameter is an optional object that can be subclassed to accept types as they
are encountered. If the user selects a file, an MZUrl object is returned. If no file is
accepted, getFile returns NULL. The resulting MZUrl, if any, can be used to open a
file stream.
Invokes the “putFile” (save) dialog, native to the OS. The prompt is displayed in
the appropriate place, and defName is the default name for the file to be saved
(which can be NULL for no name). If the user doesn’t cancel, putFile returns an
MZUrl object representing the file target. This object can be subsequently used to
create an output stream.
Same as getFile except the user can select more than one file (control-click for PC,
command-click for Mac). If the user does not cancel, getMultipleFiles returns an
array of MZUrl objects representing the path for each file (see MZArray class).