本文整理汇总了C++中Switch::outPin方法的典型用法代码示例。如果您正苦于以下问题:C++ Switch::outPin方法的具体用法?C++ Switch::outPin怎么用?C++ Switch::outPin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Switch
的用法示例。
在下文中一共展示了Switch::outPin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spanResetWires
void spanResetWires(Pin* source){
if (source == NULL) return;
if (source->visited()) return;
source->visited(true);
Wire *wire = source->wire();
if (!wire) return;
//cout <<"spanResetWires wire: "<< wire->info()<<endl;
wire->voltage(false);
list<Pin *>pins = wire->pins();
list<Pin *>::iterator it;
for (it = pins.begin(); it != pins.end(); it++){
Pin *pin = (*it);
if (pin == source) continue;
pin->visited(true);
Element *element = pin->element();
if (element->type() == "switch"){
Switch *switc = (Switch *)element;
Pin *nextPin = switc->outPin(pin);
spanResetWires(nextPin);
}
else if (element->type() == "resistor"){
Resistor *resistor = (Resistor *)element;
Pin *nextPin = resistor->outPin(pin);
spanResetWires(nextPin);
}
else if (element->type() == "bridge"){
Bridge *bridge = (Bridge *)element;
Pin *nextPin = bridge->outPin(pin);
spanResetWires(nextPin);
}
}
}
示例2: spanResistors
//void spanResistors(Pin *source, list<Wire *>wires){
void spanResistors(Pin *source, list<Resistor *>resistors){
//cout <<"entering spanResistors"<<endl;
/* 1. try to reach the end.
* 2. if end is reached, must go back and turn all wires on in the path
*/
if (source == NULL) return;
if (source->visited()) return;
source->visited(true);
//debug("spanResistors source pin: "<< source->fullName());
Wire *wire = source->wire();
if (!wire) return;
//debug("spanResistors wire: "<< wire->name());
list<Pin *>pins = wire->pins();
list<Pin *>::iterator it;
for (it = pins.begin(); it != pins.end(); it++){
Pin *pin = (*it);
if (pin == source) continue;
pin->visited(true);
//get element for source
Element *element = pin->element();
if (element->type() == "source"){
//cerr << "Encountered source "<< element->info() <<" while completing circuit."<<endl;
return;
}
else if (element->type() == "ground"){
//cout <<"ground reached: "<<endl;
//end reached.
activateResistors(resistors);
//upWires(wires);
}
else if (element->type() == "switch"){
Switch *switc = (Switch *)element;
if (!switc->isOn()) continue;
Pin *nextPin = switc->outPin(pin);
spanResistors(nextPin,resistors);
}
else if (element->type() == "resistor"){
Resistor *resistor = (Resistor *)element;
resistors.push_back(resistor);
Pin *nextPin = resistor->outPin(pin);
spanResistors(nextPin, resistors);
}
else if (element->type() == "bridge"){
Bridge *bridge = (Bridge *)element;
Pin *nextPin = bridge->outPin(pin);
spanResistors(nextPin, resistors);
}
}
}
示例3: spanVoltage
int spanVoltage(Pin* source, bool voltage){
if (source == NULL) return 0;
if (source->visited()) return 0;
source->visited(true);
Wire *wire = source->wire();
if (!wire) {
return 0; //have separate audit if you want to check connectivity
cerr << "source has no wire. source: " << source->name() <<endl;
return 20;
}
/*
if (wire->visited()){
bool wireVoltage = wire->voltage();
if (wireVoltage != voltage){
cerr << "inconsistent voltage found while updating voltages on wire: " << wire->info() <<endl;
return 21;
}
return 0;
}*/
//cout <<"spanVoltage setting wire: "<< wire->info()<< " to voltage: "<<voltage<<endl;
wire->voltage(voltage);
list<Pin *>pins = wire->pins();
list<Pin *>::iterator it;
for (it = pins.begin(); it != pins.end(); it++){
Pin *pin = (*it);
//cout <<"spanvoltage pin name: "<<pin->name()<<endl;
if (pin == source) continue;
pin->visited(true);
Element *element = pin->element();
if (element->type() == "source"){
Source *source = (Source *)element;
//warning?
}
else if(element->type() == "ground"){
bool gv = pin->wire()->voltage();
if (gv){
cerr << "error: voltage at ground is high. " << pin->wire()->info()<<endl;
return 24;
}
}
else if (element->type() == "switch"){
Switch *switc = (Switch *)element;
if (!switc->isOn()) continue;
Pin *nextPin = switc->outPin(pin);
int rVal = spanVoltage(nextPin, voltage);
if (rVal != 0) return rVal;
}
else if (element->type() == "resistor"){
Resistor *resistor = (Resistor *)element;
Pin *nextPin = resistor->outPin(pin);
bool nextVoltage = voltage;
if (resistor->isActive()) nextVoltage = false;
int rVal = spanVoltage(nextPin, nextVoltage);
if (rVal != 0) return rVal;
}
else if (element->type() == "bridge"){
Bridge *bridge = (Bridge *)element;
Pin *nextPin = bridge->outPin(pin);
int rVal = spanVoltage(nextPin, voltage);
if (rVal != 0) return rVal;
}
}
return 0;
}