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
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
158
160 char ** m_argv;
161
162 private:
163
166
169
172};
173
179#endif /* __LIBAPP_APPLICATION_H */
Generic application.
Definition Application.h:39
ArgumentContainer m_arguments
Parsed Arguments.
virtual Result initialize()
Initialize the application.
char ** m_argv
Input argument values.
String m_version
Program version.
Result
Result codes.
Definition Application.h:54
const ArgumentContainer & arguments() const
Get program arguments.
void setVersion(const String &version)
Set program version.
virtual ~Application()
Class destructor.
static const uint ExitFailure
Exit code for failure termination.
Definition Application.h:46
ArgumentParser m_parser
Program argument parser object.
static const uint ExitSuccess
Exit code for successful termination.
Definition Application.h:43
virtual int run()
Run the application.
void usage() const
Print usage and terminate.
virtual Result output(const char *string) const =0
Print text to output.
virtual Result exec()=0
Execute the application event loop.
ArgumentParser & parser()
Get program arguments parser.
int m_argc
Input argument count.
Generic command-line argument parser.
Generic command-line argument parser.
Abstraction of strings.
Definition String.h:42
unsigned int uint
Unsigned integer number.
Definition Types.h:44