libptpmgmt 2.0
libptpmgmt library that provides the functionality of linuxptp pmc
Loading...
Searching...
No Matches
opt.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-3.0-or-later
2 SPDX-FileCopyrightText: Copyright © 2021 Erez Geva <ErezGeva2@gmail.com> */
3
12#ifndef __PTPMGMT_OPT_H
13#define __PTPMGMT_OPT_H
14
15#ifdef __cplusplus
16#include <map>
17#include <vector>
18#include "name.h"
19#include "buf.h"
20#ifdef __PTPMGMT_HAVE_GETOPT_H
21#include <getopt.h>
22#endif
23
24__PTPMGMT_NAMESPACE_BEGIN
25
29struct Pmc_option {
35 std::string long_name;
36 bool have_arg;
37 bool long_only;
38 std::string help_msg;
39 std::string arg_help;
40 std::string def_val;
41};
42
47{
48 private:
49
50 static Pmc_option startOptions[];
51 size_t m_max_arg_name = 0;
52 std::vector<option> m_long_opts_list;
53 Buf m_strings;
54 size_t m_last_strings = 0;
55 std::map<int, std::string> m_opts;
56 std::string m_net_opts, m_all_opts, m_all_short_opts, m_with_opts, m_msg;
57 char m_net_select = 0;
58 int m_argc = 0, m_end_optind = 0;
59 bool m_useDef = false;
60
61 class helpStore
62 {
63 private:
64 std::string m_start, m_end;
65 public:
66 helpStore(const char *s, const char *e = nullptr): m_start(s) {
67 if(e != nullptr)
68 m_end = e;
69 }
70 helpStore &addStart(const std::string &s) {m_start += s; return *this;}
71 helpStore &addStart(const char s) {m_start += s; return *this;}
72 helpStore &addEnd(const std::string &e) {m_end += e; return *this;}
73 std::string get(size_t length) const;
74 };
75 std::string help;
76 std::vector<helpStore> helpVec;
77 void update_help();
78
79 public:
91 Options(bool useDef = true);
102 bool insert(const Pmc_option &opt);
107 const char *get_help() const;
112 const std::string &get_msg() const;
117 const char *get_msg_c() const;
142 loop_val parse_options(int argc, char *const argv[]);
148 bool have(char opt) const;
155 const std::string &val(char opt) const;
162 const char *val_c(char opt) const;
169 int val_i(char opt) const;
175 char get_net_transport() const;
180 bool have_more() const;
185 int process_next() const;
186};
187
188__PTPMGMT_NAMESPACE_END
189#else /* __cplusplus */
190#include "c/opt.h"
191#endif /* __cplusplus */
192
193#endif /* __PTPMGMT_OPT_H */
Buffer for send, receive, build, and parse.
C interface to command line options parsing class.
Definition buf.h:26
Definition opt.h:47
const std::string & val(char opt) const
int val_i(char opt) const
const char * val_c(char opt) const
bool insert(const Pmc_option &opt)
const char * get_msg_c() const
char get_net_transport() const
void useDefOption()
loop_val parse_options(int argc, char *const argv[])
const std::string & get_msg() const
Options(bool useDef=true)
bool have(char opt) const
loop_val
Definition opt.h:81
@ OPT_DONE
Definition opt.h:85
@ OPT_HELP
Definition opt.h:84
@ OPT_MSG
Definition opt.h:83
@ OPT_ERR
Definition opt.h:82
int process_next() const
const char * get_help() const
bool have_more() const
Define name space.
Definition opt.h:29
std::string arg_help
Definition opt.h:39
std::string help_msg
Definition opt.h:38
std::string def_val
Definition opt.h:40
char short_name
Definition opt.h:34
bool have_arg
Definition opt.h:36
std::string long_name
Definition opt.h:35
bool long_only
Definition opt.h:37