Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | List of all members
Burger::ConsoleApp Class Reference

Base class for console applications. More...

Inheritance diagram for Burger::ConsoleApp:
Inheritance graph
[legend]
Collaboration diagram for Burger::ConsoleApp:
Collaboration graph
[legend]

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::StaticRTTIget_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
 
ConsoleAppoperator= (const ConsoleApp &)=delete
 
 ConsoleApp (ConsoleApp &&)=delete
 
ConsoleAppoperator= (ConsoleApp &&)=delete
 

Detailed Description

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.

Member Typedef Documentation

◆ CallbackProc

typedef int( * Burger::ConsoleApp::CallbackProc) (ConsoleApp *pThis, const char *pInputFilename, const char *pOutputFilename)

Callback for doing the application's work.

◆ UsageProc

typedef void( * Burger::ConsoleApp::UsageProc) (ConsoleApp *pThis)

Callback for printing instructions.

Constructor & Destructor Documentation

◆ ConsoleApp() [1/3]

Burger::ConsoleApp::ConsoleApp ( const ConsoleApp & )
privatedelete

◆ ConsoleApp() [2/3]

Burger::ConsoleApp::ConsoleApp ( ConsoleApp && )
privatedelete

◆ ConsoleApp() [3/3]

Burger::ConsoleApp::ConsoleApp ( int iArgc,
const char ** ppArgv,
uint_t uFlags = 0 )
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.

◆ ~ConsoleApp()

Burger::ConsoleApp::~ConsoleApp ( )
virtual

Dispose of any allocated resources.


When a console app is shut down, dispose of everything here.

Member Function Documentation

◆ get_StaticRTTI()

const Burger::StaticRTTI * Burger::ConsoleApp::get_StaticRTTI ( void ) const
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.

Returns
Pointer to a global, read only instance of StaticRTTI for the true class

Reimplemented from Burger::Base.

◆ GetArgc()

Burger::ConsoleApp::GetArgc ( void ) const
inlinenoexcept

Get the current argc parameter.


Accessor to get the current argc input value passed to main().

Returns
Integer with the number of valid argv commands. Can be zero.
See also
Burger::ConsoleApp::GetArgv() const

◆ GetArgv()

Burger::ConsoleApp::GetArgv ( void ) const
inlinenoexcept

Get the current argv parameter.


Accessor to get the current argv input value passed to main().

Returns
nullptr or pointer to an array of char pointers of command line parameters.
See also
Burger::ConsoleApp::GetArgc() const

◆ InputAndOutput()

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.

Parameters
pCallbackPointer to a function to perform the actual work.
pUsagePointer to a function to print the instructions.
Returns
The current error code. Can be returned to the operating system.
See also
int Burger::ConsoleApp::SimpleTool( Burger::ConsoleApp::CallbackProc,Burger::ConsoleApp::UsageProc)

◆ operator=() [1/2]

ConsoleApp & Burger::ConsoleApp::operator= ( ConsoleApp && )
privatedelete

◆ operator=() [2/2]

ConsoleApp & Burger::ConsoleApp::operator= ( const ConsoleApp & )
privatedelete

◆ PauseOnError()

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.

Parameters
uErrorError code to test.

◆ ProcessFilenames()

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.

Note
This function will set the console return code to 1 on entry, so if the processing doesn't take place, it will assume an error has occurred. The processing procedure can set the return code to zero or any other value at will and that's the return code that will be retained.
Parameters
pCallbackFunction pointer to a call that accepts a Burgerlib filename.
Returns
TRUE if the function pointer was called. FALSE if normal processing should occur.

◆ SetArgc()

Burger::ConsoleApp::SetArgc ( int iArgc)
inlinenoexcept

Set the current argc parameter.


Override the argc input value passed to main().

Parameters
iArgcNew number of parameters present (Can be zero)
See also
Burger::ConsoleApp::SetArgv(const char **)

◆ SetArgv()

Burger::ConsoleApp::SetArgv ( const char ** ppArgv)
inlinenoexcept

Set the current argv parameter.


Override the argv input value passed to main().

Parameters
ppArgvnullptr or pointer to an array of char pointers of command line parameters.
See also
Burger::ConsoleApp::SetArgc(int)

◆ SetWindowSize()

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.

Note
The maximum supported width and height is 32767 due to limits of the Windows API.
Parameters
uWidthNumber of text cells wide of the new window
uHeightNumber of text cells high of the new window
Returns
The current error code. Can be returned to the operating system.
See also
WasDesktopLaunched()

◆ SetWindowTitle()

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.

Parameters
pTitleUTF-8 "C" string for new terminal title string.
Returns
The current error code. Can be returned to the operating system.
See also
WasDesktopLaunched()

◆ SimpleTool()

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.

Parameters
pCallbackPointer to a function to perform the actual work.
pUsagePointer to a function to print the instructions.
Returns
The current error code. Can be returned to the operating system.
See also
int Burger::ConsoleApp::InputAndOutput( Burger::ConsoleApp::CallbackProc pCallback, Burger::ConsoleApp::UsageProc pUsage)

◆ WasDesktopLaunched()

uint_t BURGER_API Burger::ConsoleApp::WasDesktopLaunched ( void )
noexcept

Was the application launched from the desktop.


Returns TRUE if the console application was launched by double clicking on the icon or FALSE if the application was launched from a command line shell.

Returns
TRUE if desktop launched, FALSE if from a shell.
See also
Burger::ConsoleApp::GetArgv() const or Burger::ConsoleApp::GetArgc() const

Member Data Documentation

◆ g_StaticRTTI

const Burger::StaticRTTI Burger::ConsoleApp::g_StaticRTTI
static

◆ m_ANSIMemoryManager

MemoryManagerGlobalANSI Burger::ConsoleApp::m_ANSIMemoryManager
protected

Use ANSI memory manager for tools.

◆ m_bLaunchedFromDesktop

uint_t Burger::ConsoleApp::m_bLaunchedFromDesktop
protected

TRUE if the application was launched by double clicking from a desktop

◆ m_iArgc

int Burger::ConsoleApp::m_iArgc
protected

Number of valid arguments.

◆ m_ppArgv

const char** Burger::ConsoleApp::m_ppArgv
protected

Arguments passed to the console.

◆ m_ppOldArgv

const char** Burger::ConsoleApp::m_ppOldArgv
protected

Saved pointer to the global __argv for restoring on exit.