GENERIC
TYPE Rows IS (<>);
TYPE Columns IS (<>);
Max_String_Length: IN Positive;
PACKAGE Spreadsheet IS
------------------------------------------------------------------
--| Specification for generic abstract data object
--| for a simple spreadsheet.
--|
--| Authors: Duane Jarc, Michael Feldman
--| The George Washington University
--| Last Modified: October 1996
------------------------------------------------------------------
TYPE Cells IS PRIVATE;
-- a Cell is a specific pair column/row coordinates
TYPE Blocks IS PRIVATE;
-- a Block is a rectangular section of a spreadsheet bounded by
-- two Cells
TYPE Functions IS (Integer_Minimum, Float_Minimum,
Integer_Maximum, Float_Maximum, Integer_Average,
Float_Average);
-- a spreadsheet cell can contain either a user-supplied value
-- or a computation over a block
FUNCTION "-"(Column: Columns; Row: Rows) RETURN Cells;
-- Pre: Column and Row are defined
-- Post: Returns the given spreadsheet cell
-- For example, A-3 returns the cell A3
FUNCTION "-"(Upper_Left, Lower_Right: Cells) RETURN Blocks;
-- Pre: Upper_Left and Lower_Right are defined
-- Post: Returns the given block
-- For example, (A-3)-(B-10) returns the Block
-- with Cell A-3 in its upper left corner and
-- Cell B-10 in its lower right corner
PROCEDURE Set(Cell: IN Cells; An_Integer: IN Integer);
PROCEDURE Set(Cell: IN Cells; A_Float: IN Float);
PROCEDURE Set(Cell: IN Cells; A_String: IN String);
-- Pre: All parameters are defined
-- Post: Sets the given cell to the given value
PROCEDURE Set(Cell: IN Cells; A_Function: IN Functions; Block: IN Blocks);
-- Pre: All parameters are defined
-- Post: Sets the cell Cell to the value given by computing
-- A_Function over the block Block
-- Example: Set (Cell => B-14,
-- Function => Integer_Maximum,
-- Block => (B-1)-(B-10));
-- sets B14 to the maximum of the column B1-B10
Improper_Type: EXCEPTION;
PRIVATE
TYPE Cells IS RECORD
Column: Columns;
Row: Rows;
END RECORD;
TYPE Blocks IS RECORD
From: Cells;
To: Cells;
END RECORD;
TYPE Types IS (Integer_Type, Float_Type, String_Type, None);
TYPE Values(A_Type: Types := None) IS RECORD
CASE A_Type IS
WHEN Integer_Type =>
Integer_Value: Integer;
WHEN Float_Type =>
Float_Value: Float;
WHEN String_Type =>
String_Value: String(1..Max_String_Length);
WHEN None =>
NULL;
END CASE;
END RECORD;
Sheet: ARRAY(Rows,Columns) OF Values;
END Spreadsheet;