Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

TResourceFile Class Reference

Implements a stream that can be indexed by string keys. More...

#include <resource.h>

Inheritance diagram for TResourceFile::

TObject List of all members.

Public Methods

 TResourceFile (fpstream *aStream)
 ~TResourceFile ()
short count ()
void remove (const char *key)
void flush ()
void* get (const char *key)
const char* keyAt (short i)
void put (TStreamable *item, const char *key)
fpstreamswitchTo (fpstream *aStream, Boolean pack)

Protected Attributes

fpstreamstream
Boolean modified
long basePos
long indexPos
TResourceCollectionindex

Detailed Description

TResourceFile implements a stream (of type fpstream) that can be indexed by string keys.

To provide fast and efficient access to the objects stored in a resource file, TResourceFile objects store the keys in a sorted string collection (using TResourceCollection) along with the position and size of the resource data in the resource file.

Definition at line 243 of file resource.h.


Constructor & Destructor Documentation

TResourceFile::TResourceFile ( fpstream * aStream )
 

Initializes a resource file using the stream given by `aStream' and sets the modified data member to False. The stream must have already been initialized.

During initialization, the TResourceFile constructor looks for a resource file header at the current position of the stream. If a header is not found, the constructor assumes that a new resource file is being created together with a new resource collection.

TResourceFile::~TResourceFile ( )
 

Flushes the resource file, using flush() and then deletes index and stream data members.


Member Function Documentation

short TResourceFile::count ( )
 

Calls index->getCount() to return the number of resource items stored in the associated @reg TResourceCollection.

See also:
index

void TResourceFile::flush ( )
 

If the resource file has not been modified since the last flush (that is, if modified is False), flush() does nothing.

Otherwise, flush() stores the updated index at the end of the stream and updates the resource header at the beginning of the stream. It then calls stream->flush() and resets modified to False.

void * TResourceFile::get ( const char * key )
 

Searches for the given key in the associated resource file collection (given by the pointer index). Returns 0 if the key is not found.

const char * TResourceFile::keyAt ( short i )
 

Uses index->at(i) to return the string key of the i'th resource in the resource file.

See also:
TNSCollection::at

The index of the first resource is zero and the index of the last resource is count() minus one. Using count() and keyAt() you can iterate over all resources in a resource file.

void TResourceFile::put ( TStreamable * item,
const char * key )
 

Adds the streamable object given by `item' to the resource file with the key string given by `key' and sets modified to True.

If the index already contains the key, then the new object replaces the old object; otherwise, the new object is appended in the correct indexed position of the resource file.

void TResourceFile::remove ( const char * key )
 

If the resource indexed by `key' is not found, remove does nothing. Otherwise it calls index->free() to remove the resource.

fpstream * TResourceFile::switchTo ( fpstream * aStream,
Boolean pack )
 

Undocumented.


Member Data Documentation

long TResourceFile::basePos [protected]
 

The base position of the stream (ignoring header information).

Definition at line 323 of file resource.h.

TResourceCollection * TResourceFile::index [protected]
 

A pointer to the associated TResourceCollection object.

Definition at line 331 of file resource.h.

long TResourceFile::indexPos [protected]
 

The current position of the stream relative to the base position.

Definition at line 327 of file resource.h.

Boolean TResourceFile::modified [protected]
 

Set True if the resource file has been modified since the last flush call; otherwise False.

Definition at line 319 of file resource.h.

fpstream * TResourceFile::stream [protected]
 

Pointer to the file stream associated with this resource file.

Definition at line 314 of file resource.h.


The documentation for this class was generated from the following file:
Generated at Sat Sep 22 20:19:32 2001 for TVision by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001