1 /*
2  * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
3  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
4  */
5 
6 #ifndef BX_COMMANDLINE_H_HEADER_GUARD
7 #define BX_COMMANDLINE_H_HEADER_GUARD
8 
9 #include "string.h"
10 
11 namespace bx
12 {
13 	///
14 	StringView tokenizeCommandLine(const StringView& _commandLine, char* _buffer, uint32_t& _bufferSize, int32_t& _argc, char* _argv[], int32_t _maxArgvs, char _term = '\0');
15 
16 	///
17 	class CommandLine
18 	{
19 	public:
20 		///
21 		CommandLine(int32_t _argc, char const* const* _argv);
22 
23 		///
24 		const char* findOption(const char* _long, const char* _default) const;
25 
26 		///
27 		const char* findOption(const char _short, const char* _long, const char* _default) const;
28 
29 		///
30 		const char* findOption(const char* _long, int32_t _numParams = 1) const;
31 
32 		///
33 		const char* findOption(const char _short, const char* _long = NULL, int32_t _numParams = 1) const;
34 
35 		///
36 		const char* findOption(int32_t _skip, const char _short, const char* _long = NULL, int32_t _numParams = 1) const;
37 
38 		///
39 		bool hasArg(const char _short, const char* _long = NULL) const;
40 
41 		///
42 		bool hasArg(const char* _long) const;
43 
44 		///
45 		bool hasArg(const char*& _value, const char _short, const char* _long = NULL) const;
46 
47 		///
48 		bool hasArg(int32_t& _value, const char _short, const char* _long = NULL) const;
49 
50 		///
51 		bool hasArg(uint32_t& _value, const char _short, const char* _long = NULL) const;
52 
53 		///
54 		bool hasArg(float& _value, const char _short, const char* _long = NULL) const;
55 
56 		///
57 		bool hasArg(double& _value, const char _short, const char* _long = NULL) const;
58 
59 		///
60 		bool hasArg(bool& _value, const char _short, const char* _long = NULL) const;
61 
62 		///
63 		int32_t getNum() const;
64 
65 		///
66 		char const* get(int32_t _idx) const;
67 
68 	private:
69 		///
70 		const char* find(int32_t _skip, const char _short, const char* _long, int32_t _numParams) const;
71 
72 		int32_t m_argc;
73 		char const* const* m_argv;
74 	};
75 
76 } // namespace bx
77 
78 #endif /// BX_COMMANDLINE_H_HEADER_GUARD
79