00001
00025 #ifndef ONEINPUTGATE_H_
00026 #define ONEINPUTGATE_H_
00027
00028 #include <string>
00029
00030 #include <cassert>
00031
00032 #include "Event.h"
00033 #include "LogicGate.h"
00034 #include "LogicFunctions.h"
00035 #include "LogicUpdate.h"
00036 #include "BaseOneInputGate.h"
00037
00041 class OneInputGate: public LogicGate, public BaseOneInputGate {
00042
00043 private:
00044
00049 const OneInputFunc& func;
00050
00051 public:
00061 OneInputGate(size_t id, const OneInputFunc& func, const std::string& outputName, const std::string& inputName, const SimTime& delay)
00062 : LogicGate (id, 1, 1, delay), BaseOneInputGate (outputName, inputName), func (func) {}
00063
00064 OneInputGate (const OneInputGate& that)
00065 : LogicGate (that), BaseOneInputGate (that), func(that.func) {}
00066
00067 virtual OneInputGate* clone () const {
00068 return new OneInputGate (*this);
00069 }
00070
00071
00072
00079 protected:
00080
00084 virtual LogicVal evalOutput () const {
00085 return func (getInputVal());
00086 }
00087
00088 virtual void execEvent (Graph& graph, GNode& myNode, const EventTy& event) {
00089
00090 if (event.getType() == EventTy::NULL_EVENT) {
00091
00092 sendEventsToFanout(graph, myNode, event, EventTy::NULL_EVENT, LogicUpdate ());
00093
00094 } else {
00095
00096 const LogicUpdate& lu = event.getAction();
00097 if (inputName == (lu.getNetName())) {
00098 inputVal = lu.getNetVal();
00099 } else {
00100 LogicGate::netNameMismatch(lu);
00101 }
00102
00103
00104
00105
00106 LogicVal newOutput = evalOutput();
00107 this->outputVal = newOutput;
00108
00109 LogicUpdate drvFanout(outputName, newOutput);
00110
00111 sendEventsToFanout(graph, myNode, event, EventTy::REGULAR_EVENT, drvFanout);
00112
00113 }
00114
00115 }
00116
00117
00118 public:
00125 virtual bool hasInputName(const std::string& net) const {
00126 return BaseOneInputGate::hasInputName (net);
00127 }
00128
00136 virtual bool hasOutputName(const std::string& net) const {
00137 return BaseOneInputGate::hasOutputName (net);
00138 }
00139
00145 virtual const std::string& getOutputName() const {
00146 return BaseOneInputGate::getOutputName ();
00147 }
00148
00149
00153 virtual const std::string getGateName () const {
00154 return func.toString ();
00155 }
00156
00157
00158
00159
00160 virtual size_t getInputIndex(const std::string& net) const {
00161 if (this->inputName == (net)) {
00162 return 0;
00163 }
00164 abort ();
00165 return -1;
00166 }
00167
00171 virtual const std::string toString() const {
00172 std::ostringstream ss;
00173 ss << AbstractSimObject::toString () << getGateName () << ": " << BaseOneInputGate::toString ()
00174 << " delay = " << BaseLogicGate::getDelay ();
00175 return ss.str ();
00176 }
00177
00178
00179
00180 };
00181
00182 #endif