1 |
22 |
wfjm |
// $Id: RtclArgs.hpp 521 2013-05-20 22:16:45Z mueller $
|
2 |
10 |
wfjm |
//
|
3 |
19 |
wfjm |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
4 |
10 |
wfjm |
//
|
5 |
|
|
// This program is free software; you may redistribute and/or modify it under
|
6 |
|
|
// the terms of the GNU General Public License as published by the Free
|
7 |
|
|
// Software Foundation, either version 2, or at your option any later version.
|
8 |
|
|
//
|
9 |
|
|
// This program is distributed in the hope that it will be useful, but
|
10 |
|
|
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
11 |
|
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
12 |
|
|
// for complete details.
|
13 |
|
|
//
|
14 |
|
|
// Revision History:
|
15 |
|
|
// Date Rev Version Comment
|
16 |
22 |
wfjm |
// 2013-05-19 521 1.0.9 add NextSubOpt() method, pass optset's as const
|
17 |
19 |
wfjm |
// 2013-03-05 495 1.0.8 add SetResult(bool)
|
18 |
|
|
// 2013-03-02 494 1.0.7 add Quit() method
|
19 |
|
|
// 2013-02-12 487 1.0.6 add CurrentArg() method
|
20 |
|
|
// 2013-02-01 479 1.0.5 add Objv() method
|
21 |
10 |
wfjm |
// 2011-03-26 373 1.0.4 add GetArg(flt/dbl), SetResult(str,sos,int,dbl)
|
22 |
|
|
// 2011-03-13 369 1.0.3 add GetArg(vector<unit8_t>)
|
23 |
|
|
// 2011-03-06 367 1.0.2 add min to GetArg(unsigned); add Config() methods;
|
24 |
|
|
// 2011-03-05 366 1.0.1 fObjc,fNDone now size_t; add NDone(), NOptMiss();
|
25 |
|
|
// add SetResult(), GetArg(Tcl_Obj), PeekArgString();
|
26 |
|
|
// 2011-02-26 364 1.0 Initial version
|
27 |
|
|
// 2011-02-06 359 0.1 First draft
|
28 |
|
|
// ---------------------------------------------------------------------------
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/*!
|
32 |
|
|
\file
|
33 |
22 |
wfjm |
\version $Id: RtclArgs.hpp 521 2013-05-20 22:16:45Z mueller $
|
34 |
10 |
wfjm |
\brief Declaration of class RtclArgs.
|
35 |
|
|
*/
|
36 |
|
|
|
37 |
|
|
#ifndef included_Retro_RtclArgs
|
38 |
|
|
#define included_Retro_RtclArgs 1
|
39 |
|
|
|
40 |
|
|
#include "tcl.h"
|
41 |
|
|
|
42 |
|
|
#include <cstddef>
|
43 |
|
|
#include <vector>
|
44 |
|
|
#include <limits>
|
45 |
|
|
#include <sstream>
|
46 |
|
|
|
47 |
|
|
#include "RtclNameSet.hpp"
|
48 |
|
|
|
49 |
|
|
namespace Retro {
|
50 |
|
|
|
51 |
|
|
class RtclArgs {
|
52 |
|
|
public:
|
53 |
|
|
|
54 |
|
|
const static int8_t int8_min = 0xff;
|
55 |
|
|
const static int8_t int8_max = 0x7f;
|
56 |
|
|
const static uint8_t uint8_max = 0xff;
|
57 |
|
|
const static int16_t int16_min = 0xffff;
|
58 |
|
|
const static int16_t int16_max = 0x7fff;
|
59 |
|
|
const static uint16_t uint16_max = 0xffff;
|
60 |
|
|
const static int32_t int32_min = 0xffffffff;
|
61 |
|
|
const static int32_t int32_max = 0x7fffffff;
|
62 |
|
|
const static uint32_t uint32_max = 0xffffffff;
|
63 |
|
|
|
64 |
|
|
RtclArgs();
|
65 |
|
|
RtclArgs(Tcl_Interp* interp, int objc,
|
66 |
|
|
Tcl_Obj* const objv[], size_t nskip=1);
|
67 |
|
|
RtclArgs(const RtclArgs& rhs);
|
68 |
|
|
~RtclArgs();
|
69 |
|
|
|
70 |
|
|
Tcl_Interp* Interp() const;
|
71 |
|
|
int Objc() const;
|
72 |
19 |
wfjm |
Tcl_Obj* const * Objv() const;
|
73 |
10 |
wfjm |
Tcl_Obj* Objv(size_t ind) const;
|
74 |
|
|
|
75 |
|
|
bool GetArg(const char* name, Tcl_Obj*& pval);
|
76 |
|
|
|
77 |
|
|
bool GetArg(const char* name, const char*& val);
|
78 |
|
|
bool GetArg(const char* name, std::string& val);
|
79 |
|
|
|
80 |
|
|
bool GetArg(const char* name, int8_t& val,
|
81 |
|
|
int8_t min=int8_min, int8_t max=int8_max);
|
82 |
|
|
bool GetArg(const char* name, uint8_t& val,
|
83 |
|
|
uint8_t max=uint8_max, uint8_t min=0);
|
84 |
|
|
bool GetArg(const char* name, int16_t& val,
|
85 |
|
|
int16_t min=int16_min, int16_t max=int16_max);
|
86 |
|
|
bool GetArg(const char* name, uint16_t& val,
|
87 |
|
|
uint16_t max=uint16_max, uint16_t min=0);
|
88 |
|
|
bool GetArg(const char* name, int32_t& val,
|
89 |
|
|
int32_t min=int32_min, int32_t max=int32_max);
|
90 |
|
|
bool GetArg(const char* name, uint32_t& val,
|
91 |
|
|
uint32_t max=uint32_max, uint32_t min=0);
|
92 |
|
|
|
93 |
|
|
bool GetArg(const char* name, float& val,
|
94 |
|
|
float min=-1.e30, float max=+1.e30);
|
95 |
|
|
bool GetArg(const char* name, double& val,
|
96 |
|
|
double min=-1.e30, double max=+1.e30);
|
97 |
|
|
|
98 |
|
|
bool GetArg(const char* name, std::vector<uint8_t>& val,
|
99 |
|
|
size_t lmin=0, size_t lmax=uint32_max);
|
100 |
|
|
bool GetArg(const char* name, std::vector<uint16_t>& val,
|
101 |
|
|
size_t lmin=0, size_t lmax=uint32_max);
|
102 |
|
|
|
103 |
|
|
bool Config(const char* name, std::string& val);
|
104 |
|
|
bool Config(const char* name, uint32_t& val,
|
105 |
|
|
uint32_t max=uint32_max, uint32_t min=0);
|
106 |
|
|
|
107 |
|
|
bool NextOpt(std::string& val);
|
108 |
22 |
wfjm |
bool NextOpt(std::string& val, const RtclNameSet& optset);
|
109 |
|
|
int NextSubOpt(std::string& val, const RtclNameSet& optset);
|
110 |
10 |
wfjm |
bool OptValid() const;
|
111 |
|
|
|
112 |
19 |
wfjm |
Tcl_Obj* CurrentArg() const;
|
113 |
|
|
|
114 |
10 |
wfjm |
bool AllDone();
|
115 |
|
|
size_t NDone() const;
|
116 |
|
|
size_t NOptMiss() const;
|
117 |
|
|
|
118 |
|
|
const char* PeekArgString(int rind) const;
|
119 |
|
|
|
120 |
|
|
void SetResult(const std::string& str);
|
121 |
|
|
void SetResult(std::ostringstream& sos);
|
122 |
19 |
wfjm |
void SetResult(bool val);
|
123 |
10 |
wfjm |
void SetResult(int val);
|
124 |
|
|
void SetResult(double val);
|
125 |
|
|
void SetResult(Tcl_Obj* pobj);
|
126 |
|
|
|
127 |
|
|
void AppendResult(const char* str, ...);
|
128 |
|
|
void AppendResult(const std::string& str);
|
129 |
|
|
void AppendResult(std::ostringstream& sos);
|
130 |
|
|
void AppendResultLines(const std::string& str);
|
131 |
|
|
void AppendResultLines(std::ostringstream& sos);
|
132 |
|
|
|
133 |
19 |
wfjm |
int Quit(const std::string& str);
|
134 |
|
|
|
135 |
10 |
wfjm |
Tcl_Obj* operator[](size_t ind) const;
|
136 |
|
|
|
137 |
|
|
protected:
|
138 |
|
|
bool NextArg(const char* name, Tcl_Obj*& pobj);
|
139 |
|
|
bool NextArgList(const char* name, int& objc,
|
140 |
|
|
Tcl_Obj**& objv, size_t lmin=0,
|
141 |
|
|
size_t lmax=uint32_max);
|
142 |
|
|
void ConfigNameCheck(const char* name);
|
143 |
|
|
bool ConfigReadCheck();
|
144 |
|
|
|
145 |
|
|
protected:
|
146 |
|
|
Tcl_Interp* fpInterp; //!< pointer to tcl interpreter
|
147 |
|
|
size_t fObjc; //!< original args count
|
148 |
|
|
Tcl_Obj* const * fObjv; //!< original args vector
|
149 |
|
|
size_t fNDone; //!< number of processed args
|
150 |
|
|
size_t fNOptMiss; //!< number of missed optional args
|
151 |
|
|
size_t fNConfigRead; //!< number of read mode config's
|
152 |
|
|
bool fOptErr; //!< option processing error flag
|
153 |
|
|
bool fArgErr; //!< argument processing error flag
|
154 |
|
|
|
155 |
|
|
};
|
156 |
|
|
|
157 |
|
|
} // end namespace Retro
|
158 |
|
|
|
159 |
|
|
#include "RtclArgs.ipp"
|
160 |
|
|
|
161 |
|
|
#endif
|