Merge branch 'testing-uf' into master-uf
[gnucap-felix.git] / lib / ap_get.cc
blobfbf8af34f585621d777e3c7565b2dd69f916d42c
1 /* -*- C++ -*-
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)
10 * any later version.
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
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
22 * get value for matching keyword
24 //testing=script 2006.07.17
25 #include "ap.h"
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('=')) {
34 cmd >> *val;
35 }else{
36 *val = true;
38 return true;
39 }else if (cmd.umatch("no" + key)) {
40 *val = false;
41 return true;
42 }else{
43 return false;
46 /*--------------------------------------------------------------------------*/
47 template<class T>
48 bool _Get_int(CS& cmd, const std::string& key, T* val, AP_MOD mod, T scale)
50 if (cmd.umatch(key + " {=}")) {
51 switch(mod) {
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;
60 return true;
61 }else{
62 return false;
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 /*--------------------------------------------------------------------------*/
81 #if 0
82 bool Get(CS& cmd, const std::string& key, int* val, AP_MOD mod, int scale)
84 if (cmd.umatch(key + " {=}")) {
85 switch(mod) {
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;
94 return true;
95 }else{
96 return false;
99 #endif
100 /*--------------------------------------------------------------------------*/
101 bool Get(CS& cmd, const std::string& key, double* val, AP_MOD mod, double scale)
103 if (cmd.umatch(key + " {=}")) {
104 switch(mod) {
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 );
111 break;
112 case mOCTAL: untested(); *val = cmd.ctoo(); break;
113 case mHEX: untested(); *val = cmd.ctox(); break;
115 return true;
116 }else{
117 return false;
120 /*--------------------------------------------------------------------------*/
121 /*--------------------------------------------------------------------------*/
122 // vim:ts=8:sw=2:noet: