ios_1_system.cpp
Go to the documentation of this file.
1 /** @file ios_1_system.cpp
2 
3 Tutorial, I/O systems
4 
5 
6 @ingroup Tutorials
7 
8 @include ios_1_system.cpp
9 
10 */
11 
12 #include "libfaudes.h"
13 
14 // make the faudes namespace available to our program
15 using namespace faudes;
16 
17 
18 
19 /////////////////
20 // main program
21 /////////////////
22 
23 int main() {
24 
25  ////////////////////////////////////////////
26  // Constructors
27  ////////////////////////////////////////////
28 
29  // construct from file
30  IoSystem sys1("data/ios_system1.gen");
31 
32  // copy construct
33  IoSystem sys2(sys1);
34 
35  // assign
36  IoSystem sys3 = sys2;
37 
38  // inspect result on console
39  std::cout << "################################\n";
40  std::cout << "# tutorial, io system 1 \n";
41  sys3.Write();
42  std::cout << "################################\n";
43 
44  // graph output requires, "dot" binary in $PATH
45  try {
46  sys1.GraphWrite("tmp_ios_system1.svg");
47  } catch(faudes::Exception& exception) {
48  std::cout << "warning: cannot execute graphviz' dot. " << std::endl;
49  }
50 
51  // output for doku
52  sys1.Write("tmp_ios_system1.gen");
53 
54 
55  ///////////////////////////////////////////////
56  // Inspect/Edit I/O attributes
57  ///////////////////////////////////////////////
58 
59  // events, result on console
60  std::cout << "################################\n";
61  std::cout << "# input events, output events\n";
62  sys3.InputEvents().Write();
63  sys3.OutputEvents().Write();
64  std::cout << "################################\n";
65 
66  // maniputlate some state attributes
67  // (to configure set state, see also IoSystem())
68  sys3.SetOutputState("s1");
69  sys3.SetInputState("s3");
70  sys3.ClrOutputState("s2");
71 
72  // swap event status all together
73  EventSet inevs = sys3.InputEvents();
74  EventSet outevs = sys3.OutputEvents();
75  sys3.ClrOutputEvent(outevs);
76  sys3.SetInputEvent(outevs);
77  sys3.ClrInputEvent(inevs);
78  sys3.SetOutputEvent(inevs);
79 
80  // inspect result on console
81  std::cout << "################################\n";
82  std::cout << "# tutorial, manipulated io system 1 \n";
83  sys3.Write();
84  std::cout << "################################\n";
85 
86  ///////////////////////////////////////////////
87  // Test I/O structure
88  ///////////////////////////////////////////////
89 
90  // the test will set the state attributes accordingly
91  bool isio=IsIoSystem(sys1);
92 
93  // sys1 from file will pass the test
94  if(!isio) std::cout << "#### test FAILED (test case error) \n";
95 
96  // report
97  std::cout << "################################\n";
98  std::cout << "# tutorial, sys1 test io properties \n";
99  sys1.InputStates().Write();
100  sys1.OutputStates().Write();
101  std::cout << "################################\n";
102 
103  // however, the input is not free
104  bool isfree=IsInputLocallyFree(sys1);
105  if(isfree) std::cout << "#### test PASSED (test case error) \n";
106  IoFreeInput(sys1);
107 
108  // report
109  std::cout << "################################\n";
110  std::cout << "# tutorial, sys1 with free input\n";
111  sys1.Write();
112  std::cout << "################################\n";
113 
114  // output for doku
115  sys1.Write("tmp_ios_system1f.gen");
116 
117  // however, the input is still not omega-free
118  StateSet qerr;
119  bool iswfree=IsInputOmegaFree(sys1,qerr);
120  if(iswfree) std::cout << "#### test PASSED (test case error) \n";
121 
122  // report
123  std::cout << "################################\n";
124  std::cout << "# tutorial, sys1 error states\n";
125  sys1.WriteStateSet(qerr);
126  std::cout << "################################\n";
127 
128  // Record testcase
129  FAUDES_TEST_DUMP("sys1", sys1);
130  FAUDES_TEST_DUMP("isio", isio);
131  FAUDES_TEST_DUMP("isfree", isfree);
132  FAUDES_TEST_DUMP("iswfree", iswfree);
133  FAUDES_TEST_DUMP("qerr", qerr);
134 
135  return 0 ;
136 
137 }
138 
139 
140 
141 
#define FAUDES_TEST_DUMP(mes, dat)
Test protocol record macro ("mangle" filename for platform independance)
Definition: cfl_helper.h:483
Faudes exception class.
Set of indices.
Definition: cfl_indexset.h:78
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
Generator with I/O-system attributes.
Definition: ios_system.h:34
StateSet InputStates(void) const
Retrieve all input states.
Definition: ios_system.h:1100
void ClrInputEvent(Idx index)
Unmark event as input event.
Definition: ios_system.h:1000
StateSet OutputStates(void) const
Retrieve all output states.
Definition: ios_system.h:1023
void SetInputState(Idx index)
Mark state as input state.
Definition: ios_system.h:1131
void ClrOutputEvent(Idx index)
Unmark event as output event.
Definition: ios_system.h:923
void ClrOutputState(Idx index)
Unmark state as output state.
Definition: ios_system.h:1077
void SetOutputEvent(Idx index)
Mark event as output event.
Definition: ios_system.h:900
EventSet OutputEvents(void) const
Retrieve all output events.
Definition: ios_system.h:870
EventSet InputEvents(void) const
Retrieve all input events.
Definition: ios_system.h:946
void SetOutputState(Idx index)
Mark state as output state.
Definition: ios_system.h:1054
void SetInputEvent(Idx index)
Mark event as input event.
Definition: ios_system.h:977
void Write(const Type *pContext=0) const
Write configuration data to console.
Definition: cfl_types.cpp:139
void WriteStateSet(const StateSet &rStateSet) const
Write a stateset to console (no re-indexing).
void GraphWrite(const std::string &rFileName, const std::string &rOutFormat="", const std::string &rDotExec="dot") const
Produce graphical representation of this generator.
bool IsInputOmegaFree(IoSystem &rIoSystem)
Test whether the system behaviour has exhibits a free input.
bool IsInputLocallyFree(IoSystem &rIoSystem)
Test whether the system has a locally free input.
bool IsIoSystem(const IoSystem &rIoSystem, StateSet &rQU, StateSet &rQY, StateSet &rQErr)
Test whether the system satisfies basic I/O conditions.
void IoFreeInput(IoSystem &rIoSystem)
Enable all input events for each input state.
int main()
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen