Go to the first, previous, next, last section, table of contents.


CNReaderTbl -- Table for adress of reader-function

SYNOPSIS

#include <CNCL/ReaderTbl.h>

TYPE

CN_READERTBL

BASE CLASSES

CNCL

DERIVED CLASSES

None

RELATED CLASSES

None

DESCRIPTION

CNReaderTbl provides a table of all persistent classes (Reader-Table) and a second table of id's ID-Table. Both tables are realized as dynamic hash-tables.

The first one uses the classname as key for registering in the table, the object stored in it is the reader function pointer (the adress of the reader-function). This table is for checking if a class is registered to be persistent and for calling the reader constructor when objects are taken from the stream.

The other table uses the id as key and stores the according object to this id. The table is used during two occasions. First whenever an object is written to the stream the id is stored in this table. When the same object should be stored again it will be recognized. In addition to the id a special delimitation character is used for indicating this. When the objects are taken from the stream all objects and their old id are stored in this table again. When this special delimitation character apears on the stream the object can be taken out of the table by its id. Thus it is possible to restore containers even if one object appears several times at different locations, e.g at a double linked list.

Constructors:

CNReaderTbl(char* classname, Reader_ptr reader_ptr);
Initializes a new Reader Table entry. Each given classname is added to the table.


Additional types provided by CNReaderTbl are:

typedef CNObject*(*Reader_ptr)(CNPstream&);
This is the type for the reader-function-pointer.


The functions provided by CNReaderTbl are:

static Reader_ptr reader_pointer_by_classname(char* classname);
This function checks if the requested classname is registered in the Reader Table and returns the according Reader_ptr. If it is not registered, a fatal error is yielded.
static bool is_in(long id_key);
Checks if the given id_key is in the id table.
static void add_to_id_tbl(long id_key, CNObject* obj);
static void add_to_id_tbl(long id_key, CNObject& obj);
Adds the persistent object obj to the id table with id_key as its key.
static CNObject* get_from_id_tbl(long id_key);
Returns the persistent object stored in the id table with id_key as the key.
static void reset_id_tbl();
Resets the id table to its initial state (all stored elemts are deleted). This method should be used if You change from the write-to-stream to the read_from_stream sequence.


Go to the first, previous, next, last section, table of contents.