Programmer Guide/Macro Library/CObjEx: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}__NOTOC__
{{DISPLAYTITLE:{{SUBPAGENAME}} - Base class for objects used in script applications}}
*'''File''': CLASSES.STX, linked to library STX.LIB
*'''File''': CLASSES.STX, linked to library STX.LIB
*'''Title''': Base class for objects used in script applications
*'''Parent''': [[Programmer_Guide/Macro_Library/COBJ|CObj]], '''Derived classes''': [[Programmer_Guide/Macro_Library/XPlot|XPlot]], [[Programmer_Guide/Macro_Library/XGraph|XGraph]], [[Programmer_Guide/Macro_Library/XWave|XWave]]
*'''Parent''': [[Programmer_Guide/Macro_Library/CObj|CObj]], '''Derived classes''': [[Programmer_Guide/Macro_Library/XPlot|XPlot]], [[Programmer_Guide/Macro_Library/XGraph|XGraph]], [[Programmer_Guide/Macro_Library/XWave|XWave]]


The class <code>CObjEx</code> is an enhanced base class designed for objects which are used in {{STX}} scripts. Objects based on this class are deleted automatically before the script application is finished. By convention a class based on <code>CObjEx</code> implements the following simple instantiation method:
::<code> <var>cobjexinst</var> := <var>cobjExClassName</var> <var>constructionArguments</var> </code>


The class <code>CObjEx</code> is an enhanced base class designed for objects which are used in {{STX}} scripts. Objects based on this class are deleted automatically before the script application is finished. By convention a class based on <code>CObjEx</code> implements the following simple instantiation method:
This instantation method can simply be implemented:
::<code> cobjExInstance := cobjExClassName <var>constructionArguments</var> </code>


<pre>
[class myclassex cobjex]
exit 1 set '$(cobj 'new $#mac $#argv')'


;Constructor: The default constructor calls the CObj constructor and writes a construct-message in the console window. The function takes no arguments and returns always 0 (success). It must be called by derived classes.
// start with member functions here
...
</pre>


==Rules for derived classes==
If a derived class implementa a '''construct''' or '''destruct''' member, the base class member must be called.


;Destructor: The default constructor stops and deletes the internal timer (&logTimerItem), calls the CObj constructor and writes a destruct-message in the console window. It must be called by derived classes.
'''public_construct:'''
:The default constructor calls the CObj constructor and writes a construct-message to the console window. The base class member takes no arguments and returns always 0 (success). It must be called by derived classes.


'''public_destruct:'''
:The default constructor stops and deletes the internal timer (&logTimerItem), calls the CObj destructor and writes a destruct-message to the console window. It must be called by derived classes.


;Member functions: [[#Cleanup|Cleanup (static)]], [[#Log|Log]], [[#LogExt|LogExt]], [[#LogExit|LogExit]], [[#LogTimer|LogTimer]], [[#ELog|ELog]]
==Member Functions==


===Cleanup===
===Cleanup (static)===
'''static'''


;<code>CObjEx Cleanup</code>
;<code>cobjex cleanup</code>
;Result: none:
;Result: none:
;Description:Delete all instances of classes based on <code>CObjEx</code>. This function is called automatically by the script processor (<code>BScript</code>) before the script application exits.
;Description:Delete all instances of classes derived from <code>CObjEx</code>. This function is called automatically by the script controller (<code>BScript</code>) before the script application exits.


====Log====
===Log===
'''public'''
;Usage:<code><var>cobjex_inst</var> log <var>text</var></code>:
;<code><var>cobjex</var> log <var>text</var></code>:
:;<var>text</var>: the text to write to the script console
:;<var>text</var>: The text to write to the log window.
;Result: none
;Result: none
;Description: Write the message <code>class-instance: <var>text</var></code> to the script console.
;Description: Write the message <code><var>cobjex_inst</var>: <var>text</var></code> to the script console.


====LogExit====
===ELog===
;<code><var>cobjex</var> logError <var>result</var>; <var>text</var></code>:
;Usage:<code><var>cobjex_inst</var> elog <var>lev ; res ; text</var></code>
:;<var>result</var>: The result to assign after returning.
:;<var>lev</var>: the number of macro levels to close ('''1''' = return to caller, '''2''' = exit caller, ...; default=2)
:;<var>text</var>: The text to write to the console window.
:;<var>res</var>: the result value to be returned; no default (empty)
;Result: The value of argument <var>result</var>
:;<var>text</var>: the text to write to the script console.
;Description: Writes the message <code>class-instance: <var>text</var></code> to the script console and exits from 2 macros (= return from caller) with the return value <var>result</var>.
;Result: none
;Description: Write the message <code><var>cobjex_inst</var>: Error! - <var>text</var></code> to the script console and exits the specified number of macro levels (<code>exit <var>lev</var> set '<var>res</var>'</code>).


=====Usage:=====
===LogExit===
 
;Usage: <code><var>cobjex_inst</var> logexit <var>res ; text</var></code>:
 
:;<var>res</var>: the result to assign after returning.
===LogExt===
:;<var>text</var>: the text to write to the console window
 
;Result: The value of argument <var>res</var>
Write text to the <code>CON</code> log window with the option of overwriting the last line. This is useful for progress reports.
;Description: Writes the message <code>class-instance: <var>text</var></code> to the script console and exits from 2 macros (= return from caller) with the return value <var>res</var>.
 
Usage:
 
<code><var>inst</var> LogExt <var>mode</var> ; <var>text</var></code>
 
=====Parameters:=====
 
;<var>mode</var>
 
:If <code>0</code>, the text overwrites the last log window line. If <code>1</code>, the text is appended to the last log window line.
 
;<var>text</var>
 
:The text to write to the log window.


===LogTimer===
===LogTimer===
 
;<code><var>cobjex_inst</var> logtimer <var>cmd ; text</var></code>:
Start or stop the internal <code>BScript</code> timer. The elapsed time is written to the CON log window.
:;<var>cmd</var>: one of the following:
 
::*<code>ON</code> or <code>BEGIN</code>: start the timer and/or display the elapsed time the console window.
Usage:
::*<code>OFF</code> or <code>END</code>: stop the timer and display the elapsed time in the console window.
 
:;<var>text</var>: the text to write to the console window
<code><var>inst</var> LogTimer <var>cmd</var></code>
;Return: The elapsed time in seconds.
 
;Description: Start (continue) or stop the internal timer of the object and write the elapsed time and <var>text</var> to the console window.
=====Parameters:=====
 
;<var>cmd</var>
 
:One of the following:
 
:<code>ON</code>|<code>BEGIN</code> - Start the timer. If the timer has already been started, then the elapsed time in seconds is returned. The elapsed time is also displayed in the CON window.
 
:<code>OFF</code>|<code>END</code> - Stop the timer. The elapsed time is also displayed in the CON window.
 
 
 
====ELog====
;<code><var>cobjex</var> ELog <var>level</var> ; <var>result</var> ; <var>text</var></code>:
:;<var>level</var>: The number of macro levels to return (<code>2</code> means: return from calling-macro).
:;<var>result</var>: The result to set on returning.
:;<var>text</var>: The text to write to the console window.
;Result: The value of the argument <var>result</var>. Note: This value is returned to macro addressed by argument <var>level</var>.
;Description: Writes the message <code>class-instance: ERROR - <var>text</var></code> to the script console and exits from <var>level</var> macros with the return value <var>result</var>.

Latest revision as of 13:05, 7 March 2018

The class CObjEx is an enhanced base class designed for objects which are used in STx scripts. Objects based on this class are deleted automatically before the script application is finished. By convention a class based on CObjEx implements the following simple instantiation method:

cobjexinst := cobjExClassName constructionArguments

This instantation method can simply be implemented:

[class myclassex cobjex]
exit 1 set '$(cobj 'new $#mac $#argv')'

// start with member functions here
...

Rules for derived classes

If a derived class implementa a construct or destruct member, the base class member must be called.

public_construct:

The default constructor calls the CObj constructor and writes a construct-message to the console window. The base class member takes no arguments and returns always 0 (success). It must be called by derived classes.

public_destruct:

The default constructor stops and deletes the internal timer (&logTimerItem), calls the CObj destructor and writes a destruct-message to the console window. It must be called by derived classes.

Member Functions

Cleanup (static)

cobjex cleanup
Result
none:
Description
Delete all instances of classes derived from CObjEx. This function is called automatically by the script controller (BScript) before the script application exits.

Log

Usage
cobjex_inst log text:
text
the text to write to the script console
Result
none
Description
Write the message cobjex_inst: text to the script console.

ELog

Usage
cobjex_inst elog lev ; res ; text
lev
the number of macro levels to close (1 = return to caller, 2 = exit caller, ...; default=2)
res
the result value to be returned; no default (empty)
text
the text to write to the script console.
Result
none
Description
Write the message cobjex_inst: Error! - text to the script console and exits the specified number of macro levels (exit lev set 'res').

LogExit

Usage
cobjex_inst logexit res ; text:
res
the result to assign after returning.
text
the text to write to the console window
Result
The value of argument res
Description
Writes the message class-instance: text to the script console and exits from 2 macros (= return from caller) with the return value res.

LogTimer

cobjex_inst logtimer cmd ; text
cmd
one of the following:
  • ON or BEGIN: start the timer and/or display the elapsed time the console window.
  • OFF or END: stop the timer and display the elapsed time in the console window.
text
the text to write to the console window
Return
The elapsed time in seconds.
Description
Start (continue) or stop the internal timer of the object and write the elapsed time and text to the console window.

Navigation menu

Personal tools