viminfo
[gnucap-felix.git] / apps / bm_complex.cc
blob0f2d46b3a35dbcc5e2d08c70c8660897c55a74c9
1 /*$Id: bm_complex.cc,v 26.137 2010/04/10 02:37:05 al Exp $ -*- 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 * behavioral modeling complex value
23 * used with tc, etc, and conditionals
25 //testing=script 2006.07.13
26 #include "globals.h"
27 #include "e_elemnt.h"
28 #include "bm.h"
29 /*--------------------------------------------------------------------------*/
30 namespace {
31 /*--------------------------------------------------------------------------*/
32 class EVAL_BM_COMPLEX : public EVAL_BM_ACTION_BASE {
33 private:
34 COMPLEX _value;
35 explicit EVAL_BM_COMPLEX(const EVAL_BM_COMPLEX& p);
36 public:
37 explicit EVAL_BM_COMPLEX(int c=0);
38 ~EVAL_BM_COMPLEX() {}
39 private: // override virtual
40 bool operator==(const COMMON_COMPONENT&)const;
41 COMMON_COMPONENT* clone()const {return new EVAL_BM_COMPLEX(*this);}
42 void print_common_obsolete_callback(OMSTREAM&, LANGUAGE*)const;
43 void tr_eval(ELEMENT*)const;
44 void ac_eval(ELEMENT*)const;
45 std::string name()const {return "complex";}
46 bool ac_too()const {untested();return true;}
47 bool parse_numlist(CS&);
49 /*--------------------------------------------------------------------------*/
50 /*--------------------------------------------------------------------------*/
51 EVAL_BM_COMPLEX::EVAL_BM_COMPLEX(int c)
52 :EVAL_BM_ACTION_BASE(c),
53 _value(NOT_INPUT)
56 /*--------------------------------------------------------------------------*/
57 EVAL_BM_COMPLEX::EVAL_BM_COMPLEX(const EVAL_BM_COMPLEX& p)
58 :EVAL_BM_ACTION_BASE(p),
59 _value(p._value)
62 /*--------------------------------------------------------------------------*/
63 bool EVAL_BM_COMPLEX::operator==(const COMMON_COMPONENT& x)const
65 const EVAL_BM_COMPLEX* p = dynamic_cast<const EVAL_BM_COMPLEX*>(&x);
66 bool rv = p
67 && _value == p->_value
68 && EVAL_BM_ACTION_BASE::operator==(x);
69 if (rv) {
70 untested();
72 return rv;
74 /*--------------------------------------------------------------------------*/
75 void EVAL_BM_COMPLEX::print_common_obsolete_callback(OMSTREAM& o, LANGUAGE* lang)const
77 assert(lang);
78 o << name() << '('
79 << _value.real() << ',' << _value.imag() << ')';
80 EVAL_BM_ACTION_BASE::print_common_obsolete_callback(o, lang);
82 /*--------------------------------------------------------------------------*/
83 void EVAL_BM_COMPLEX::tr_eval(ELEMENT* d)const
85 tr_finish_tdv(d, _value.real());
87 /*--------------------------------------------------------------------------*/
88 void EVAL_BM_COMPLEX::ac_eval(ELEMENT* d)const
90 d->_ev = _value;
91 ac_final_adjust_with_temp(&(d->_ev));
93 /*--------------------------------------------------------------------------*/
94 bool EVAL_BM_COMPLEX::parse_numlist(CS& cmd)
96 unsigned here = cmd.cursor();
97 double real = NOT_VALID;
98 double imag = 0.;
99 cmd >> real >> imag;
100 if (cmd.gotit(here)) {
101 _value = COMPLEX(real,imag);
102 return true;
103 }else{
104 untested();
105 return false;
108 /*--------------------------------------------------------------------------*/
109 /*--------------------------------------------------------------------------*/
110 EVAL_BM_COMPLEX p1(CC_STATIC);
111 DISPATCHER<COMMON_COMPONENT>::INSTALL d1(&bm_dispatcher, "complex", &p1);
113 /*--------------------------------------------------------------------------*/
114 /*--------------------------------------------------------------------------*/
115 // vim:ts=8:sw=2:noet: