CObjEx - Base class for objects used in script applications
From STX Wiki
Jump to navigationJump to search
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 ...
Contents
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_detsruct:
- 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
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.
- 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.