KSquare Utilities
KKB::Application Class Reference

The base class for all standalone application. More...

#include <Application.h>

Public Member Functions

 Application ()
 Constructor for Application class that will start with a default logger(RunLog),. More...
 
 Application (const Application &_application)
 Copy Constructor for Application class. More...
 
 Application (RunLog &_log)
 Constructor for Application class where we already have an existing logger '_log'. More...
 
virtual ~Application ()
 
bool Abort ()
 Returns 'true' if application has been aborted. More...
 
void Abort (bool _abort)
 Used to specify that the application is been aborted. More...
 
virtual const char * ApplicationName ()
 
void AssignLog (RunLog &_log)
 Replaces the Log file to write to. More...
 
virtual KKStr BuildDate () const
 
virtual void InitalizeApplication (kkint32 argc, char **argv)
 Initialized Application Instance; 1st method to be called after instance construction. More...
 

Public Attributes

RunLoglog
 

Protected Member Functions

virtual void DisplayCommandLineParameters ()
 Will display Command Lone parameters that the 'Application' class will manage. More...
 
virtual bool ProcessCmdLineParameter (const KKStr &parmSwitch, const KKStr &parmValue)
 This method will get called once for each parameter specified in the command line. More...
 

Detailed Description

The base class for all standalone application.

This class is meant to be a general class that all standalone applications should be inherited from. It supports command line processing, and logging facilities. Derived classes will need to override the virtual methods "ApplicationName", "DisplayCommandLineParameters", and "ProcessCmdLineParameter". Right after an instance is created you need to call the "InitalizeApplication" method; this will start the processing of any encountered parameters. For each set of parameters encountered a call to "ProcessCmdLineParameter" will be made; this is where you can intercept and process parameters that are specific to your application. Any parameters that you do not recognized should be passed onto the base-class by calling "Application::ProcessCmdLineParameter".

Definition at line 29 of file Application.h.

Constructor & Destructor Documentation

Application::Application ( )

Constructor for Application class that will start with a default logger(RunLog),.

After creating an instance of this class you initialize it by calling InitalizeApplication.

Definition at line 39 of file Application.cpp.

References KKB::KKStr::KKStr(), log, and KKB::RunLog::RunLog().

39  :
40  abort (false),
41  log (*(new RunLog ())),
42  logFileName (),
43  ourLog (NULL)
44 {
45  ourLog = &log;
46 }
Used for logging messages.
Definition: RunLog.h:49
Application::Application ( const Application _application)

Copy Constructor for Application class.

Parameters
[in]_applicationApplication instance to copy.

Definition at line 51 of file Application.cpp.

References KKB::KKStr::KKStr(), and log.

51  :
52  abort (_application.abort),
53  log (_application.log),
54  logFileName (_application.logFileName),
55  ourLog (_application.ourLog)
56 {
57 }
Application::Application ( RunLog _log)

Constructor for Application class where we already have an existing logger '_log'.

After creating an instance of this class you initialize it by calling InitalizeApplication.

Parameters
[in]_logA reference to a RunLog object.

Definition at line 29 of file Application.cpp.

References KKB::KKStr::KKStr(), and log.

29  :
30  abort (false),
31  log (_log),
32  logFileName (),
33  ourLog (NULL)
34 {
35 }
Application::~Application ( )
virtual

Definition at line 61 of file Application.cpp.

62 {
63  delete ourLog;
64  ourLog = NULL;
65 }

Member Function Documentation

bool KKB::Application::Abort ( )
inline

Returns 'true' if application has been aborted.

You would typically call this method after you are done processing the command line to make sure that the application is to keep on running.

Definition at line 62 of file Application.h.

62 {return abort;}
void KKB::Application::Abort ( bool  _abort)
inline

Used to specify that the application is been aborted.

If you have a reason to abort the processing of this application you would call this method to set the 'abort' flag to true. It will be the responsibility of the derived class to monitor the 'Abort' flag. If is set to true they should terminate as quickly as they can; they should also release any resources they have taken.

Parameters
[in]_abortAbort status to set; if set to true you are telling the application that the program needs to be terminated.

Definition at line 71 of file Application.h.

71 {abort = _abort;}
const char * Application::ApplicationName ( )
virtual

Specify the name of the application

Definition at line 80 of file Application.cpp.

81 {
82  return "No-Application-Name-Provided";
83 } /* ApplicationName */
void Application::AssignLog ( RunLog _log)

Replaces the Log file to write to.

Definition at line 87 of file Application.cpp.

References log.

88 {
89  log = _log;
90 
91  if (ourLog)
92  {
93  delete ourLog;
94  ourLog = NULL;
95  }
96 } /* AssignRunLog */
KKStr Application::BuildDate ( ) const
virtual

Definition at line 162 of file Application.cpp.

References KKB::DateType::DateType(), KKB::TimeType::HH_MM_SS(), KKB::KKStr::operator+(), KKB::TimeType::TimeType(), and KKB::DateType::YYYY_MM_DD().

163 {
164  DateType buildDate (__DATE__);
165  TimeType buildTime (__TIME__);
166  return buildDate.YYYY_MM_DD () + "-" + buildTime.HH_MM_SS ();
167 } /* BuildDate */
Represents a Time, consisting of three fields, Hour, Minute, and Second. summary>Represents Date and ...
Definition: DateTime.h:149
Represents a calendar date consisting of three fields, Year, Month, and Day.
Definition: DateTime.h:28
void Application::DisplayCommandLineParameters ( )
protectedvirtual

Will display Command Lone parameters that the 'Application' class will manage.

Derived classes that implement this method need to call their immediate base class version of this method to include these parameters.

Definition at line 134 of file Application.cpp.

135 {
136  cout << ApplicationName () << endl
137  << endl
138  << " -LogFile <FileName> File that logging messages will be written to; if left will" << endl
139  << " be written to Standard-Out (cout)." << endl
140  << endl
141  << " -CmdFile <File-Name> Filename where additional command line options are stored;" << endl
142  << " This file can also specify additional '-CmdFile parameters." << endl
143  << endl;
144 }
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
virtual const char * ApplicationName()
Definition: Application.cpp:80
void Application::InitalizeApplication ( kkint32  argc,
char **  argv 
)
virtual

Initialized Application Instance; 1st method to be called after instance construction.

This method will scan the command line parameters for the log file options (-L, -Log, or -LogFile) and use its parameter as the LogFile name. If none is provided it will assume the stdout as the Log File to write to. It will take ownership of this log file and delete it in its destructor. Right after calling this constructor you will need to call the method ProcessCmdLineParameters.

See also
RunLog
ProcessCmdLineParameters
Parameters
[in]argcNumber of arguments in argv.
[in]argvList of asciiz strings; one string for each argument.

Definition at line 69 of file Application.cpp.

References KKB::RunLog::AttachFile(), KKB::KKStr::Empty(), and log.

72 {
73  ProcessCmdLineParameters (argc, argv);
74  if (!logFileName.Empty ())
75  log.AttachFile (logFileName);
76 }
bool Empty() const
Definition: KKStr.h:241
void AttachFile(const KKStr &_fileName)
Call this method to start logging messages to a different file.
Definition: RunLog.cpp:127
bool Application::ProcessCmdLineParameter ( const KKStr parmSwitch,
const KKStr parmValue 
)
protectedvirtual

This method will get called once for each parameter specified in the command line.

Derived classes should define this method to intercept parameters that they are interested in. Parameters are treated as pairs, Switch and Values where switches have a leading dash("-"). The CmdLineExpander class will be used to expand any "-CmdFile" parameters.

Parameters
[in]parmSwitchThe fill switch parameter.
[in]parmValueAny value parameter that followed the switch parameter.

Definition at line 149 of file Application.cpp.

152 {
153  log.Level (-1) << endl
154  << "Application::ProcessCmdLineParameter ***ERROR*** Unrecognized Parameter [" << parmSwitch << "] Value [" << parmValue << "]" << endl
155  << endl;
156  return false;
157 }
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220

Member Data Documentation

RunLog& KKB::Application::log

Definition at line 143 of file Application.h.

Referenced by Application(), AssignLog(), and InitalizeApplication().


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