PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
inputParser.h
Go to the documentation of this file.
1/*
2* -------------------------------------------
3 * Copyright (c) 2021 - 2026 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#ifndef UTILS_IO_INPUTPARSER_H
12#define UTILS_IO_INPUTPARSER_H
13
14#include <fstream>
15#include <iostream>
16#include <vector>
17#include <algorithm>
18
19namespace util {
21 namespace io {
29 public:
35 InputParser(int &argc, char **argv) {
36 for (int i = 1; i < argc; ++i)
37 this->tokens.push_back(std::string(argv[i]));
38 }
39
45 const std::string &getCmdOption(const std::string &option) const {
46 std::vector<std::string>::const_iterator itr;
47 itr = std::find(this->tokens.begin(), this->tokens.end(), option);
48 if (itr != this->tokens.end() && ++itr != this->tokens.end())
49 return *itr;
50
51 static const std::string empty_string("");
52 return empty_string;
53 }
54
60 bool cmdOptionExists(const std::string &option) const {
61 return std::find(this->tokens.begin(), this->tokens.end(), option) != this->tokens.end();
62 }
63
64 private:
66 std::vector<std::string> tokens;
67 };
68 } // namespace io
69} // namespace util
70
71#endif // UTILS_IO_INPUTPARSER_H
Input command line argument parser.
Definition inputParser.h:28
std::vector< std::string > tokens
Tokens.
Definition inputParser.h:66
InputParser(int &argc, char **argv)
Constructor.
Definition inputParser.h:35
bool cmdOptionExists(const std::string &option) const
Check if argument exists.
Definition inputParser.h:60
const std::string & getCmdOption(const std::string &option) const
Get value of argument specified by key.
Definition inputParser.h:45
Collection of methods useful in simulation.
Definition constants.h:14