1 % (c) 2009-2022 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
2 % Heinrich Heine Universitaet Duesseldorf
3 % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
4 :- module(pltables, [
5 new_table/2, add_column/3,
6 pltable/2, pltable_header/3,
7 delete_tables/0,
8 pltable_row/3, add_row/3,
9 tables_to_html/2, tables_to_html_stream/2,
10 tables_to_latex/2, tables_to_latex_stream/2,
11 tables_to_xml/2, tables_to_xml_stream/2,
12 tables_to_csv/2, tables_to_csv_stream/2
13 ]).
14
15 :- use_module(pltables_export).
16 :- use_module(probsrc(self_check)).
17 :- use_module(probsrc(module_information)).
18
19 :- module_info(group,pltables).
20 :- module_info(description,'This module is used to generate, store and export coverage tables.').
21
22 :- volatile pltable/2, pltable_header/3, pltable_row/3.
23 :- dynamic pltable/2, pltable_header/3, pltable_row/3.
24
25 :- assert_must_succeed((pltables:new_table(a,[]),pltables:delete_tables,\+(pltables:pltable(a,[])))).
26 delete_tables :-
27 retractall(pltable(_,_)),
28 retractall(pltable_header(_,_,_)),
29 retractall(pltable_row(_,_,_)).
30
31 :- assert_must_succeed((pltables:new_table(a,[]),pltables:delete_tables)).
32 :- assert_must_succeed((pltables:new_table(aa,[]),pltables:new_table(bb,[]),pltables:delete_tables)).
33 :- assert_must_fail((pltables:new_table(x,[]),pltables:new_table(x,[]),pltables:delete_tables)).
34 % As the above test fails, delete_tables is not called. The following test serves as a cleanup routine
35 :- assert_must_succeed(pltables:delete_tables).
36 new_table(Name, Attributes) :-
37 pltable(Name,Attributes) -> false ; assertz(pltable(Name, Attributes)).
38
39 add_column(TableName, ColumnText, Attributes) :-
40 pltable(TableName, _),
41 ( retract(pltable_header(TableName, OldHeadings, OldAttributes)) ->
42 append(OldAttributes, [Attributes], NewAttributes),
43 append(OldHeadings, [ColumnText], NewHeadings),
44 assertz(pltable_header(TableName, NewHeadings, NewAttributes))
45 ;
46 assertz(pltable_header(TableName, [ColumnText], [Attributes]))
47 ).
48
49 add_row(TableName, Entries, Attributes) :-
50 pltable_header(TableName, Columns, _),
51 length(Columns, NrOfColumns),
52 length(Entries, NrOfColumns),
53 assertz(pltable_row(TableName, Entries, Attributes)).
54