2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
22 * get value for matching keyword
24 //testing=script 2006.07.17
26 /*--------------------------------------------------------------------------*/
27 /* special version of "get" for "bool"
28 * so "nofoo" works as an equivalent to foo=false
30 bool Get(CS
& cmd
, const std::string
& key
, bool* val
)
32 if (cmd
.umatch(key
+ ' ')) {
33 if (cmd
.skip1b('=')) {
39 }else if (cmd
.umatch("no" + key
)) {
46 /*--------------------------------------------------------------------------*/
48 bool _Get_int(CS
& cmd
, const std::string
& key
, T
* val
, AP_MOD mod
, T scale
)
50 if (cmd
.umatch(key
+ " {=}")) {
52 case mNONE
: *val
= T(cmd
.ctof()); break;
53 case mSCALE
: untested(); *val
= T(T(cmd
.ctof())*scale
); break;
54 case mOFFSET
: untested(); *val
= T(T(cmd
.ctof())+scale
); break;
55 case mINVERT
: untested(); *val
= T(1 / T(cmd
.ctof())); break;
56 case mPOSITIVE
: untested(); *val
= T(std::abs(T(cmd
.ctof()))); break;
57 case mOCTAL
: *val
= T(cmd
.ctoo()); break;
58 case mHEX
: untested(); *val
= T(cmd
.ctox()); break;
65 /*--------------------------------------------------------------------------*/
66 bool Get(CS
& cmd
, const std::string
& key
, short int* val
, AP_MOD mod
, short int scale
)
68 return _Get_int(cmd
, key
, val
, mod
, scale
);
70 /*--------------------------------------------------------------------------*/
71 bool Get(CS
& cmd
, const std::string
& key
, int* val
, AP_MOD mod
, int scale
)
73 return _Get_int(cmd
, key
, val
, mod
, scale
);
75 /*--------------------------------------------------------------------------*/
76 bool Get(CS
& cmd
, const std::string
& key
, unsigned* val
, AP_MOD mod
, unsigned scale
)
78 return _Get_int(cmd
, key
, val
, mod
, scale
);
80 /*--------------------------------------------------------------------------*/
82 bool Get(CS
& cmd
, const std::string
& key
, int* val
, AP_MOD mod
, int scale
)
84 if (cmd
.umatch(key
+ " {=}")) {
86 case mNONE
: *val
= int(cmd
.ctof()); break;
87 case mSCALE
: untested(); *val
= int(cmd
.ctof())*scale
; break;
88 case mOFFSET
: untested(); *val
= int(cmd
.ctof())+scale
; break;
89 case mINVERT
: untested(); *val
= 1 / int(cmd
.ctof()); break;
90 case mPOSITIVE
: untested(); *val
= std::abs(int(cmd
.ctof())); break;
91 case mOCTAL
: *val
= cmd
.ctoo(); break;
92 case mHEX
: untested(); *val
= cmd
.ctox(); break;
100 /*--------------------------------------------------------------------------*/
101 bool Get(CS
& cmd
, const std::string
& key
, double* val
, AP_MOD mod
, double scale
)
103 if (cmd
.umatch(key
+ " {=}")) {
105 case mNONE
: untested(); *val
= cmd
.ctof(); break;
106 case mSCALE
: untested(); *val
= cmd
.ctof()*scale
; break;
107 case mOFFSET
: *val
= cmd
.ctof()+scale
; break;
108 case mINVERT
: untested(); *val
= 1 / cmd
.ctof(); break;
109 case mPOSITIVE
: *val
= std::abs(cmd
.ctof());
110 trace1(("Get " + std::string((cmd
.fullstring()))).c_str(), *val
);
112 case mOCTAL
: untested(); *val
= cmd
.ctoo(); break;
113 case mHEX
: untested(); *val
= cmd
.ctox(); break;
120 /*--------------------------------------------------------------------------*/
121 /*--------------------------------------------------------------------------*/
122 // vim:ts=8:sw=2:noet: