diff -r 148f8dd077e8 -r 465572518625 src/CLI.h --- a/src/CLI.h Mon Aug 19 17:21:02 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/** - * cadMousePro - * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -/** - * a common header-only library for CLI programs - */ -class CLI { -public: - - CLI(int argc, char* argv[]) { - setlocale(LC_ALL, ""); - - this->argc = &argc; - this->argv = &argv; - - program = convertor.from_bytes(argv[0]); - - for (int i = 1; i < argc; i++) { - args.insert(args.end(), convertor.from_bytes(argv[i])); - } - - } - - CLI(const CLI& orig) { - } - - virtual ~CLI() { - } - - const std::wstring programName() { - return (const std::wstring) program; - } - - const std::vector arguments() { - return (const std::vector)args; - } - - static const int EXIT_CODE_SUCCESS = 0; - static const int EXIT_CODE_UNEXPECTED_ERROR = 1; - static const int EXIT_CODE_BAD_CLI_ARGUMENTS = 6; - - /** - * std::cin and std::cout are "tied" by default i.e. reading from std::cin causes flush of the std::cout. - * Call this to "untie" them and have less write() calls (better buffering). - */ - static void untieStdIO() { - std::cin.tie(nullptr); - } - -private: - int* argc; - char*** argv; - std::wstring program; - std::vector args; - std::wstring_convert> convertor; // TODO: support also other encodings. -};