Guard

Top  Previous  Next

Examples > Guard

 

You should know the most essential operation elements of TETRA.

 

This example shall demonstrate the use of sub-expression in regular expressions.

The access of sub-expressions will be possible in the future only in the standard and professional version of the TextTransformer.

 

 

Problem definition:

 

Into a c++ source file at the entering and exit positions of methods - i.e. after the opening brace of the function body and before the closing brace - additional instructions shall be inserted, which can be used for debugging or profiling purposes. The name of the class and the name of the function shall be passed to the inserted code.

For example, if there is defined a method:

 

void CClass::Name ( int xi )

{

  ...

}

 

this shall be transformed to:

 

void CClass::Name ( int xi )

{

   CGuard GUARD("CClass", "Name");

  ...

   GUARD.stop();

}

 

For example the class CGuard can block certain resources in its constructor or initiate a time measurement and leave the resources in the destructor or stop the time respectively.

Another possibility would be the insertion of a try catch block

 

void CClass::Name ( int xi )

{

   try

   {

      ...

   }

   catch(...)

   {

        throw CException("CClass::Name");

   }

}

 

 

TETRA Program:

 

The example Guard is in:

 

       \TextTransformer\Examples\Guard\guard.ttp

 

The program is for demonstration only. It is not guaranteed, that it can transform every c++ source file. But it will transform the source files TETRA creates. So two parsers generated by the TextTransformers are used as examples for the input.

 

       \TextTransformer\Examples\Guard\calculatorparser.cpp

       \TextTransformer\Examples\Guard\guardparser.cpp

 

 



This page belongs to the TextTransformer Documentation

Home  Content  German