summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pmain.h
blob: cfa73844f57fb13ceb75d644da3184f1cd6280b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
 * poptions.h
 *
 */

#pragma once

#ifndef PMAIN_H_
#define PMAIN_H_

#include "palloc.h"
#include "poptions.h"
#include "pstream.h"
#include "pstring.h"
#include "putil.h"

#include <memory>

#ifdef _WIN32
#include <cwchar>
#define PMAIN(appclass) \
extern "C" int wmain(int argc, wchar_t *argv[]) { return plib::app::mainrun<appclass, wchar_t>(argc, argv); }
#else
#define PMAIN(appclass) \
int main(int argc, char **argv) { return plib::app::mainrun<appclass, char>(argc, argv); }
#endif


namespace plib {
/***************************************************************************
    Application
***************************************************************************/

	class app : public options
	{
	public:
		app();

		COPYASSIGNMOVE(app, delete)

		virtual ~app() = default;

		virtual pstring usage() = 0;
		virtual int execute() = 0;

		plib::putf8_fmt_writer pout;
		plib::putf8_fmt_writer perr;

		template <class C, typename T>
		static int mainrun(int argc, T **argv)
		{
			auto a = plib::make_unique<C>();
			return a->main_utfX(argc, argv);
		}

	private:
		int main_utfX(int argc, char **argv);
#ifdef _WIN32
		int main_utfX(int argc, wchar_t *argv[]);
#endif

	};

} // namespace plib



#endif /* PMAIN_H_ */