(* * * This file defines the room database as described in * * Section 2.5.1 of the Requirements Document * *) module RoomDB; export RoomDB, RoomRecord, BuildingName, RoomNumber, RoomType; obj RoomDB is components: rr:RoomRecord*; description: (* This is the top-level object for a room database containing room records *); end RoomDB; obj RoomRecord is components: bn:BuildingName and rn:RoomNumber and rt:RoomType and rh:RoomHours and rc:RoomCapacity and rf:RoomFeature*; description: (* This is the object which contains all information about a particular room *); end RoomRecord; obj BuildingName is components: string; description: (* This object holds the name of the building (given by the university) as a freeform string. *); end BuildingName; obj RoomNumber is components: string; description: (* This object holds the name/number of the room (given by the university) as a freeform string. *); end RoomNumber; obj RoomType is components: Lecture or Lab; description: (* A room at Cal Poly is either Lecture or Lab type *); end RoomType; obj Lecture description: (* This is just to denote that the room is lecture type. *); end Lecture; obj Lab description: (* This is just to denote that the toom is Lab type. *); end Lab; obj RoomHours is components: days: Day* and rng: Range*; description: (* The room's open hours are input into the editing dialog as days and ranges of contiguous hours. *); end RoomHours; obj Day is components: M or T or W or R or F or S or U; description: (* A day is denoted by a letter of the alphabet corresponding to a day of the week; *); end Day; obj M(*Monday*); obj T(*Tuesday*); obj W(*Wednesday*); obj R(*thuRsday*); obj F(*Friday*); obj S(*Saturday*); obj U(*sUnday*); obj Range is components: sh: startHour, eh: endHour; description: (* Open Hour ranges for a room are denoted by a valid starting integer, a dash, and a valid ending integer *); end Range; obj startHour is components: integer; description: (* The start hour is just a valid integer representing the hour in which the room opens *); end startHour; obj endHour is components: integer; description: (* The end hour is just a valid integer representing the hour in which the room closes *); end endHour; obj RoomCapacity is components: integer; description: (* An integer value corresponding to the number of students that the room can legally hold *); end RoomCapacity; obj RoomFeature is components: FeatureName and fc: FeatureCount; description: (* This is intended for use with the NeededFacilities of the Courses. FeatureName may be any string the admin chooses, but if its corresponding FeatureCount is less than 1, the RoomFeature will not be stored. *); end RoomFeature; obj FeatureName is components: string; description: (* A freeform string used as the name of a feature in the current room *); end FeatureName; obj FeatureCount is components: integer; description: (* The count of the named feature *); end FeatureCount; obj valid is components: boolean; description: (* A boolean for use with testing certain preconditions and postconditions *); end valid; op AddRoomRecord is inputs: rdb:RoomDB, rr:RoomRecord; outputs: rdb':RoomDB; description: (* Adds exactly (no more and no less) the RoomRecord information input by the Scheduling Administrator into a new RoomRecord in the Room Database. It also does not remove or change any previous RoomRecords or the data in them. If the RoomRecord is not unique, it calls ChangeRoomRecord on the new data instead *); pre: isUnique(rr); post: ; end AddRoomRecord; op DeleteRoomRecord is inputs: rdb:RoomDB, rr:RoomRecord; outputs: rdb':RoomDB; description: (* Only (no more, no less) removes the selected RoomRecord from the RoomDB, popping up a confirmation window to confirm that this is what the Scheduling Administrator desires. *); pre: ; post: ; end DeleteRoomRecord; op ChangeRoomRecord is inputs: rdb:RoomDB, rr:RoomRecord, rr':RoomRecord; outputs: rdb':RoomDB; description: (* If and only if an old RoomRecord has been selected and new data exists in one or more of the RoomRecord fields, this operation only (no more and no less) replaces the old RoomRecord selected by the Scheduling Administrator with the new RoomRecord containing the new data. *); pre: (rr in rdb); post: isUnique(rr'); end ChangeRoomRecord; function isUnique is inputs: rr:RoomRecord; outputs: valid; description: (* Checks to see if the combination of Building, RoomNumber, and RoomType is unique. If so, valid is set to true. Otherwise, valid is set to false. *); pre: ; post: ; end isUnique; function validDays is inputs: dy:Day*; outputs: valid; description: (* Checks all the days in the RoomHours object to see if they are valid. Sets the boolean true if they are, false if not. *); pre: ; post: ; end validDays; function validHours is inputs: rng:Range*; outputs: valid; description: (* Checks all the hours in the RoomHours object to see if they are valid. Sets the boolean true if they are, false if not. Also returns false if a startHour is greater than an endHour. *); pre: ; post: ; end validHours; function validCount is inputs: rf:RoomFeature, valid; outputs: valid; description: (* Checks to see if the FeatureCount of a RoomFeature is greater than 0. If so, valid is set to true and the RoomFeature is saved. Otherwise, valid is set to false and the RoomFeature is removed. *); pre: ; post: ; end validCount; end RoomDB;