70 likes | 187 Vues
This tutorial provides an in-depth guide to using Violeta's advanced file I/O and data visualization mechanisms. It covers how to store, access, and manipulate visual representations of data, focusing on procedures for saving and loading storable extensible objects. You'll learn about hierarchical file systems, the use of text mappers, and how to implement internalization and externalization procedures for custom data types. Enhance your understanding of data management in Violeta's framework with practical examples and coding techniques.
E N D
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 • 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
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
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
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;
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:
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