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 "buf.h"
19#ifdef __PTPMGMT_HAVE_GETOPT_H
20#include <getopt.h>
21#endif
22
23__PTPMGMT_NAMESPACE_BEGIN
24
28struct Pmc_option {
34 std::string long_name;
35 bool have_arg;
36 bool long_only;
37 std::string help_msg;
38 std::string arg_help;
39 std::string def_val;
40};
41
46{
47 private:
48
49 static Pmc_option startOptions[];
50 size_t m_max_arg_name = 0;
51 std::vector<option> m_long_opts_list;
52 Buf m_strings;
53 size_t m_last_strings = 0;
54 std::map<int, std::string> m_opts;
55 std::string m_net_opts, m_all_opts, m_all_short_opts, m_with_opts, m_msg;
56 char m_net_select = 0;
57 int m_argc = 0, m_end_optind = 0;
58 bool m_useDef = false;
59
60 class helpStore
61 {
62 private:
63 std::string m_start, m_end;
64 public:
65 helpStore(const char *s, const char *e = nullptr): m_start(s) {
66 if(e != nullptr)
67 m_end = e;
68 }
69 helpStore &addStart(const std::string &s) {m_start += s; return *this;}
70 helpStore &addStart(const char s) {m_start += s; return *this;}
71 helpStore &addEnd(const std::string &e) {m_end += e; return *this;}
72 std::string get(size_t length) const;
73 };
74 std::string help;
75 std::vector<helpStore> helpVec;
76 void update_help();
77
78 public:
90 Options(bool useDef = true);
101 bool insert(const Pmc_option &opt);
106 const char *get_help() const;
111 const std::string &get_msg() const;
116 const char *get_msg_c() const;
141 loop_val parse_options(int argc, char *const argv[]);
147 bool have(char opt) const;
154 const std::string &val(char opt) const;
161 const char *val_c(char opt) const;
168 int val_i(char opt) const;
174 char get_net_transport() const;
179 bool have_more() const;
184 int process_next() const;
185};
186
187__PTPMGMT_NAMESPACE_END
188#else /* __cplusplus */
189#include "c/opt.h"
190#endif /* __cplusplus */
191
192#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:46
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:80
@ OPT_DONE
Definition opt.h:84
@ OPT_HELP
Definition opt.h:83
@ OPT_MSG
Definition opt.h:82
@ OPT_ERR
Definition opt.h:81
int process_next() const
const char * get_help() const
bool have_more() const
Definition opt.h:28
std::string arg_help
Definition opt.h:38
std::string help_msg
Definition opt.h:37
std::string def_val
Definition opt.h:39
char short_name
Definition opt.h:33
bool have_arg
Definition opt.h:35
std::string long_name
Definition opt.h:34
bool long_only
Definition opt.h:36