Subversion Repositories spk

Rev

Rev 309 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
303 cycrow 1
#pragma once
2
 
3
#include "WString.h"
4
#include "WStringList.h"
5
#include "../File_IO.h"
6
#include "../DirIO.h"
7
 
8
namespace Utils
9
{
10
	class CommandLine
11
	{
12
	private:
13
		std::shared_ptr<CFileIO> _file;
14
		Utils::WStringList _options;
15
		std::vector<Utils::WString> _args;
16
 
17
	public:
18
		CommandLine(int argc, char* argv[])
19
		{
20
			_file = std::make_shared<CFileIO>(argv[0]);
21
 
22
			for (int i = 1; i < argc; i++)
23
			{
24
				Utils::WString arg(argv[i]);
25
				if (arg.startsWith(L"--"))
26
				{
27
					arg = arg.substr(2);
28
 
29
					if (arg.contains(L":"))
30
					{
31
						Utils::WString a = arg.token(L":", 1);
32
						Utils::WString b = arg.tokens(L":", 2);
33
						_options.pushBack(a, b);
34
					}
35
					else
36
						_options.pushBack(arg);
37
				}
38
				else
39
					_args.push_back(arg);
40
			}
41
		}
42
 
43
		const std::shared_ptr<CFileIO> file() const
44
		{
45
			return _file;
46
		}
47
 
48
		const Utils::WString& cmdName() const
49
		{
50
			return _file->filename();
51
		}
52
 
53
		const Utils::WString& cmdDir() const
54
		{
55
			return _file->dir();
56
		}
57
 
58
		const Utils::WStringList options() const
59
		{
60
			return _options;
61
		}
62
 
63
		const std::vector<Utils::WString>& args() const
64
		{
65
			return _args;
66
		}
67
 
68
		size_t argCount() const
69
		{
70
			return _args.size();
71
		}
72
 
73
		Utils::WString arg(size_t i) const
74
		{
75
			if(i >= _args.size())
76
				return Utils::WString::Null();
77
			return _args[i];
78
		}
79
 
80
		bool hasSwitch(const Utils::WString& s) const
81
		{
82
			return _options.contains(s);
83
		}
84
 
85
		Utils::WString switchData(const Utils::WString& s) const
86
		{
87
			if (_options.contains(s))
88
				return _options[s]->data;
89
			return Utils::WString::Null();
90
		}
91
	};
92
}