Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,25 +0,0 @@
|
|||
with Ada.Calendar; use Ada.Calendar;
|
||||
|
||||
package Messages is
|
||||
type Message is tagged record
|
||||
Timestamp : Time;
|
||||
end record;
|
||||
|
||||
procedure Print(Item : Message);
|
||||
procedure Display(Item : Message'Class);
|
||||
|
||||
type Sensor_Message is new Message with record
|
||||
Sensor_Id : Integer;
|
||||
Reading : Float;
|
||||
end record;
|
||||
|
||||
procedure Print(Item : Sensor_Message);
|
||||
|
||||
type Control_Message is new Message with record
|
||||
Actuator_Id : Integer;
|
||||
Command : Float;
|
||||
end record;
|
||||
|
||||
procedure Print(Item : Control_Message);
|
||||
|
||||
end Messages;
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
|
||||
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
|
||||
|
||||
package body Messages is
|
||||
|
||||
-----------
|
||||
-- Print --
|
||||
-----------
|
||||
|
||||
procedure Print (Item : Message) is
|
||||
The_Year : Year_Number;
|
||||
The_Month : Month_Number;
|
||||
The_Day : Day_Number;
|
||||
Seconds : Day_Duration;
|
||||
begin
|
||||
Split(Date => Item.Timestamp, Year => The_Year,
|
||||
Month => The_Month, Day => The_Day, Seconds => Seconds);
|
||||
|
||||
Put("Time Stamp:");
|
||||
Put(Item => The_Year, Width => 4);
|
||||
Put("-");
|
||||
Put(Item => The_Month, Width => 1);
|
||||
Put("-");
|
||||
Put(Item => The_Day, Width => 1);
|
||||
New_Line;
|
||||
end Print;
|
||||
|
||||
-----------
|
||||
-- Print --
|
||||
-----------
|
||||
|
||||
procedure Print (Item : Sensor_Message) is
|
||||
begin
|
||||
Print(Message(Item));
|
||||
Put("Sensor Id: ");
|
||||
Put(Item => Item.Sensor_Id, Width => 1);
|
||||
New_Line;
|
||||
Put("Reading: ");
|
||||
Put(Item => Item.Reading, Fore => 1, Aft => 4, Exp => 0);
|
||||
New_Line;
|
||||
end Print;
|
||||
|
||||
-----------
|
||||
-- Print --
|
||||
-----------
|
||||
|
||||
procedure Print (Item : Control_Message) is
|
||||
begin
|
||||
Print(Message(Item));
|
||||
Put("Actuator Id: ");
|
||||
Put(Item => Item.Actuator_Id, Width => 1);
|
||||
New_Line;
|
||||
Put("Command: ");
|
||||
Put(Item => Item.Command, Fore => 1, Aft => 4, Exp => 0);
|
||||
New_Line;
|
||||
end Print;
|
||||
|
||||
-------------
|
||||
---Display --
|
||||
-------------
|
||||
|
||||
procedure Display(Item : Message'Class) is
|
||||
begin
|
||||
Print(Item);
|
||||
end Display;
|
||||
|
||||
end Messages;
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
with Messages; use Messages;
|
||||
with Ada.Streams.Stream_Io; use Ada.Streams.Stream_Io;
|
||||
with Ada.Calendar; use Ada.Calendar;
|
||||
with Ada.Text_Io;
|
||||
|
||||
procedure Streams_Example is
|
||||
S1 : Sensor_Message;
|
||||
M1 : Message;
|
||||
C1 : Control_Message;
|
||||
Now : Time := Clock;
|
||||
The_File : Ada.Streams.Stream_Io.File_Type;
|
||||
The_Stream : Ada.Streams.Stream_IO.Stream_Access;
|
||||
begin
|
||||
S1 := (Now, 1234, 0.025);
|
||||
M1.Timestamp := Now;
|
||||
C1 := (Now, 15, 0.334);
|
||||
Display(S1);
|
||||
Display(M1);
|
||||
Display(C1);
|
||||
begin
|
||||
Open(File => The_File, Mode => Out_File,
|
||||
Name => "Messages.dat");
|
||||
exception
|
||||
when others =>
|
||||
Create(File => The_File, Name => "Messages.dat");
|
||||
end;
|
||||
The_Stream := Stream(The_File);
|
||||
Sensor_Message'Class'Output(The_Stream, S1);
|
||||
Message'Class'Output(The_Stream, M1);
|
||||
Control_Message'Class'Output(The_Stream, C1);
|
||||
Close(The_File);
|
||||
Open(File => The_File, Mode => In_File,
|
||||
Name => "Messages.dat");
|
||||
The_Stream := Stream(The_File);
|
||||
Ada.Text_Io.New_Line(2);
|
||||
while not End_Of_File(The_File) loop
|
||||
Display(Message'Class'Input(The_Stream));
|
||||
end loop;
|
||||
Close(The_File);
|
||||
end Streams_Example;
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
Rebol [
|
||||
title: "Rosetta code: Object serialization"
|
||||
file: %Object_serialization.r3
|
||||
url: https://rosettacode.org/wiki/Object_serialization
|
||||
needs: 2.7.0
|
||||
]
|
||||
; ----------------------------
|
||||
; Define a base "class" Person
|
||||
; ----------------------------
|
||||
; In Rebol, `make object! [...]` creates an object with defined fields (and optionally functions).
|
||||
; Here, Person has two properties: name (string) and age (integer).
|
||||
Person: make object! [
|
||||
name: ""
|
||||
age: 0
|
||||
]
|
||||
|
||||
; ------------------------------------------------
|
||||
; "Inherit" a subclass Student from Person
|
||||
; ------------------------------------------------
|
||||
; Since Rebol doesn't have classical inheritance, `make Person [...]`
|
||||
; makes a copy of the Person object and lets you add or override fields.
|
||||
; Student adds an extra property: grade (e.g., "A", "B", etc.)
|
||||
Student: make Person [
|
||||
grade: ""
|
||||
]
|
||||
|
||||
; ------------------------------------------------
|
||||
; Inherit another subclass Teacher from Person
|
||||
; ------------------------------------------------
|
||||
; Teacher adds an extra property: subject (teaching subject)
|
||||
Teacher: make Person [
|
||||
subject: ""
|
||||
]
|
||||
|
||||
; ----------------------------------
|
||||
; Create specific instances of each
|
||||
; ----------------------------------
|
||||
; Values in brackets override default properties when creating the object.
|
||||
john: make Person [name: "John" age: 40]
|
||||
sally: make Student [name: "Sally" age: 18 grade: "A"]
|
||||
bob: make Teacher [name: "Bob" age: 50 subject: "Math"]
|
||||
|
||||
; ------------------------------------------------
|
||||
; Print text in yellow (assuming ANSI color functions are set up)
|
||||
; ------------------------------------------------
|
||||
print "Original instances:"
|
||||
|
||||
; ------------------------------------------------
|
||||
; `probe` prints the value in developer-readable format and returns it
|
||||
; This is useful for quickly seeing object content
|
||||
; ------------------------------------------------
|
||||
probe john
|
||||
probe sally
|
||||
probe bob
|
||||
|
||||
; ------------------------------------------------
|
||||
; Create a block containing all three objects
|
||||
; `reduce` evaluates each word and inserts its value into the block
|
||||
; ------------------------------------------------
|
||||
objects: reduce [john sally bob]
|
||||
|
||||
; ------------------------------------------------
|
||||
; Save all object data (including words, values, and types) to a file
|
||||
; `save/all` preserves the complete object structure
|
||||
; ------------------------------------------------
|
||||
save/all %objects.dat objects
|
||||
|
||||
; ------------------------------------------------
|
||||
; Show header for loaded instances
|
||||
; ------------------------------------------------
|
||||
print "Loaded instances:"
|
||||
|
||||
; ------------------------------------------------
|
||||
; Load objects back from the file
|
||||
; `load` reconstructs the original structures from the saved format
|
||||
; ------------------------------------------------
|
||||
read-objects: load %objects.dat
|
||||
|
||||
; ------------------------------------------------
|
||||
; Iterate over loaded objects and display them
|
||||
; ------------------------------------------------
|
||||
foreach obj read-objects [
|
||||
probe obj
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue