5_attributes.cpp

Go to the documentation of this file.
00001 
00019 #include "libfaudes.h"
00020 
00021 
00022 // we make the faudes namespace available to our program
00023 
00024 using namespace faudes;
00025 
00026 
00028 // main program
00030 
00031 int main() {
00032 
00033   // convenience typedef for a generator with event flags
00034   typedef TaGenerator<AttributeVoid,AttributeVoid,AttributeFlags,AttributeVoid> fGenerator; 
00035   typedef TaEventSet<AttributeFlags> fEventSet;
00036 
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 
00045   // set a flag: 1. read the attribute (e.g. by event index)
00046   AttributeFlags aflag= fg1.EventAttribute(1); 
00047 
00048   // set a flag: 2. use attribute methods to manipulate
00049   aflag.Set(0x0000000f);
00050 
00051   // set a flag: 3. copy the new attribute to the generators alphabet
00052   // note: if the attribute turns out to be the default attribute, no
00053   // memory will be allocated
00054   fg1.EventAttribute(1,aflag);
00055 
00056   // set a flag: alternatively, use generator method 
00057   // note that even if the attrute became the default attribute, memory is allocated
00058 
00059   fg1.EventAttributep(1)->Set(0x00000f000);
00060 
00061   // get a flag: use generator method
00062 
00063   AttributeFlags bflag= fg1.EventAttribute(1); 
00064 
00065   // retrieve a const reference to the Generator's alphabet, includes attributes 
00066 
00067   fEventSet  eset_ref_alph = fg1.Alphabet();
00068 
00069   // Retrieve a copy of the Generator's alphabet without attributes
00070 
00071   EventSet eset_copy_alph = fg1.Alphabet();
00072 
00073 
00074   // report flag to console
00075       
00076   std::cout << "################################\n";
00077   std::cout << "# tutorial, show flags \n";
00078   std::cout << bflag.ToString() << "\n";
00079   std::cout << "################################\n";
00080 
00081 
00082   // write to generator file, incl attributes
00083 
00084   fg1.Write("tmp_fsimplemachine.gen");
00085 
00086   // read back
00087 
00088   fg1.Read("tmp_fsimplemachine.gen");
00089 
00090   // report to console
00091 
00092   std::cout << "################################\n";
00093   std::cout << "# tutorial, show generator with  flags \n";
00094   fg1.DWrite();
00095   std::cout << "################################\n";
00096 
00097 
00098   // when reading attributed files to std generator, attributes are ignored
00099 
00100   Generator g1;
00101   g1.Read("tmp_fsimplemachine.gen");
00102 
00103   // report to console
00104 
00105   std::cout << "################################\n";
00106   std::cout << "# tutorial, show generator without flags \n";
00107   g1.DWrite();
00108   std::cout << "################################\n";
00109 
00110 }
00111 

Generated on Mon Nov 10 08:13:14 2008 for libFAUDES 2.11v by  doxygen 1.4.4