#ifndef _INPUTPARSER_
#define _INPUTPARSER_
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
/// @brief Анализирует входящие параметры
class InputParser
{
public:
    InputParser(){}
    InputParser(int &argc, char **argv)
    {
        for (int i = 1; i < argc; ++i)
            this->tokens.push_back(std::string(argv[i]));
    }
    /// @brief Пакует без параметров --debug и address
    /// @param argc
    /// @param argv
    InputParser(int &argc, char **argv, bool skip)
    {
        for (int i = 1; i < argc; ++i)
        {
            std::string cur(argv[i]);
            if (cur.compare("--debug") == 0)
            {
                ++i;
                continue;
            }
            if (cur.compare("--address") == 0)
            {
                i += 2;
                continue;
            }
            this->tokens.push_back(cur);
        }
    }
    /// @brief получение строки параметров
    const std::string &getCmdOption(const std::string &option) const
    {
        std::vector<std::string>::const_iterator itr;
        itr = std::find(this->tokens.begin(), this->tokens.end(), option);
        if (itr != this->tokens.end() && ++itr != this->tokens.end())
        {
            return *itr;
        }
        static const std::string empty_string("");
        return empty_string;
    }
    /// @brief get last argument
    const std::string& getLast() {
        return tokens[tokens.size() - 1];
    }
    const void getBuffer() const
    {
        std::string ret;
        for (const auto &s : this->tokens)
        {
            if (!ret.empty())
                ret += ",";
            ret += s;
        }
        std::cout << ret << std::endl;
    }
    /// @brief существует ли параметр
    bool cmdOptionExists(const std::string &option) const
    {
        return std::find(this->tokens.begin(), this->tokens.end(), option) != this->tokens.end();
    }

private:
    std::vector<std::string> tokens;
};

#endif