📄 wires.h
字号:
#ifndef _WIRES_H
#define _WIRES_H
#include <iostream>
#include <string>
using namespace std;
#include "tvector.h"
// A wire has current flowing through it.
// When the current changes, a wire notifies
// all the gates listening on the wire that the current
// has changed. The gates act accordingly (see gates.h).
//
// Some of the "gates" are really connectors to other wires.
// A connector allows gates to be strung together, but connectors
// are more like solder than real gates. As such, connectors aren't
// part of a CompositeGate. To facilitate finding a wire's
// connectors, a ConnectorIterator can be used to access all a wire's
// connectors.
class Gate;
class Connector;
class Wire
{
public:
Wire(const string& name="");
virtual ~Wire();
virtual bool GetSignal() const; // true/false, on/off
virtual string tostring() const; // for I/O
virtual void SetSignal(bool signal); // set signal, propagate
virtual void AddGate(Gate * g); // g monitors this wire
virtual void RemoveGate(Gate * g); // g stops monitoring
virtual int Number() const; // which wire is this?
friend class ConnectorIterator; // access myGates
private:
tvector<Gate *> myGates;
bool mySignal;
string myName;
int myNumber;
static int ourCount; // class wide, keeps count
};
ostream& operator << (ostream& out, const Wire& w);
// A WireFactory is used to encapsulate wire creation.
// If wires are "ordered" from the factory, the factory takes
// care of cleaning up the wires when the factory ceases to exist.
// This is a rudimentary factory, there's no facility for clients
// to recycle wires and the factory doesn't clean up the gates
// attached to the wires it destroys.
//
// MakeWire -- creates a new wire
// GetWire -- retrieves an already created wire by the wire's number
class WireFactory
{
public:
WireFactory();
virtual ~WireFactory();
virtual Wire * MakeWire(const string& name="wire"); // create anew
virtual Wire * GetWire(int num) const; // get by number
private:
tvector<Wire *> myWires;
};
// standard tapestry iterator for iterating over all
// connectors attached to a wire
class ConnectorIterator
{
public:
ConnectorIterator(Wire* w);
void Init();
bool HasMore();
void Next();
Connector * Current();
private:
Wire * myWire;
Connector * myConnector;
int myIndex;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -