1 / 7

Tutorial Files, Stores

Tutorial Files, Stores. Violeta Seretan LATL. Standard IO access. view provides visual presentation of data views are storable as files open file: Views. Old PROCEDURE Old (ask: BOOLEAN; VAR loc: Files.Locator; VAR name: Files.Name; VAR conv: Converters.Converter): View

pilar
Download Presentation

Tutorial Files, Stores

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial Files, Stores Violeta Seretan LATL

  2. Standard IO access • view • provides visual presentation of data • views are storable as files • open file: Views.Old PROCEDURE Old (ask: BOOLEAN; VAR loc: Files.Locator; VAR name: Files.Name; VAR conv: Converters.Converter): View • save file: Views.Register PROCEDURE Register (view: View; ask: BOOLEAN; VAR loc: Files.Locator; VAR name: Files.Name; VAR conv: Converters.Converter; OUT res: INTEGER) • model • represents some data, without knowing how these data may be represented • IO access functions (for text files): • via TextMappers connected to view's model

  3. Advanced IO access. Files • Module Files • handle aspects of a hierarchical file system • Files.File • a sequence of bytes • identified by name and location (Files.Locator) • informations about file (Files. FileInfo) • indicated access: via Stores.Reader and Stores.Writer

  4. Advanced IO access. Stores • Module Stores • defines a data type Store • Stores.Store is the base type of all storableextensible objects(s.e. objects) • defining storable extensible objects e.g. TYPE MyObject = POINTER TO EXTENSIBLE RECORD (Stores.Store) int: INTEGER; string: Dialog.String END; • allows reading/writing s.e. objects to a file

  5. Internalize/Externalize Procedures • Stores.Internalize and Stores.Externalize define the IO procedures for: • reading s.e. objects, via Stores.Reader • writing s.e. objects, via Stores.Writer • These procedures are to be implemented for the s.e. objects that have been defined e.g. PROCEDURE (object: MyObject) Externalize (VAR writer: Stores.Writer), EXTENSIBLE; BEGIN writer.WriteInt(object.int); writer.WriteString(object.string) END Externalize; PROCEDURE (object: MyObject) Internalize (VAR reader: Stores.Reader), EXTENSIBLE; BEGIN reader.ReadInt(object.int); reader.ReadString(object.string) END Internalize;

  6. Store.Reader: VAR reader: Stores.Reader; file: Files.File; loc: Files.Locator; name: Files.Name; loc := Files.dir.This(""); (* default path *) fileName := "testfile"; file := Files.dir.Old(loc, name, Files.shared); IF file # NIL THEN reader.ConnectTo(file); END Stores.Writer: VAR writer: Stores.Writer; file: Files.File; loc: Files.Locator; loc := Files.dir.This(""); (* default path *) file := Files.dir.New(loc, Files.dontAsk); IF file # NIL THEN writer.ConnectTo(file); END; Reading/Writing Objects to a File • the file to be accessed isthe one connected to:

  7. writing: VAR obj: MyObject; NEW(obj); obj.int := "10"; obj.string := "Ten"; writer.WriteStore(obj) reading: VAR s: Stores.Store; obj: MyObject; reader.ReadStore(s); IF s IS MyObject THEN obj := s(MyObject); Log.Ln; Log.Int(object.int); Log.String(" " + object.string); END; Reading/Writing Objects to a File (cont) • reading/writing the objects: • WriteStore and ReadStore implicitely call Externalize/Internalize

More Related