5_attributes.cppGo to the documentation of this file.00001 /** @file 5_attributes.cpp 00002 00003 Tutorial, attributes. 00004 00005 The StateSet, the EventSet and the TransitionSet of the Generator 00006 accept a template parameter to specify attributes for the respective entity. 00007 There is also a parameter to specify attributes of the generator itself. This tutorial 00008 illustrates how to use the attribute parameter to distinguish controllabel events. 00009 Note that there is a more convenient class System for this particular 00010 purpose (see 4_cgenerator.cpp) 00011 00012 @ingroup Tutorials 00013 00014 @include 5_attributes.cpp 00015 00016 */ 00017 00018 00019 00020 #include "libfaudes.h" 00021 00022 00023 // we make the faudes namespace available to our program 00024 00025 using namespace faudes; 00026 00027 00028 ///////////////// 00029 // main program 00030 ///////////////// 00031 00032 int main() { 00033 00034 // convenience typedef for a generator with event flags 00035 typedef TaGenerator<AttributeVoid,AttributeVoid,AttributeFlags,AttributeVoid> fGenerator; 00036 typedef TaEventSet<AttributeFlags> fEventSet; 00037 00038 // instantiate generator object 00039 fGenerator fg1; 00040 00041 // read from std generator file, all attributes take the default value 00042 fg1.Read("data/simplemachine.gen"); 00043 00044 // set a flag: 1. read the attribute (e.g. by event index) 00045 AttributeFlags aflag = fg1.EventAttribute(1); 00046 00047 // set a flag: 2. use attribute methods to manipulate 00048 aflag.Set(0x0000000f); 00049 00050 // set a flag: 3. copy the new attribute to the generators alphabet 00051 // note: if the attribute turns out to be the default attribute, no 00052 // memory will be allocated 00053 fg1.EventAttribute(1,aflag); 00054 00055 // set a flag: alternatively, use generator method 00056 // note that even if the attrute became the default attribute, memory is allocated 00057 fg1.EventAttributep(1)->Set(0x00000f000); 00058 00059 // get a flag: use generator method 00060 AttributeFlags bflag= fg1.EventAttribute(1); 00061 00062 // Retrieve a const reference to the Generator's alphabet, includes attributes 00063 const fEventSet& eset_ref_alph = fg1.Alphabet(); 00064 00065 // Retrieve a const reference of the Generator's alphabet without attributes 00066 const EventSet& set_ref_alph = fg1.Alphabet(); 00067 00068 // Retrieve a copy of the Generator's alphabet without attributes 00069 EventSet eset_copy_alph = fg1.Alphabet(); 00070 00071 // report flag to console 00072 std::cout << "################################\n"; 00073 std::cout << "# tutorial, show flags \n"; 00074 std::cout << bflag.ToString() << "\n"; 00075 std::cout << "################################\n"; 00076 00077 00078 // write to generator file, incl attributes 00079 fg1.Write("tmp_fsimplemachine.gen"); 00080 00081 // read back 00082 fg1.Read("tmp_fsimplemachine.gen"); 00083 00084 // report to console 00085 std::cout << "################################\n"; 00086 std::cout << "# tutorial, show generator with flags \n"; 00087 fg1.DWrite(); 00088 std::cout << "################################\n"; 00089 00090 00091 // when reading attributed files to std generator, attributes are ignored 00092 Generator g1; 00093 g1.Read("tmp_fsimplemachine.gen"); 00094 00095 // report to console 00096 std::cout << "################################\n"; 00097 std::cout << "# tutorial, show generator without flags \n"; 00098 g1.DWrite(); 00099 std::cout << "################################\n"; 00100 00101 } 00102 libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |