summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pmain.h
blob: e2f84b90de62ca36479ed8042ffe7199095b563a (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
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
 * poptions.h
 *
 */

#pragma once

#ifndef PMAIN_H_
#define PMAIN_H_

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

#include <memory>
#include <cwchar>

#ifdef _WIN32
#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();
		virtual ~app();

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

		plib::pstdout pout_strm;
		plib::pstderr perr_strm;

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

		template <class C, typename T>
		static int mainrun(int argc, T *argv[])
		{
			auto a = std::unique_ptr<C>(new 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

	};

}



#endif /* PMAIN_H_ */