w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RtclArgs.hpp
Go to the documentation of this file.
1// $Id: RtclArgs.hpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-09-22 1049 1.0.10 BUGFIX: get *_min limits correct
8// 2013-05-19 521 1.0.9 add NextSubOpt() method, pass optset's as const
9// 2013-03-05 495 1.0.8 add SetResult(bool)
10// 2013-03-02 494 1.0.7 add Quit() method
11// 2013-02-12 487 1.0.6 add CurrentArg() method
12// 2013-02-01 479 1.0.5 add Objv() method
13// 2011-03-26 373 1.0.4 add GetArg(flt/dbl), SetResult(str,sos,int,dbl)
14// 2011-03-13 369 1.0.3 add GetArg(vector<unit8_t>)
15// 2011-03-06 367 1.0.2 add min to GetArg(unsigned); add Config() methods;
16// 2011-03-05 366 1.0.1 fObjc,fNDone now size_t; add NDone(), NOptMiss();
17// add SetResult(), GetArg(Tcl_Obj), PeekArgString();
18// 2011-02-26 364 1.0 Initial version
19// 2011-02-06 359 0.1 First draft
20// ---------------------------------------------------------------------------
21
22
27#ifndef included_Retro_RtclArgs
28#define included_Retro_RtclArgs 1
29
30#include "tcl.h"
31
32#include <cstddef>
33#include <vector>
34#include <limits>
35#include <sstream>
36
37#include "RtclNameSet.hpp"
38
39namespace Retro {
40
41 class RtclArgs {
42 public:
43
44 const static int8_t int8_min = std::numeric_limits<int8_t>::min();
45 const static int8_t int8_max = std::numeric_limits<int8_t>::max();
46 const static uint8_t uint8_max = std::numeric_limits<uint8_t>::max();
47 const static int16_t int16_min = std::numeric_limits<int16_t>::min();
48 const static int16_t int16_max = std::numeric_limits<int16_t>::max();
49 const static uint16_t uint16_max = std::numeric_limits<uint16_t>::max();
50 const static int32_t int32_min = std::numeric_limits<int32_t>::min();
51 const static int32_t int32_max = std::numeric_limits<int32_t>::max();
52 const static uint32_t uint32_max = std::numeric_limits<uint32_t>::max();
53
54 RtclArgs();
55 RtclArgs(Tcl_Interp* interp, int objc,
56 Tcl_Obj* const objv[], size_t nskip=1);
57 RtclArgs(const RtclArgs& rhs);
58 ~RtclArgs();
59
60 Tcl_Interp* Interp() const;
61 int Objc() const;
62 Tcl_Obj* const * Objv() const;
63 Tcl_Obj* Objv(size_t ind) const;
64
65 bool GetArg(const char* name, Tcl_Obj*& pval);
66
67 bool GetArg(const char* name, const char*& val);
68 bool GetArg(const char* name, std::string& val);
69
70 bool GetArg(const char* name, int8_t& val,
71 int8_t min=int8_min, int8_t max=int8_max);
72 bool GetArg(const char* name, uint8_t& val,
73 uint8_t max=uint8_max, uint8_t min=0);
74 bool GetArg(const char* name, int16_t& val,
75 int16_t min=int16_min, int16_t max=int16_max);
76 bool GetArg(const char* name, uint16_t& val,
77 uint16_t max=uint16_max, uint16_t min=0);
78 bool GetArg(const char* name, int32_t& val,
79 int32_t min=int32_min, int32_t max=int32_max);
80 bool GetArg(const char* name, uint32_t& val,
81 uint32_t max=uint32_max, uint32_t min=0);
82
83 bool GetArg(const char* name, float& val,
84 float min=-1.e30, float max=+1.e30);
85 bool GetArg(const char* name, double& val,
86 double min=-1.e30, double max=+1.e30);
87
88 bool GetArg(const char* name, std::vector<uint8_t>& val,
89 size_t lmin=0, size_t lmax=uint32_max);
90 bool GetArg(const char* name, std::vector<uint16_t>& val,
91 size_t lmin=0, size_t lmax=uint32_max);
92
93 bool Config(const char* name, std::string& val);
94 bool Config(const char* name, uint32_t& val,
95 uint32_t max=uint32_max, uint32_t min=0);
96
97 bool NextOpt(std::string& val);
98 bool NextOpt(std::string& val, const RtclNameSet& optset);
99 int NextSubOpt(std::string& val, const RtclNameSet& optset);
100 bool OptValid() const;
101
102 Tcl_Obj* CurrentArg() const;
103
104 bool AllDone();
105 size_t NDone() const;
106 size_t NOptMiss() const;
107
108 const char* PeekArgString(int rind) const;
109
110 void SetResult(const std::string& str);
111 void SetResult(std::ostringstream& sos);
112 void SetResult(bool val);
113 void SetResult(int val);
114 void SetResult(double val);
115 void SetResult(Tcl_Obj* pobj);
116
117 void AppendResult(const char* str, ...);
118 void AppendResult(const std::string& str);
119 void AppendResult(std::ostringstream& sos);
120 void AppendResultLines(const std::string& str);
121 void AppendResultLines(std::ostringstream& sos);
122
123 int Quit(const std::string& str);
124
125 Tcl_Obj* operator[](size_t ind) const;
126
127 protected:
128 bool NextArg(const char* name, Tcl_Obj*& pobj);
129 bool NextArgList(const char* name, int& objc,
130 Tcl_Obj**& objv, size_t lmin=0,
131 size_t lmax=uint32_max);
132 void ConfigNameCheck(const char* name);
133 bool ConfigReadCheck();
134
135 protected:
136 Tcl_Interp* fpInterp;
137 size_t fObjc;
138 Tcl_Obj* const * fObjv;
139 size_t fNDone;
140 size_t fNOptMiss;
142 bool fOptErr;
143 bool fArgErr;
144
145 };
146
147} // end namespace Retro
148
149#include "RtclArgs.ipp"
150
151#endif
FIXME_docs.
Definition: RtclArgs.hpp:41
void ConfigNameCheck(const char *name)
FIXME_docs.
Definition: RtclArgs.cpp:561
Tcl_Obj * CurrentArg() const
FIXME_docs.
Definition: RtclArgs.cpp:435
bool NextOpt(std::string &val)
FIXME_docs.
Definition: RtclArgs.cpp:368
static const int32_t int32_min
Definition: RtclArgs.hpp:50
static const int16_t int16_max
Definition: RtclArgs.hpp:48
const char * PeekArgString(int rind) const
FIXME_docs.
Definition: RtclArgs.cpp:461
void AppendResultLines(const std::string &str)
FIXME_docs.
Definition: RtclArgs.cpp:484
Tcl_Obj *const * Objv() const
FIXME_docs.
Definition: RtclArgs.ipp:44
Tcl_Obj * operator[](size_t ind) const
FIXME_docs.
Definition: RtclArgs.ipp:166
int NextSubOpt(std::string &val, const RtclNameSet &optset)
FIXME_docs.
Definition: RtclArgs.cpp:409
bool fArgErr
argument processing error flag
Definition: RtclArgs.hpp:143
bool GetArg(const char *name, Tcl_Obj *&pval)
FIXME_docs.
Definition: RtclArgs.cpp:114
RtclArgs()
Default constructor.
Definition: RtclArgs.cpp:52
size_t fNOptMiss
number of missed optional args
Definition: RtclArgs.hpp:140
Tcl_Obj *const * fObjv
original args vector
Definition: RtclArgs.hpp:138
static const int8_t int8_max
Definition: RtclArgs.hpp:45
bool Config(const char *name, std::string &val)
FIXME_docs.
Definition: RtclArgs.cpp:333
size_t fNConfigRead
number of read mode config's
Definition: RtclArgs.hpp:141
void AppendResult(const char *str,...)
FIXME_docs.
Definition: RtclArgs.cpp:471
bool OptValid() const
FIXME_docs.
Definition: RtclArgs.ipp:52
static const int8_t int8_min
Definition: RtclArgs.hpp:44
bool fOptErr
option processing error flag
Definition: RtclArgs.hpp:142
int Quit(const std::string &str)
FIXME_docs.
Definition: RtclArgs.ipp:157
static const uint8_t uint8_max
Definition: RtclArgs.hpp:46
static const int32_t int32_max
Definition: RtclArgs.hpp:51
bool ConfigReadCheck()
FIXME_docs.
Definition: RtclArgs.cpp:571
void SetResult(const std::string &str)
FIXME_docs.
Definition: RtclArgs.ipp:76
int Objc() const
FIXME_docs.
Definition: RtclArgs.ipp:36
static const uint16_t uint16_max
Definition: RtclArgs.hpp:49
size_t fNDone
number of processed args
Definition: RtclArgs.hpp:139
bool NextArgList(const char *name, int &objc, Tcl_Obj **&objv, size_t lmin=0, size_t lmax=uint32_max)
FIXME_docs.
Definition: RtclArgs.cpp:535
static const int16_t int16_min
Definition: RtclArgs.hpp:47
bool NextArg(const char *name, Tcl_Obj *&pobj)
FIXME_docs.
Definition: RtclArgs.cpp:499
static const uint32_t uint32_max
Definition: RtclArgs.hpp:52
size_t NOptMiss() const
FIXME_docs.
Definition: RtclArgs.ipp:68
~RtclArgs()
Destructor.
Definition: RtclArgs.cpp:98
Tcl_Interp * fpInterp
pointer to tcl interpreter
Definition: RtclArgs.hpp:136
size_t NDone() const
FIXME_docs.
Definition: RtclArgs.ipp:60
Tcl_Interp * Interp() const
FIXME_docs.
Definition: RtclArgs.ipp:28
bool AllDone()
FIXME_docs.
Definition: RtclArgs.cpp:447
size_t fObjc
original args count
Definition: RtclArgs.hpp:137
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47