ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::app::App Class Referenceabstract

Description:

This is a central class of library module ALib App.

For information about general use and features of this class consult the ALib App User Manual.

Definition at line 16 of file app.inl.

Inheritance diagram for alib::app::App:
alib::app::AppCli

Inner Type Index:

struct  ConfigFileDescriptor
struct  StateMachine

Public Type Index:

enum class  BuiltInExitCodes { OK = 0 , ErrConfigFileNotFound = 10 , ErrConfigFileNotWritable = 11 , ErrUnknown = 127 }
enum class  Exceptions { ControlledEarlyExit }

Public Method Index:

virtual void exceptionDisplay (Exception &exception, AString &target)
virtual Enum exceptionToExitCode (alib::Exception &exception)
virtual void getConfigFilePaths (StdVectorMA< ConfigFileDescriptor > &files)
virtual void getConfigFilePathsFromResources (StdVectorMA< ConfigFileDescriptor > &files)
virtual void getConfigFilePathsMakeAbsolutePaths (StdVectorMA< ConfigFileDescriptor > &files)
String GetInfo ()
String GetName ()
virtual lox::textlogger::TextLoggerGetRLogger ()
virtual lox::LoxGetRLox ()
String GetVersion ()
virtual int Main (int argc, const char **argv, const wchar_t **argvw=nullptr)
virtual void onBsFinalizeBootstrap ()
virtual void onBsImportConfig ()
virtual void onBsPreloadVariables ()
virtual void onBsPrepareConfig ()
virtual void onBsPrepareResources ()
virtual void onBsSetCamps ()
virtual void onBsSetNameVersionAndInfo ()
virtual void onBsSetupALox ()
virtual void onRun ()=0
virtual void onRunEnd ()
virtual void onRunStart ()
virtual void onSdAnnounceShutdown ()
virtual void onSdCleanALox ()
virtual void onSdExportConfig ()
virtual void onSdFinalizeShutdown ()
virtual void onSdOutput ()
virtual void printConfigFileInfo (Paragraphs &target)

Protected Type Index:

enum class  Flags {
  NONE = 0 , CreateReleaseLox =(1<<0) , UseReleaseLoggerForDebugLogging =(1<<1) , ALoxVerbosityExportAllAndWriteBackRelLogger =(1<<2) ,
  ALoxVerbosityExportAllAndWriteBackDbgLogger =(1<<3)
}
 Configuration flags used with class App. More...
enum class  States {
  NOT_STARTED = 0 , SetCamps = 11 , PrepareResources = 12 , SetNameVersionAndInfo = 13 ,
  PrepareConfig = 21 , PreloadVariables = 22 , ImportConfig = 23 , FinalizeBootstrap = 31 ,
  SetupALox = 33 , RunStart =100 , Run =111 , RunEnd =120 ,
  AnnounceShutdown =910 , CleanALox =920 , ExportConfig =930 , Output =940 ,
  FinalizeShutdown =950 , CNTD_BUILTIN_STATES = 16
}

Protected Field Index:

camp::CampappCamp =nullptr
String appInfo =nullptr
String appName =nullptr
String appVersion =nullptr
ParagraphscErr =nullptr
 Same as cOut, but used for stream std::err.
ParagraphscOut =nullptr
Flags flags =Flags::NONE
 Various boolean flags used to configure the application.
StateMachine machine
 The state-machine singleton.
lox::textlogger::TextLoggerreleaseLogger =nullptr
String releaseLoggerName =A_CHAR("RLOGGER")
lox::LoxreleaseLox =nullptr
String releaseLoxName =A_CHAR("RLOX")
StopWatch stopWatch

Protected Method Index:

 App (camp::Camp *appCamp)
virtual ~App ()
 Virtual destructor.

Enumeration Details:

◆ BuiltInExitCodes

Built-in exit-codes of the ALib application. The underlying integer values may be used by a descendant application as the result of C/C++ method main().
They are provided here rather as a sample and to be able to provide a default implementation of the method exceptionToExitCode. In the case that an application desires to use different exit codes, the latter method has to be overridden.

When using the derived class AppCli, this enumeration gets the according ALib Enum Records assigned and default resources are defined.

Enumerator
OK 

Success.

ErrConfigFileNotFound 

The default configuration file(s), or that (those) specified by option '–config', could not be found or read.

ErrConfigFileNotWritable 

The configuration file(s) could not be written.

ErrUnknown 

An unknown exception occurred.

Definition at line 45 of file app.inl.

◆ Exceptions

enum class alib::app::App::Exceptions
strong

Generic Exceptions handled by class App. This enumeration contains only one single entry.

Enumerator
ControlledEarlyExit 

This exception is used to support the exception/error/exit code paradigm introduced by class App.

See also
A detailed description on the usage of this exception is given in chapter 3.6 Controlled Early Exit (Exceptions::ControlledEarlyExit) of the Programmer's Manual of the module ALib App.

Definition at line 25 of file app.inl.

◆ Flags

enum class alib::app::App::Flags
strongprotected

Configuration flags used with class App.

Enumerator
NONE 

No flags set.

CreateReleaseLox 

If set, method virtual void onBsSetupALox()  will create a release Lox instance available via field virtual lox::Lox * GetRLox() , as well as an attached logger available via field virtual lox::textlogger::TextLogger * GetRLogger() .

UseReleaseLoggerForDebugLogging 

If set, method virtual void onBsSetupALox()  will create and attach the release logger to the debug Lox Lox.

ALoxVerbosityExportAllAndWriteBackRelLogger 

If set, method virtual void onSdExportConfig()  adds 'ExportAll' and 'writeback' to the verbosity variable of the lox::textlogger::TextLogger * releaseLogger in the case that this variable had not been read from the INI file with virtual void onBsImportConfig() .

ALoxVerbosityExportAllAndWriteBackDbgLogger 

If set, method virtual void onSdExportConfig()  adds 'ExportAll' and 'writeback' to the verbosity variable of the debug-logger in the case that this variable had not been read from the INI file with virtual void onBsImportConfig() .

Definition at line 59 of file app.inl.

◆ States

enum class alib::app::App::States
strongprotected

The predefined states of the simple linear state-machine implemented by outer class App. For each state, a corresponding virtual function exists. The pairs of states and the corresponding virtual functions are collected in the field StateMachine::Program.
Custom applications (derived from class App) define their own enum type in case they want to insert additional pairs of state/methods into the program. This is possible because the collection of states in the field StateMachine::Program is implemented as type Enum, which may hold enumeration elements of an arbitrary type.

Note that the numbering of the enum elements is not of importance. The numbers found here were chosen to be quickly identifiable while debugging. The simple scheme is:

  • 1x: Bootstrap phase resources. (See also BootstrapPhases).
  • 2x: Bootstrap phase configuration/variables.
  • 3x: Bootstrap phase finalization.
  • 1xx: running phase.
  • 9xx: shutdown phase. (See also ShutdownPhases).

Also, the numbers are not defining the order of execution, which is solely defined by the order in the vector StateMachine::Program.

The custom enumeration type used for potential custom states may but does not need to align. It even may have the same integral values as given here. This flexibility is gained by the little magic of class Enum introduced by module ALib Boxing.

Enumerator
NOT_STARTED 

Initial state before starting the App.

The starting state not associated with a method.

SetCamps 

Invokes the virtual method onBsSetCamps.

PrepareResources 

Invokes the virtual method onBsPrepareResources.

SetNameVersionAndInfo 

Invokes the virtual method onBsSetNameVersionAndInfo.

PrepareConfig 

Invokes the virtual method onBsPrepareConfig.

PreloadVariables 

Invokes the virtual method onBsPreloadVariables.

ImportConfig 

Invokes the virtual method onBsImportConfig.

FinalizeBootstrap 

Invokes the virtual method onBsFinalizeBootstrap.

SetupALox 

Invokes the virtual method onBsSetupALox.

RunStart 

Invokes the virtual method onRunStart.

Run 

Invokes the virtual method onRun.

RunEnd 

Invokes the virtual method onRunEnd.

AnnounceShutdown 

Invokes the virtual method onSdAnnounceShutdown.

CleanALox 

Invokes the virtual method onSdCleanALox.

ExportConfig 

Invokes the virtual method onSdExportConfig.

Output 

Invokes the virtual method onSdOutput.

FinalizeShutdown 

Invokes the virtual method onSdFinalizeShutdown.

CNTD_BUILTIN_STATES 

The number of built-in states. Only used for reserving the 'program's' capacity.

Definition at line 110 of file app.inl.

Field Details:

◆ appCamp

camp::Camp* alib::app::App::appCamp =nullptr
protected

The main camp of the application. This is where resources are loaded from.

See also
Notes are given in the constructor.

Definition at line 379 of file app.inl.

◆ appInfo

String alib::app::App::appInfo =nullptr
protected

Some short information and probably copyright message of the application. If not set from the descendant, it is tried to be loaded from resource "AppInfo" by the default implementation of onBsSetNameVersionAndInfo.

Definition at line 394 of file app.inl.

◆ appName

String alib::app::App::appName =nullptr
protected

The name of the application. If not set from the descendant, it is tried to be loaded from resource "AppName" by the default implementation of onBsSetNameVersionAndInfo.

Definition at line 384 of file app.inl.

◆ appVersion

String alib::app::App::appVersion =nullptr
protected

A version string of the application. If not set from the descendant, it is tried to be loaded from resource "AppVersion" by the default implementation of onBsSetNameVersionAndInfo.

Definition at line 389 of file app.inl.

◆ cErr

Paragraphs* alib::app::App::cErr =nullptr
protected

Same as cOut, but used for stream std::err.

Definition at line 404 of file app.inl.

◆ cOut

Paragraphs* alib::app::App::cOut =nullptr
protected

Used to assemble and collect the output for standard output character stream std::cout during the run of this application.
The collected output is scheduled to be written by the method onSdOutput. This method, may also be "manually" invoked at any time to flush the current buffers to the output streams.

Definition at line 401 of file app.inl.

◆ flags

Flags alib::app::App::flags =Flags::NONE
protected

Various boolean flags used to configure the application.

Definition at line 427 of file app.inl.

◆ machine

StateMachine alib::app::App::machine
protected

The state-machine singleton.

Definition at line 371 of file app.inl.

◆ releaseLogger

lox::textlogger::TextLogger* alib::app::App::releaseLogger =nullptr
protected

The release logger used by the application.

See also
Method onBsSetupALox.

Definition at line 424 of file app.inl.

◆ releaseLoggerName

String alib::app::App::releaseLoggerName =A_CHAR("RLOGGER")
protected

This will be the name of the release logger attached to the release Lox. The name defaults to "RLOGGER" and may be changed prior to the call to the method onBsSetupALox.

Definition at line 416 of file app.inl.

◆ releaseLox

lox::Lox* alib::app::App::releaseLox =nullptr
protected

The release Lox used by the application.

See also
Method onBsSetupALox.

Definition at line 420 of file app.inl.

◆ releaseLoxName

String alib::app::App::releaseLoxName =A_CHAR("RLOX")
protected

This will be the name of the release Lox. The name defaults to "RLOX" and may be changed prior to the call to the method onBsSetupALox.

Definition at line 411 of file app.inl.

◆ stopWatch

StopWatch alib::app::App::stopWatch
protected

A stop-watch usable for measuring performance of different steps of an application. Time is taken in the constructor.

Definition at line 375 of file app.inl.

Constructor(s) / Destructor Details:

◆ App()

alib::app::App::App ( camp::Camp * appCamp)
protected

Constructor. Initializes this app. Mainly by filling the vector StateMachine::Program with all states found in the enumeration States along with the corresponding virtual methods.

While the parameter appCamp is optional, it is intentionally not provided with a default value of nullptr. Derived types should create and provide a custom camp here (See the Programmer's Manual of the module ALib Camp). If it is missing, many default implementations of the virtual methods render useless, and return instantly.
If not given, it will be set in the default implementation of the method onBsSetCamps to the last camp in the list CAMPS. If given that default implementation will add it to the end of this list.

Parameters
appCampAn optional camp instance to search resources in.

Definition at line 43 of file app.cpp.

◆ ~App()

alib::app::App::~App ( )
protectedvirtual

Virtual destructor.

Definition at line 73 of file app.cpp.

Method Details:

◆ exceptionDisplay()

void alib::app::App::exceptionDisplay ( alib::Exception & exception,
AString & target )
virtual

Writes exception information to std::cerr
.

Parameters
exceptionThe exception that was thrown.
targetThe target string to write into. An option is to pass cErr->Buffer here. Of course a custom buffer might be passed, i.e. if the text is to be logged with ALox.

Definition at line 159 of file app.cpp.

◆ exceptionToExitCode()

Enum alib::app::App::exceptionToExitCode ( alib::Exception & exception)
virtual

Todo: This implementation does not do the same as CLIUtil::GetExitCode. Das muss noch eingebaut werden, oder? Oder wir bauen es lieber nicht ein und ändern den Text hier. Schließlich kann das die AppCLi machen. TODO(251208 17:30): Also insgesamt ist das noch ne größere Baustelle/Design Problem!!! Zusammen mit der nächsten method exceptionDisplay Es ist wirklich schwierig. Wo ist es am besten Exit codes zu erzeugen und den cErr Text dazu? Exceptions zu werfen ist schon blöd. Dann muss man sich die ganzen Infos wieder rausziehen. Andererseits hat man es dann wirklich an einer stelle. Aber an dieser Stelle fehlen dann manche dinge. Zb. File not open. Tja, ok nicht nur welches file? Manchmal gibt es auch von file-typen mehrere. Zb. beim DoxygenXLinks mehrere tag-files. Es wäre dann schon schön zu wissen woher die Info über das Tag-file käme. Also bewegt man sich na oben im callstack zur stelle wo es auftritt, und wirft erst gar keine Exception. Tja, dann muss man den ganzen Stack alleine abbauen (also überall den exit code durchreichen und ihn abfragen. Das geht nicht. Dazhu sind ja exceptions da. Vielleicht sollte man eine einzige Exception zulassen, nämlich eine built-in "Handled Exception" Bevor die geworfen wird, wird eine ordentlich Ausgabe ins CErr geworfen und der ExitCode wird als parameter in die exception mit reingegeben. Ja, das ist ein guter Ansatz. Die App muss dann cOut und cErr public freigeben. Dass kann aber auch die abgeleitete MyApp machen. Aber so ginge es: überall wo ein ExitCode auftritt wird dieser in einer Exception gekapselt und diese exception wird geworfen. Und diese zwei Funktionen hier können ja dennoch da bleiben. Vielleicht etwas hübscher ...hab schon mal angefangen damit und die exception eingebaut.

Translates exceptions to exit-codes of the application. This default implementation performs similarly to static integer GetExitCode(CommandLine&, Exception&)  to convert command-line exceptions to exit-codes. Thus, if all exceptions have an exit-code conversion defined, there is no need to override this method.
Implementations should call this method first and, if necessary, perform their own conversions then. If they do so, they should check whether this default version returned BuiltInExitCodes::ErrUnknown, perform their own translation in that case and probably debug-assert on failure.

Parameters
exceptionThe exception that was thrown.
Returns
On success, the exit-code resulting from the given exception. Otherwise a nulled Enum.

Reimplemented in alib::app::AppCli.

Definition at line 141 of file app.cpp.

◆ getConfigFilePaths()

void alib::app::App::getConfigFilePaths ( StdVectorMA< ConfigFileDescriptor > & files)
virtual

This default implementation in turn calls the virtual helper methods getConfigFilePathsFromResources and getConfigFilePathsMakeAbsolutePaths.

Parameters
filesA pointer to an object of type StdVectorMA<ConfigFileDescriptor> that is to be filled by this method.

Reimplemented in alib::app::AppCli.

Definition at line 282 of file app.cpp.

◆ getConfigFilePathsFromResources()

void alib::app::App::getConfigFilePathsFromResources ( StdVectorMA< ConfigFileDescriptor > & files)
virtual

If the given vector files is empty, this method tries resources named "CFGF_NAME_1", "CFGF_NAME_2", "CFGF_NAME_3" and so forth until a first name is not found. For all names found, an entry in vector files is created.

Then, for each entry in the vector (regardless if they were preexisting or created with this method), comment information is loaded from resources. The resource name is composed from "CFGF_CMT_" and the number of the entry. If found, the resource is assigned to the field String Comment.

Then for each entry resources named "CFGF_EXP_" and the number of the entry are searched. If found, the field String Exports is set. If more resources (with higher numbers) are existing, such additional exports are appended to the list of the last config file entry.

Parameters
filesThe vector of file paths that is to be filled or modified by this method.

Definition at line 210 of file app.cpp.

◆ getConfigFilePathsMakeAbsolutePaths()

void alib::app::App::getConfigFilePathsMakeAbsolutePaths ( StdVectorMA< ConfigFileDescriptor > & files)
virtual

Checks all filenames in the given vector and converts them to an absolute path.

Parameters
filesThe vector of file paths that is to be modified by this method.

Definition at line 270 of file app.cpp.

◆ GetInfo()

String alib::app::App::GetInfo ( )
inline

Returns the version of this application. This default implementation returns the field appVersion.

Returns
A usually multi-line string containing information about this application.

Definition at line 490 of file app.inl.

◆ GetName()

String alib::app::App::GetName ( )
inline

Returns the name of this application. This default implementation returns the field appName. This is not necessarily equal to the process module name which can be received with ProcessInfo::Current().ExecFileName.

Returns
This application's name.

Definition at line 480 of file app.inl.

◆ GetRLogger()

virtual lox::textlogger::TextLogger * alib::app::App::GetRLogger ( )
inlinevirtual

Has to return the Logger instance used with release-logging.

Returns
This implementation returns field releaseLogger.

Definition at line 473 of file app.inl.

◆ GetRLox()

virtual lox::Lox * alib::app::App::GetRLox ( )
inlinevirtual

Has to return the Lox instance used with release-logging.

Returns
This implementation returns field releaseLox.

Definition at line 469 of file app.inl.

◆ GetVersion()

String alib::app::App::GetVersion ( )
inline

Returns the version of this application. This default implementation returns the field appVersion.

Returns
A string containing version information of this application.

Definition at line 485 of file app.inl.

◆ Main()

int alib::app::App::Main ( int argc,
const char ** argv,
const wchar_t ** argvw = nullptr )
virtual

Stores cli-parameters and executes this app.

Parameters
argcThe number of command-line arguments.
argvList of command-line arguments, given as single byte character strings.
argvwThe CLI arguments on platforms that use wide command-line strings. Defaults to nullptr. If given, parameter argv has to be nulled.
Returns
The exit code to be returned by C/C++ main().

Definition at line 75 of file app.cpp.

◆ onBsFinalizeBootstrap()

void alib::app::App::onBsFinalizeBootstrap ( )
virtual

Called on transition to state FinalizeBootstrap.
This default implementation just calls the function Bootstrap passing BootstrapPhases::Final as the parameter.

Definition at line 361 of file app.cpp.

◆ onBsImportConfig()

void alib::app::App::onBsImportConfig ( )
virtual

Called on transition to state ImportConfig.
This default implementation creates the vector of file descriptors using getConfigFilePaths and then uses type IniFileFeeder to import the variables from the INI-files.

Definition at line 337 of file app.cpp.

◆ onBsPreloadVariables()

void alib::app::App::onBsPreloadVariables ( )
virtual

Called on transition to state PreloadVariables.
Preloading variables allows later fetching and exporting those variables into a configuration file (if freshly created), even if they have not been read/used in the first run of an application.
This default implementation calls void PreloadVariables()  on the variables found with the enumeration Variables.

Reimplemented in alib::app::AppCli.

Definition at line 335 of file app.cpp.

◆ onBsPrepareConfig()

void alib::app::App::onBsPrepareConfig ( )
virtual

Called on transition to state PrepareConfig.
This default implementation just calls the function Bootstrap passing BootstrapPhases::PrepareConfig as the parameter.

Definition at line 333 of file app.cpp.

◆ onBsPrepareResources()

void alib::app::App::onBsPrepareResources ( )
virtual

Called on transition to state PrepareResources.
This default implementation

Definition at line 300 of file app.cpp.

◆ onBsSetCamps()

void alib::app::App::onBsSetCamps ( )
virtual

Called on transition to state SetCamps.
This default implementation calls the BootstrapAddDefaultCamps and then adds camp appCamp to the end of that list. In case field appCamp is nulled, rather the opposite is done: the field is set to point to the end of the list.

Definition at line 290 of file app.cpp.

◆ onBsSetNameVersionAndInfo()

void alib::app::App::onBsSetNameVersionAndInfo ( )
virtual

Called on transition to state SetNameVersionAndInfo.
This default implementation tries resources "AppName", "AppVersion", and "AppInfo" to set fields appName, appVersion, and appInfo. The latter is supported with three placeholders: the name, the version, and the current year and is created using the method Paragraphs & AddMarked(const BoxedObjects& ...) .

A string that is set before this method is called, is not replaced.

Reimplemented in alib::app::AppCli.

Definition at line 316 of file app.cpp.

◆ onBsSetupALox()

void alib::app::App::onBsSetupALox ( )
virtual

Called on transition to state SetupALox.
If this method returns an error, bootstrapping is aborted. This default implementation interprets the flags CreateReleaseLox and UseReleaseLoggerForDebugLogging, and furthermore uses the fields releaseLoxName and releaseLoggerName into account and potentially creates releaseLox and releaseLogger.

Definition at line 364 of file app.cpp.

◆ onRun()

virtual void alib::app::App::onRun ( )
pure virtual

This is the main execution method of the application. The default-implementation is not just empty, but is (the only) abstract method of this class.

Implemented in alib::app::AppCli.

◆ onRunEnd()

virtual void alib::app::App::onRunEnd ( )
inlinevirtual

This method is following the main execution method onRun. Overwriting this method is useful to collect code which has to be executed at the end of all (or most) execution paths of the custom implementation of onRun.

Reimplemented in alib::app::AppCli.

Definition at line 663 of file app.inl.

◆ onRunStart()

virtual void alib::app::App::onRunStart ( )
inlinevirtual

This method is preceding the main execution method onRun. When this is called, all bootstrapping is done. Final preparations might be performed here to unclutter onRun.

Reimplemented in alib::app::AppCli.

Definition at line 652 of file app.inl.

◆ onSdAnnounceShutdown()

void alib::app::App::onSdAnnounceShutdown ( )
virtual

Called on transition to state AnnounceShutdown.
This default implementation just calls the function Shutdown passing ShutdownPhases::Announce as the parameter.

Definition at line 390 of file app.cpp.

◆ onSdCleanALox()

void alib::app::App::onSdCleanALox ( )
virtual

Called on transition to state CleanALox.
This default implementation checks the flags ALoxVerbosityExportAllAndWriteBackRelLogger, and ALoxVerbosityExportAllAndWriteBackDbgLogger and calls bool SetVerbosityExport(Lox*, bool, Priority)  if set.
Then, if set, the release logger and Lox are deleted.

Definition at line 393 of file app.cpp.

◆ onSdExportConfig()

void alib::app::App::onSdExportConfig ( )
virtual

Called on transition to state ExportConfig.
This default implementation creates the vector of file descriptors using getConfigFilePaths and then uses type IniFileFeeder to export variables that are either not existing yet, or which have a writeback flag set, into the INI-files.
This is done for all variables (and variable trees) determined by the field String Exports.

Definition at line 416 of file app.cpp.

◆ onSdFinalizeShutdown()

void alib::app::App::onSdFinalizeShutdown ( )
virtual

Called on transition to state FinalizeShutdown.
This default implementation calls the function Shutdown passing ShutdownPhases::Destruct as the parameter.
Prior to that, some memory cleaning and debug exercises are done.

Definition at line 483 of file app.cpp.

◆ onSdOutput()

void alib::app::App::onSdOutput ( )
virtual

Flushes what is collected in the fields cOut and cErr to their respective streams and clears the buffers. With that, this method - while named with the prefix onSd and scheduled at the end of the StateMachine::Program - may be directly called by descendants whenever they wish to flush the current collected output stream, for example, after important milestones, before long-running operations, or prior to program termination when early partial output is desired.

Definition at line 465 of file app.cpp.

◆ printConfigFileInfo()

void alib::app::App::printConfigFileInfo ( Paragraphs & target)
virtual

Writes configuration file information into the given target.

Parameters
targetThe target to write into. The common option is to pass cOut here.

Definition at line 189 of file app.cpp.


The documentation for this class was generated from the following files: