WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
ArgParser.h
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (c) ATTX INC 2025. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX INC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX INC.
15******************************************************************************/
16#ifndef ARG_PARSER_H
17#define ARG_PARSER_H
18
19#include <vector>
20#include <string>
21
24
25namespace warptwin {
26
27 const std::string ARG_INDICATOR = "--";
28
32 class ArgParser {
33 public:
37
41 std::string operator () (const std::string &name) {std::string tmp; get(name, tmp); return tmp;}
42
47 int get(const std::string &name, std::string &val);
48
53 int get(const std::string &name, double &val);
54
59 int get(const std::string &name, int &val);
60
65 int parseArgs(int argc, char *argv[]);
66
70 int parseArgs(std::vector<std::string> args);
71
75 void addDefaultArgument(const std::string &name, const std::string &val);
76
80 void addDefaultArgument(const std::string &name, double val);
81
85 void addDefaultArgument(const std::string &name, int val);
86
88 void dump();
89 private:
90 // Pair to store key value pairs as <key, value>
91 std::vector<std::pair<std::string, std::string>> _key_val_pairs;
92
93 // Pair to store default key value pairs that can be overwritten by input arguments
94 std::vector<std::pair<std::string, std::string>> _default_key_val_pairs;
95 };
96
101 bool contains(const std::string &parent_str, const std::string &substr);
102
107 std::string trim(const std::string& str, const std::string& whitespace=" \t");
108
109}
110
111#endif
std::string operator()(const std::string &name)
Function to get the string value of an arg.
Definition ArgParser.h:41
void addDefaultArgument(const std::string &name, const std::string &val)
Function to add a default argument that can be overridden from the cmd line.
Definition ArgParser.cpp:144
~ArgParser()
Definition ArgParser.h:36
void dump()
Function to dump all argument value pairs held in the class.
Definition ArgParser.cpp:156
ArgParser()
Default constructor for the arg parser – sets name to "args".
Definition ArgParser.h:35
int parseArgs(int argc, char *argv[])
Function to parse argc and argv for string arguments.
Definition ArgParser.cpp:77
int get(const std::string &name, std::string &val)
Function to get the string value of an arg.
Definition ArgParser.cpp:22
Class to propagate CR3BP dynamics in characteristic units.
Definition statistics.hpp:22
const std::string ARG_INDICATOR
Definition ArgParser.h:27
bool contains(const std::string &parent_str, const std::string &substr)
Function to return whether substr is in parent_str.
Definition ArgParser.cpp:195
std::string trim(const std::string &str, const std::string &whitespace)
Function to trim leading and trailing whitespace from string.
Definition ArgParser.cpp:199