tgff/
content.rs

1#![allow(missing_copy_implementations)]
2
3use std::collections::HashMap;
4
5/// The content of a TGFF file.
6pub struct Content {
7    /// Global attributes such as `HYPERPERIOD`.
8    pub attributes: HashMap<String, usize>,
9    /// Task graphs.
10    pub graphs: Vec<Graph>,
11    /// Data tables.
12    pub tables: Vec<Table>,
13}
14
15/// A task graph.
16pub struct Graph {
17    /// The name of the graph.
18    pub name: String,
19    /// The ID of the graph.
20    pub id: usize,
21    /// Graph attributes such as `PERIOD`.
22    pub attributes: HashMap<String, usize>,
23    /// Vertices representing tasks.
24    pub tasks: Vec<Task>,
25    /// Edges representing dependencies between the tasks.
26    pub arcs: Vec<Arc>,
27    /// Hard deadlines of a subset of the tasks.
28    pub deadlines: Vec<Deadline>,
29}
30
31/// A node in a graph representing a task.
32pub struct Task {
33    /// The ID of the task.
34    pub id: usize,
35    /// The type of the task.
36    pub kind: usize,
37}
38
39/// An edge in a graph connecting two tasks.
40pub struct Arc {
41    /// The ID of the arc.
42    pub id: usize,
43    /// The ID of the source task.
44    pub from: usize,
45    /// The ID of the destination task.
46    pub to: usize,
47    /// The type of the arc.
48    pub kind: usize,
49}
50
51/// The deadline of a task.
52pub struct Deadline {
53    /// The ID of the deadline.
54    pub id: usize,
55    /// The ID of the task.
56    pub on: usize,
57    /// The time associated with the deadline.
58    pub at: usize,
59}
60
61/// A data table.
62pub struct Table {
63    /// The name of the table.
64    pub name: String,
65    /// The ID of the table.
66    pub id: usize,
67    /// Table attributes.
68    pub attributes: HashMap<String, f64>,
69    /// The columns of the table.
70    pub columns: Vec<Column>,
71}
72
73/// A column of a table.
74pub struct Column {
75    /// The name of the column.
76    pub name: String,
77    /// The data contained in the column.
78    pub data: Vec<f64>,
79}
80
81#[inline]
82pub fn new() -> Content {
83    Content {
84        attributes: HashMap::new(),
85        graphs: Vec::new(),
86        tables: Vec::new(),
87    }
88}
89
90#[inline]
91pub fn new_graph(name: String, id: usize) -> Graph {
92    Graph {
93        name: name,
94        id: id,
95        attributes: HashMap::new(),
96        tasks: Vec::new(),
97        arcs: Vec::new(),
98        deadlines: Vec::new(),
99    }
100}
101
102#[inline]
103pub fn new_task(id: usize, kind: usize) -> Task {
104    Task { id: id, kind: kind }
105}
106
107#[inline]
108pub fn new_arc(id: usize, from: usize, to: usize, kind: usize) -> Arc {
109    Arc { id: id, from: from, to: to, kind: kind }
110}
111
112#[inline]
113pub fn new_deadline(id: usize, on: usize, at: usize) -> Deadline {
114    Deadline { id: id, on: on, at: at }
115}
116
117#[inline]
118pub fn new_table(name: String, id: usize) -> Table {
119    Table {
120        name: name,
121        id: id,
122        attributes: HashMap::new(),
123        columns: Vec::new(),
124    }
125}
126
127#[inline]
128pub fn new_column(name: String) -> Column {
129    Column { name: name, data: vec![] }
130}