5_attributes.cpp
Go to the documentation of this file.
1 /** @file 5_attributes.cpp
2 
3 Tutorial, attributes.
4 
5 The StateSet, the EventSet and the TransitionSet of the Generator
6 accept a template parameter to specify attributes for the respective entity.
7 There is also a parameter to specify attributes of the generator itself. This tutorial
8 illustrates how to use the attribute parameter to distinguish controllabel events.
9 Note that there is a more convenient class System for this particular
10 purpose (see 4_cgenerator.cpp)
11 
12 @ingroup Tutorials
13 
14 @include 5_attributes.cpp
15 
16 */
17 
18 
19 
20 #include "libfaudes.h"
21 
22 
23 // we make the faudes namespace available to our program
24 
25 using namespace faudes;
26 
27 
28 /////////////////
29 // main program
30 /////////////////
31 
32 int main() {
33 
34  // convenience typedef for a generator with event flags
36  typedef TaEventSet<AttributeFlags> fEventSet;
37 
38  // instantiate generator object
39  fGenerator fg1;
40 
41  // read from std generator file, all attributes take the default value
42  fg1.Read("data/simplemachine.gen");
43 
44  // set a flag: 1. read the attribute (e.g. by event index)
45  AttributeFlags aflag = fg1.EventAttribute(1);
46 
47  // set a flag: 2. use attribute methods to manipulate
48  aflag.Set(0x0000000f);
49 
50  // set a flag: 3. copy the new attribute to the generators alphabet
51  // note: if the attribute turns out to be the default attribute, no
52  // memory will be allocated
53  fg1.EventAttribute(1,aflag);
54 
55  // set a flag: alternatively, use generator method
56  // note that even if the attrute became the default attribute, memory is allocated
57  fg1.EventAttributep(1)->Set(0x00000f000);
58 
59  // get a flag: use generator method
60  AttributeFlags bflag= fg1.EventAttribute(1);
61 
62  // Retrieve a const reference to the Generator's alphabet, includes attributes
63  const fEventSet& eset_ref_alph = fg1.Alphabet();
64 
65  // Retrieve a const reference of the Generator's alphabet without attributes
66  const EventSet& set_ref_alph = fg1.Alphabet();
67 
68  // Retrieve a copy of the Generator's alphabet without attributes
69  EventSet eset_copy_alph = fg1.Alphabet();
70 
71  // report flag to console
72  std::cout << "################################\n";
73  std::cout << "# tutorial, show flags \n";
74  std::cout << bflag.ToString() << "\n";
75  std::cout << "################################\n";
76 
77 
78  // write to generator file, incl attributes
79  fg1.Write("tmp_fsimplemachine.gen");
80 
81  // read back
82  fg1.Read("tmp_fsimplemachine.gen");
83 
84  // report to console
85  std::cout << "################################\n";
86  std::cout << "# tutorial, show generator with flags \n";
87  fg1.DWrite();
88  std::cout << "################################\n";
89 
90 
91  // when reading attributed files to std generator, attributes are ignored
92  Generator g1;
93  g1.Read("tmp_fsimplemachine.gen");
94 
95  // report to console
96  std::cout << "################################\n";
97  std::cout << "# tutorial, show generator without flags \n";
98  g1.DWrite();
99  std::cout << "################################\n";
100 
101 }
102 
int main()
Boolean flags Attribute.
void Set(fType mask)
Set multiple flags.
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
Generator with specified attribute types.
void DWrite(const Type *pContext=0) const
Write configuration data to console, debugging format.
Definition: cfl_types.cpp:225
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
Definition: cfl_types.cpp:169
Base class of all FAUDES generators.
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.

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