1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/*$Id: bm_model.cc,v 26.137 2010/04/10 02:37:05 al Exp $ -*- C++ -*-
* Copyright (C) 2001 Albert Davis
* Author: Albert Davis <aldavis@gnu.org>
*
* This file is part of "Gnucap", the Gnu Circuit Analysis Package
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*------------------------------------------------------------------
* behavioral modeling ".model" stub
* accepts an unknown name for later linking to a .model
*/
//testing=script 2006.07.13
#include "globals.h"
#include "e_model.h"
#include "bm.h"
/*--------------------------------------------------------------------------*/
namespace {
/*--------------------------------------------------------------------------*/
class EVAL_BM_MODEL : public EVAL_BM_ACTION_BASE {
private:
std::string _arglist;
COMMON_COMPONENT* _func;
explicit EVAL_BM_MODEL(const EVAL_BM_MODEL& p);
public:
explicit EVAL_BM_MODEL(int c=0);
~EVAL_BM_MODEL() {detach_common(&_func);}
private: // override virtual
bool operator==(const COMMON_COMPONENT&)const override;
COMMON_COMPONENT* clone()const override {return new EVAL_BM_MODEL(*this);}
void parse_common_obsolete_callback(CS&)override;
void print_common_obsolete_callback(OMSTREAM&, LANGUAGE*)const override;
void expand(const COMPONENT*)override;
COMMON_COMPONENT* deflate()override {return (_func) ? _func->deflate() : this;}
void tr_eval(ELEMENT*d)const override{assert(_func); _func->tr_eval(d);}
void ac_eval(ELEMENT*d)const override{assert(_func); _func->ac_eval(d);}
std::string name()const override {itested();return modelname();}
bool ac_too()const override {return true;}
};
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
EVAL_BM_MODEL::EVAL_BM_MODEL(int c)
:EVAL_BM_ACTION_BASE(c),
_arglist(),
_func(0)
{
}
/*--------------------------------------------------------------------------*/
EVAL_BM_MODEL::EVAL_BM_MODEL(const EVAL_BM_MODEL& p)
:EVAL_BM_ACTION_BASE(p),
_arglist(p._arglist),
_func(0)
{
attach_common(p._func, &_func);
}
/*--------------------------------------------------------------------------*/
bool EVAL_BM_MODEL::operator==(const COMMON_COMPONENT& x)const
{
const EVAL_BM_MODEL* p = dynamic_cast<const EVAL_BM_MODEL*>(&x);
bool rv = p
&& _arglist == p->_arglist
&& EVAL_BM_ACTION_BASE::operator==(x);
if (rv) {
incomplete();
untested();
}
return rv;
}
/*--------------------------------------------------------------------------*/
void EVAL_BM_MODEL::parse_common_obsolete_callback(CS& cmd) //used
{
assert(!_func);
assert(!has_model());
parse_modelname(cmd);
_arglist = cmd.ctos("", "(", ")");
assert(!_func);
}
/*--------------------------------------------------------------------------*/
void EVAL_BM_MODEL::print_common_obsolete_callback(OMSTREAM& o, LANGUAGE* lang)const
{
assert(lang);
if (_func) {
_func->print_common_obsolete_callback(o, lang);
}else{
o << modelname();
if (_arglist != "") {
o << "(" << _arglist << ")";
}else{
}
}
}
/*--------------------------------------------------------------------------*/
void EVAL_BM_MODEL::expand(const COMPONENT* d)
{
EVAL_BM_ACTION_BASE::expand(d);
// not sure what kind of model it is yet.
// see what we find.
COMMON_COMPONENT* c = NULL;
try {
attach_model(d);
assert(has_model());
c = dynamic_cast<EVAL_BM_ACTION_BASE*>(model()->new_common());
}catch (Exception& e) {
error(bTRACE, e.message() + "++++\n");
assert(!has_model());
c = bm_dispatcher.clone("eval_bm_value");
}
if (!c) {
throw Exception(d->long_label() + ": model type mismatch");
//BUG// memory leak
}else{
}
// now we have one
// link to the real one
// later, a "deflate" will push it down to proper place.
c->set_modelname(modelname());
CS args(CS::_STRING, _arglist);
c->parse_common_obsolete_callback(args);
c->expand(d);
attach_common(c, &_func);
assert(_func);
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
EVAL_BM_MODEL p1(CC_STATIC);
DISPATCHER<COMMON_COMPONENT>::INSTALL d1(&bm_dispatcher, "eval_bm_model", &p1);
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// vim:ts=8:sw=2:noet:
|