Base class for console applications. More...
Public Types | |
typedef int(*) | CallbackProc(ConsoleApp *pThis, const char *pInputFilename, const char *pOutputFilename) |
Callback for doing the application's work. | |
typedef void(*) | UsageProc(ConsoleApp *pThis) |
Callback for printing instructions. | |
Public Member Functions | |
const Burger::StaticRTTI * | get_StaticRTTI (void) const noexcept override |
Get the description to the class. | |
ConsoleApp (int iArgc, const char **ppArgv, uint_t uFlags=0) noexcept | |
Base constructor. | |
virtual | ~ConsoleApp () |
Dispose of any allocated resources. | |
void | SetArgv (const char **ppArgv) noexcept |
Set the current argv parameter. | |
const char ** | GetArgv (void) const noexcept |
Get the current argv parameter. | |
void | SetArgc (int iArgc) noexcept |
Set the current argc parameter. | |
int | GetArgc (void) const noexcept |
Get the current argc parameter. | |
uint_t | WasDesktopLaunched (void) noexcept |
Was the application launched from the desktop. | |
void | PauseOnError (eError uError=kErrorGeneric) |
Pause console output if the return code is not zero. | |
uint_t | ProcessFilenames (CallbackProc pCallback) |
Handle drag and drop for console apps. | |
int | InputAndOutput (CallbackProc pCallback, UsageProc pUsage) |
Function for 2 or 3 argument tools. | |
int | SimpleTool (CallbackProc pCallback, UsageProc pUsage) |
Handle simple console applications. | |
eError | SetWindowTitle (const char *pTitle) |
Set the title of the console window. | |
eError | SetWindowSize (uint_t uWidth, uint_t uHeight) |
Set the size of the console window. | |
Public Member Functions inherited from Burger::Base | |
const char * | get_class_name (void) const noexcept |
Get the name of the class. | |
virtual | ~Base () noexcept=default |
Destructor. | |
Static Public Attributes | |
static const Burger::StaticRTTI | g_StaticRTTI |
Static Public Attributes inherited from Burger::Base | |
static const Burger::StaticRTTI | g_StaticRTTI |
The global description of the class. | |
Protected Attributes | |
MemoryManagerGlobalANSI | m_ANSIMemoryManager |
Use ANSI memory manager for tools. | |
const char ** | m_ppArgv |
Arguments passed to the console. | |
int | m_iArgc |
Number of valid arguments. | |
uint_t | m_bLaunchedFromDesktop |
TRUE if the application was launched by double clicking from a desktop | |
const char ** | m_ppOldArgv |
Saved pointer to the global __argv for restoring on exit. | |
Private Member Functions | |
ConsoleApp (const ConsoleApp &)=delete | |
ConsoleApp & | operator= (const ConsoleApp &)=delete |
ConsoleApp (ConsoleApp &&)=delete | |
ConsoleApp & | operator= (ConsoleApp &&)=delete |
Base class for console applications.
This class contains everything needed to create a cross-platform environment for writing console based applications. Functions are included to allow for the application to gain drag and drop functionality on platforms that support it.
int( *) Burger::ConsoleApp::CallbackProc(ConsoleApp *pThis, const char *pInputFilename, const char *pOutputFilename) |
Callback for doing the application's work.
void( *) Burger::ConsoleApp::UsageProc(ConsoleApp *pThis) |
Callback for printing instructions.
|
privatedelete |
|
privatedelete |
|
noexcept |
Base constructor.
When a console app is spawned using ANSI C++ main(), it is given two parameters argc and argv. These parameters are cached inside of this base class so the member functions can handle automatic parameter passing and decoding. The return code is initialized to zero.
|
virtual |
Dispose of any allocated resources.
When a console app is shut down, dispose of everything here.
|
overridevirtualnoexcept |
Get the description to the class.
This virtual function will pull the pointer to the StaticRTTI instance that has the name of the class. Due to it being virtual, it will be the name of the most derived class.
Reimplemented from Burger::Base.
|
inlinenoexcept |
Get the current argc parameter.
Accessor to get the current argc input value passed to main().
|
inlinenoexcept |
Get the current argv parameter.
Accessor to get the current argv input value passed to main().
int BURGER_API Burger::ConsoleApp::InputAndOutput | ( | CallbackProc | pCallback, |
UsageProc | pUsage ) |
Function for 2 or 3 argument tools.
If the console application was invoked with argc == 2 or argc == 3, then execute the callback with a Burgerlib input filename and a NULL for the output filename (argc==2) or a burgerlib input filename and a burgerlib output filename (argc==3). There is no checking performed on the filenames to see if they are actually pointing to valid files.
If argc!=2 and argc!=3 then set the error code to 10 and then the pUsage function is called so that instructions can be displayed. If pUsage is nullptr, no instructions will be printed.
pCallback | Pointer to a function to perform the actual work. |
pUsage | Pointer to a function to print the instructions. |
|
privatedelete |
|
privatedelete |
void Burger::ConsoleApp::PauseOnError | ( | Burger::eError | uError = kErrorGeneric | ) |
Pause console output if the return code is not zero.
If the error code is not set to zero, force the text output to remain on the screen if the application was launched from double clicking. If the application was launched from a console, this function does nothing.
uError | Error code to test. |
uint_t BURGER_API Burger::ConsoleApp::ProcessFilenames | ( | CallbackProc | pCallback | ) |
Handle drag and drop for console apps.
Detect if the application was launched from the Finder or from Explorer. If so, detect if it was because data files were "dropped" on the application for processing. If both cases are true, then call the user supplied function pointer for each file to be processed. The filenames are in Burgerlib format.
pCallback | Function pointer to a call that accepts a Burgerlib filename. |
|
inlinenoexcept |
Set the current argc parameter.
Override the argc input value passed to main().
iArgc | New number of parameters present (Can be zero) |
|
inlinenoexcept |
Set the current argv parameter.
Override the argv input value passed to main().
ppArgv | nullptr or pointer to an array of char pointers of command line parameters. |
Burger::eError BURGER_API Burger::ConsoleApp::SetWindowSize | ( | uint_t | uWidth, |
uint_t | uHeight ) |
Set the size of the console window.
On platforms that present console text output in a desktop window, this function will resize the window to the specified width and height in text cells. On platforms that don't text window resizing, this function does nothing and returns no error.
uWidth | Number of text cells wide of the new window |
uHeight | Number of text cells high of the new window |
Burger::eError BURGER_API Burger::ConsoleApp::SetWindowTitle | ( | const char * | pTitle | ) |
Set the title of the console window.
On platforms that present console text output in a desktop window, this function will set the title of that window to the specified UTF-8 string. On platforms that don't support such a string, this function does nothing and returns no error.
pTitle | UTF-8 "C" string for new terminal title string. |
int BURGER_API Burger::ConsoleApp::SimpleTool | ( | CallbackProc | pCallback, |
UsageProc | pUsage ) |
Handle simple console applications.
For console applications that only accept 2 or 3 parameters, namely a file to input data and a file to output data, this helper function performs the drag and drop and mundane operations for setup and tear down of the command line.
All is needed are two callbacks, one for the actual console application's conversion function and the other for printing the instructions to the console.
pCallback | Pointer to a function to perform the actual work. |
pUsage | Pointer to a function to print the instructions. |
|
noexcept |
|
static |
|
protected |
Use ANSI memory manager for tools.
|
protected |
TRUE if the application was launched by double clicking from a desktop
|
protected |
Number of valid arguments.
|
protected |
Arguments passed to the console.
|
protected |
Saved pointer to the global __argv for restoring on exit.