BinaryRelations Classes Reference


Andrew Girow

Copyright © 1996 Andrew Girow. All Rights Reserved.


1. BObj Class

The BObj class (BINARY OBJECT) implements an abstract "binary object in memory" type.

Member functions:


BObj(void);
Default constructor.


BObj(int size);
Constructs a binary object with the given size. On successful completion, isNULL returns 0, otherwise 1.


BObj(BObj &source);
Copy constructor. Constructs a binary object from the given source object. On successful completion, isNULL returns 0, otherwise 1.


~BObj(void);
Removes the object from the memory.


int isNULL(void);
If it is a NULL-object isNULL returns 1, otherwise it returns 0. There is a 1:1 correspondence between the NULL-object and the NULL pointer.


char *Data(void);
Returns a pointer to this object.


int Size(void);
Returns the object size.

Read functions are used to read data from the given object:


BR_LONG ReadLong(void);
Read a long word (4 bytes).


float ReadFloat(void);
Read a float (4 bytes).


double ReadDouble(void);
Read a double (8 bytes).


BR_SHORT ReadShort(void);
Read a two byte word.


char ReadChar(void);
Read a single byte character.


char *ReadString(void);
Read a null terminated string. String is limited to 256 chars including null terminator.


BOID ReadOid4(void);
Read an object identity. Assumes Oid4 is 4 bytes.

Write functions are used to write data to the given object:


void WriteLong(BR_LONG data);
Write a long word (4 bytes).


void WriteFloat(float data);
Write a float (4 bytes).


void WriteDouble(double data);
Write a double (8 bytes).


void WriteShort(BR_SHORT data);
Write a two byte word.


void WriteChar(char data);
Write a single byte character.


void WriteString(char *string);
Write a null terminated string. String is limited to 256 chars including null terminator.


void WriteOid4(Oid4 id);
Write an object identity. Assumes Oid4 is 4 bytes.


int operator! ()
See isNULL member function.


BObj &operator=(BObj &source)
Copy operator.


2. BRel Class

The BRel class (BINARY RELATION) provides a simple mechanism for associating two BINARY OBJECT types, known as the value and the key, in one BINARY RELATION type.

Member functions:


BRel(void);
Constructor.


~BRel(void);
Destructor.


int isNULL(void);
Returns the relation state. If the relation is not open it returns 1, otherwise it returns 0.

Open/Close functions:


int Open(char *relation_name);
Opens a binary relation with the given name. On successful completion, Open returns 1. In the event of error, it returns 0. You can simultaneously open up to 40 relations.


int Close(void);
Closes the relation. On successful completion, brClose returns 1. In the event of error it returns 0.

Update functions:


int Add(BObj &key, BObj &value );
Adds the given pair of key and value to the relation only if it is not already a member. If it is found in the relation Add does nothing. On successful completion, Add returns 1. In the event of error it returns 0.


int Destroy(void);
Removes the current pair the relation. If the relation is empty, Destroy does nothing. On successful completion, brDestroy returns 1. In the event of error it returns 0.


int DestroyAll(void);
Removes all pairs from the relation. If the relation is empty, DestroyAll does nothing. On successful completion, DestroyAll returns 1. In the event of error it returns 0.


int Update(BObj &value);
Updates the current pair with the value. On successful completion, Update returns 1. In the event of error it returns 0.

Iterate functions:


int First(void);
Moves the current position to the first stored pair. On successful completion, First returns 1. In the event of error it returns 0.


int Last(void);
Moves the current position to the last stored pair. On successful completion, Last returns 1. In the event of error it returns 0.


int Next(void);
Moves the current position to the next stored pair. On successful completion, Next returns 1. In the event of error it returns 0.


int Prev(void);
Moves the current position to the previos stored pair. On successful completion, Prev returns 1. In the event of error it returns 0.


BObj &Key(void);
Returns a pointer to the key object of the current pair. If there is an error or if the relation is empty it returns NULL-object.


BObj &KeyObj(BR *rel);
Returns a pointer to the key object of the current pair of the relation.


BObj &Value(void);
Returns a pointer to the value object of the current pair. If there is an error or if the relation is empty it returns NULL-object.


BObj &ValueObj(void);
Returns a pointer to the value object of the current pair of the relation.

Evaluate functions:


BObj &Eval(BObj &key);
Evaluates the value in the relation by the supplied key. Returns the value object in the relation that has a given key. NULL-object is returned if no pair meets the condition. In the event of error it returns NULL-object.


BObj &EvalFirst(BObj &key);
Evaluates the first value in the relation by the supplied key. Returns the first value object in the relation that has a given key. NULL-object is returned if no pair meets the condition. In the event of error it returns NULL-object.


BObj &EvalLast(BObj &key);
Evaluates the last value in the relation by the supplied key. Returns the last value object in the relation that has a given key. NULL-object is returned if no pair meets the condition. In the event of error it returns NULL-object.

Test function:
int Test(BObj &key, BObj &value);
Returns 1 if the relation contains the given pair; otherwise it returns 0.


int Card(void);
Returns the relation cardinality: UNIQUE or MULTIPLE.


unsigned long Count(void);
Returns the number of pairs in the relation.


int operator! () { return isNULL(); }
See isNULL(void).


BObj &operator()();
See Value(void).


BObj &operator()(BObj &key);
See Eval(BObj &key).


BObj &operator()(BObj &key, int dir);
When dir == FIRST see EvalFirst(BObj &key) and when dir == LAST see EvalLast(BObj &key).


2. BData Class

The BData class (DATABASE) is a collection of binary relations.

Member functions:

Open/close functions:
static int Create(char *database_name,int num);
Constructs and "zeroes" a database (and associated file) with the given name and maximum number of relations. On successful completion, Create returns 1; otherwise it returns 0.


static int Open(char *database_name);
Opens a database (and associated file) with the given name. On successful completion, Open returns 1; ottherwise it returns 0.


static int Close(void);
Closes the database (and associated file). On successful completion, Close returns 1. In the event of error it returns 0.

Update functions:
static int Add(char *relation_name,int keysz, int valuesz, int crd);
Adds a new relation to the database only if it is not already a member. On successful completion, Add returns 1. In the event of error, it returns 0.

Parameters:

name     name of relation
keysz    size of key object
valuesz  size of value object
crd      relation cardinality is one of enumeration:
         enum { UNIQUE = 0, MULTIPLE = 1 };
You can not create a relation with the sum of keysz and valuesz more than 336 bytes.


int Destroy(char *relation_name);
Removes the given relation from the databases. If the relation is not found or the database is empty, brDBDestroy does nothing. On successful completion, Destroy returns 1. In the event of error it returns 0.

Access functions:
char *First(void);
Returns the name of the first relation in the database. In the event of error it returns 0.


char *Next(void);
Returns the name of the next relation in the database. In the event of error it returns 0.


int Test(char *relation_name);
Returns 1 if the relation is in the database; otherwise it returns 0.


int Max(void);
Returns the maximum number of relations in the database.


int Count(void);
Returns the current number of relations in the database.


void Clear(void);
Clears the database state.


int State(void);
Returns the database state. If an error occurs when a BR library function called, an internal state of the database is set. You retrieve the error code for the last operation that reported an error by calling State. It returns the database state from the enumeration:

BR_OK            =  0,  /* No error */
BR_FAIL          = -1,  /* Last operation failed */
BR_TOOMANYOPENBR = -2,  /* Too many open relations */
BR_NOENTRY       = -3,  /* No such relation */
BR_READFAIL      = -4,  /* Read error */
BR_WRITEFAIL     = -5,  /* Write error */
BR_INVARG        = -6,  /* Invalid argument */
BR_OFFSET        = -7   /* Invalid offset */


Copyright © 1996 Andrew Girow. All Rights Reserved.
Last updated: November 15, 1996 1