ETHZ_Logo RAMSES_Logo_Right   RAMSES   RAMSES_Logo_Left Systems Ecology  
Start    search button      Modules:   A-Z   Function   Layer        QuickRefs:   DM   AuxLib   AuxLibE   SciLib   EasyMW   MW   ISIS   RMSLib

DEFINITION MODULE TableLists;

  (*******************************************************************

    Module  TableLists     (Version 1.0)

      Copyright (c) 1996-2006 by Andreas Fischlin, Dimitrios Gyalistras
      and ETH Zurich.

    Purpose   Extends the functionality of module TableHandler.

    Remarks   Functionality:

              1) Maintains for each table a linear list of
                 table items in the order of their declaration.
              2) Supports retrieval of table items via an
                 integer key.
              3) Supports storing of one attribute per table or
                 table item.
              4) Supports installation of an arbitrary number
                 of remove handlers per table or table item.
              5) Supports an arbitrary number of tag records per
                 table item.


    Programming

      o Design
        Andreas Fischlin          16/01/1996
        Dimitrios Gyalistras      17/04/1998

      o Implementation
        Andreas Fischlin          16/01/1996
        Dimitrios Gyalistras      17/04/1998


    ETH Zurich
    Systems Ecology
    CHN E 35.1
    Universitaetstrasse 16
    8092 Zurich
    SWITZERLAND

    URLs:
        <mailto:RAMSES@env.ethz.ch>
        <http://www.sysecol.ethz.ch>
        <http://www.sysecol.ethz.ch/SimSoftware/RAMSES>


    Last revision of definition:  19/05/1998  AF

  *******************************************************************)


  FROM SYSTEM IMPORT ADDRESS;
  IMPORT DMLanguage;


  (********************************)
  (*#####   Error handling   #####*)
  (********************************)

  CONST
    TableListsOffset         = DMLanguage.userBase + 700;
    allOk                    = DMLanguage.allOk;
    insuffMem                = DMLanguage.insuffMem;
    unknownTable             = TableListsOffset + 1;
    unknownItem              = TableListsOffset + 2;
    tblAlreadyDeclared       = TableListsOffset + 3;
    itemAlreadyInTable       = TableListsOffset + 4;
    itemKeyAlreadyUsed       = TableListsOffset + 5;
    identAlreadyUsedWithAKey = TableListsOffset + 6;
    badItemKeySpecif         = TableListsOffset + 7;
    errCreatingTable         = TableListsOffset + 8;
    errRecordingItem         = TableListsOffset + 9;
    errCreatingHashTbl       = TableListsOffset + 10;
    errStoringHashTblKey     = TableListsOffset + 11;
    errStoringHashTblEntry   = TableListsOffset + 12;
    errDeclaringEventClass   = TableListsOffset + 13;
    errAddingRemoveHandler   = TableListsOffset + 14;


  (**************************************)
  (*#####   General declarations   #####*)
  (**************************************)

  TYPE
    Table;
    Item;
    Tag;
    Attribute = ADDRESS;
    TableProc = PROCEDURE( Table );
    ItemProc  = PROCEDURE( Item );

  VAR
    undefTable     : Table;       (* read only *)
    undefItem      : Item;        (* read only *)
    undefTag       : Tag;         (* read only *)
    undefItemKey   : INTEGER;     (* read only *)
    undefAttribute : Attribute;   (* read only *)


  (************************)
  (*#####   Tables   #####*)
  (************************)

  PROCEDURE InitTable      ( VAR t       : Table;
                             name        : ARRAY OF CHAR;
                             VAR resCode : INTEGER );

  PROCEDURE DeleteTable    ( t: Table );

  PROCEDURE TableExists    ( t: Table ): BOOLEAN;

  PROCEDURE EntriesInTable ( t: Table ): INTEGER;

  PROCEDURE GetTableName   ( t        : Table;
                             VAR name : ARRAY OF CHAR );

  PROCEDURE AttachTableAttr( t           : Table;
                             a           : Attribute;
                             VAR resCode : INTEGER );

  PROCEDURE TableAttr      ( t : Table ): Attribute;

  PROCEDURE AttachTableRemoveHdlr( t           : Table;
                                   tp          : TableProc;
                                   VAR resCode : INTEGER );

  PROCEDURE DetachTableRemoveHdlr( t  : Table;
                                   tp : TableProc );


  (**********************************************)
  (*#####   Management of items and tags   #####*)
  (**********************************************)

  PROCEDURE RecordItem    ( t            : Table;
                            VAR itemId   : ARRAY OF CHAR;            (* VAR for speed-up only *)
                            VAR descr    : ARRAY OF CHAR;            (* VAR for speed-up only *)
                            VAR r        : REAL;
                            storeWithKey : BOOLEAN;
                            key          : INTEGER;
                            attr         : Attribute;
                            VAR resCode  : INTEGER );

  PROCEDURE DeleteItem    ( t           : Table;
                            VAR itemId  : ARRAY OF CHAR );           (* VAR for speed-up only *)

  PROCEDURE AttachItemAttr( t           : Table;
                            VAR itemId  : ARRAY OF CHAR;             (* VAR for speed-up only *)
                            attr        : Attribute;
                            VAR resCode : INTEGER );

  PROCEDURE AddTag        ( t           : Table;
                            VAR itemId  : ARRAY OF CHAR;             (* VAR for speed-up only *)
                            class       : LONGINT;
                            attr        : Attribute;
                            VAR resCode : INTEGER );

  PROCEDURE DelTag        ( t           : Table;
                            VAR itemId  : ARRAY OF CHAR;             (* VAR for speed-up only *)
                            class       : LONGINT;
                            attr        : Attribute );

  PROCEDURE AttachItemRemoveHdlr( t           : Table;
                                  VAR itemId  : ARRAY OF CHAR;       (* VAR for speed-up only *)
                                  ip          : ItemProc;
                                  VAR resCode : INTEGER );

  PROCEDURE DetachItemRemoveHdlr( t          : Table;
                                  VAR itemId : ARRAY OF CHAR;        (* VAR for speed-up only *)
                                  ip         : ItemProc );



  (***************************************************)
  (*#####   Traversing of items and tag lists   #####*)
  (***************************************************)

  PROCEDURE FrstItem( t : Table ): Item;

  PROCEDURE NextItem( item: Item  ): Item;  (* assumes item is correct *)

  PROCEDURE PrevItem( item: Item  ): Item;  (* assumes item is correct *)

  PROCEDURE LastItem( t : Table ): Item;


  PROCEDURE FrstTagOfItem( t          : Table;
                           VAR itemId : ARRAY OF CHAR ): Tag;  (* VAR for speed-up only *)

  PROCEDURE LastTagOfItem( t          : Table;
                           VAR itemId : ARRAY OF CHAR ): Tag;  (* VAR for speed-up only *)


  PROCEDURE FrstTag      ( item: Item ): Tag;  (* assumes item is correct *)

  PROCEDURE NextTag      ( tag : Tag ): Tag;   (* assumes tag is correct *)

  PROCEDURE PrevTag      ( tag : Tag ): Tag;   (* assumes tag is correct *)

  PROCEDURE LastTag      ( item: Item ): Tag;  (* assumes item is correct *)



  (**********************************************************)
  (*#####   Retrieval and setting of tag information   #####*)
  (**********************************************************)

  PROCEDURE TagAvailable( t          : Table;
                          VAR itemId : ARRAY OF CHAR;             (* VAR for speed-up only *)
                          class      : LONGINT;
                          attr       : Attribute ): BOOLEAN;

  PROCEDURE TagExists   ( item  : Item ;                          (* assumes item is correct *)
                          class : LONGINT;
                          attr  : Attribute ): BOOLEAN;


  PROCEDURE NoOfTags    ( t          : Table;
                          VAR itemId : ARRAY OF CHAR ): INTEGER;  (* VAR for speed-up only *)

  PROCEDURE TagCount    ( item: Item ): INTEGER;                  (* assumes item is correct *)


  PROCEDURE TagClass    ( tag : Tag ): LONGINT;                   (* assumes tag is correct *)

  PROCEDURE TagAttr     ( tag : Tag ): Attribute;                 (* assumes tag is correct *)


  PROCEDURE SetTagClass ( tag   : Tag;
                          class : LONGINT );                      (* assumes tag is correct *)

  PROCEDURE SetTagAttr  ( tag  : Tag ;
                          attr : Attribute );                     (* assumes tag is correct *)


  (***************************************)
  (*#####   Information retrieval   #####*)
  (***************************************)

  (*---------------------*)
  (*=====   Varia   =====*)
  (*---------------------*)

  PROCEDURE ItemExists    ( t          : Table;
                            VAR itemId : ARRAY OF CHAR ): BOOLEAN;   (* VAR for speed-up only *)

  PROCEDURE FindReal      ( t          : Table;
                            VAR itemId : ARRAY OF CHAR ): REAL;      (* VAR for speed-up only *)

  PROCEDURE ItemOrd       ( item: Item ): INTEGER;                   (* assumes item is correct *)

  PROCEDURE ItemsTable    ( item: Item ): Table;                     (* assumes item is correct *)


  (*--------------------------------------------*)
  (*=====   Retrieval of item identifier   =====*)
  (*--------------------------------------------*)

  PROCEDURE GetItemId     ( item       : Item;                       (* assumes item is correct *)
                            VAR itemId : ARRAY OF CHAR );

  PROCEDURE RetrieveItemId( t          : Table;
                            key        : INTEGER;
                            VAR itemId : ARRAY OF CHAR );


  (*--------------------------------------------*)
  (*=====   Retrieval of item descriptor   =====*)
  (*--------------------------------------------*)

  PROCEDURE GetDescrOfItem( t          : Table;
                            VAR itemId : ARRAY OF CHAR;              (* VAR for speed-up only *)
                            VAR descr  : ARRAY OF CHAR );

  PROCEDURE GetItemDescr  ( item       : Item;                       (* assumes item is correct *)
                            VAR descr  : ARRAY OF CHAR );

  PROCEDURE RetrieveDescr ( t          : Table;
                            key        : INTEGER;
                            VAR descr  : ARRAY OF CHAR );


  (*----------------------------------*)
  (*=====   Retrieval of Items   =====*)
  (*----------------------------------*)

  PROCEDURE ItemWithId    ( t          : Table;
                            VAR itemId : ARRAY OF CHAR ): Item;      (* VAR for speed-up only *)

  PROCEDURE ItemWithKey   ( t   : Table;
                            key : INTEGER ): Item;

  PROCEDURE ItemWithAttr  ( t    : Table;
                            attr : Attribute ): Item;

  PROCEDURE ItemWithOrd   ( t   : Table;
                            ord : INTEGER ): Item;


  (*--------------------------------*)
  (*=====   Retrieval of key   =====*)
  (*--------------------------------*)

  PROCEDURE KeyOfItem     ( t          : Table;
                            VAR itemId : ARRAY OF CHAR ): INTEGER;   (* VAR for speed-up only *)

  PROCEDURE ItemKey       ( item: Item ): INTEGER;                   (* assumes item is correct *)


  (*--------------------------------------*)
  (*=====   Retrieval of attribute   =====*)
  (*--------------------------------------*)

  PROCEDURE AttrOfItem    ( t          : Table;
                            VAR itemId : ARRAY OF CHAR ): Attribute; (* VAR for speed-up only *)

  PROCEDURE ItemAttr      ( item: Item ): Attribute;                 (* assumes item is correct *)

  PROCEDURE RetrieveAttr  ( t   : Table;
                            key : INTEGER ): Attribute;


END TableLists.

  Contact RAMSES@env.ethz.ch Last updated: 25-Jul-2011 [Top of page]