FreeNOS
Application.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIBAPP_APPLICATION_H
19 #define __LIBAPP_APPLICATION_H
20 
21 #include <Types.h>
22 #include <Macros.h>
23 #include <Log.h>
24 #include "ArgumentParser.h"
25 #include "ArgumentContainer.h"
26 
39 {
40  private:
41 
43  static const uint ExitSuccess = 0;
44 
46  static const uint ExitFailure = 1;
47 
48  public:
49 
53  enum Result
54  {
62  };
63 
64  public:
65 
72  Application(int argc, char **argv);
73 
77  virtual ~Application();
78 
84  virtual int run();
85 
86  protected:
87 
93  virtual Result initialize();
94 
100  virtual Result exec() = 0;
101 
108  virtual Result output(const char *string) const = 0;
109 
117  virtual Result output(String & string) const;
118 
119  protected:
120 
127 
133  const ArgumentParser & parser() const;
134 
138  const ArgumentContainer & arguments() const;
139 
145  void setVersion(const String & version);
146 
147  private:
148 
152  void usage() const;
153 
154  protected:
155 
157  int m_argc;
158 
160  char ** m_argv;
161 
162  private:
163 
166 
169 
172 };
173 
179 #endif /* __LIBAPP_APPLICATION_H */
Application::usage
void usage() const
Print usage and terminate.
Definition: Application.cpp:91
Application::~Application
virtual ~Application()
Class destructor.
Definition: Application.cpp:29
Macros.h
Application::setVersion
void setVersion(const String &version)
Set program version.
Definition: Application.cpp:117
Types.h
Application::run
virtual int run()
Run the application.
Definition: Application.cpp:38
Application::m_version
String m_version
Program version.
Definition: Application.h:171
String
Abstraction of strings.
Definition: String.h:41
Application::TimedOut
@ TimedOut
Definition: Application.h:60
ArgumentParser
Generic command-line argument parser.
Definition: ArgumentParser.h:40
Application::exec
virtual Result exec()=0
Execute the application event loop.
Application::Application
Application(int argc, char **argv)
Class constructor.
Definition: Application.cpp:20
Application::NotFound
@ NotFound
Definition: Application.h:56
Application::m_argv
char ** m_argv
Input argument values.
Definition: Application.h:160
Application::output
virtual Result output(const char *string) const =0
Print text to output.
Application
Generic application.
Definition: Application.h:38
Application::Success
@ Success
Definition: Application.h:55
Application::arguments
const ArgumentContainer & arguments() const
Get program arguments.
Definition: Application.cpp:112
Application::ShowUsage
@ ShowUsage
Definition: Application.h:59
Log.h
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
ArgumentContainer.h
Application::IOError
@ IOError
Definition: Application.h:57
ArgumentContainer
Generic command-line argument parser.
Definition: ArgumentContainer.h:40
Application::OutOfMemory
@ OutOfMemory
Definition: Application.h:61
Application::InvalidArgument
@ InvalidArgument
Definition: Application.h:58
Application::ExitFailure
static const uint ExitFailure
Exit code for failure termination.
Definition: Application.h:46
Application::m_arguments
ArgumentContainer m_arguments
Parsed Arguments.
Definition: Application.h:168
Application::Result
Result
Result codes.
Definition: Application.h:53
Application::ExitSuccess
static const uint ExitSuccess
Exit code for successful termination.
Definition: Application.h:43
Application::initialize
virtual Result initialize()
Initialize the application.
Definition: Application.cpp:33
Application::parser
ArgumentParser & parser()
Get program arguments parser.
Definition: Application.cpp:102
ArgumentParser.h
Application::m_parser
ArgumentParser m_parser
Program argument parser object.
Definition: Application.h:165
Application::m_argc
int m_argc
Input argument count.
Definition: Application.h:157