Initial circuits plugin work.
This commit is contained in:
parent
b5f21900eb
commit
f8a2ce3c59
50 changed files with 1451 additions and 97 deletions
13
plugins/circuits/src/gates/BasicLogicGates.cpp
Normal file
13
plugins/circuits/src/gates/BasicLogicGates.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "BasicLogicGates.h"
|
||||
|
||||
AndLogicGate::AndLogicGate(Wire* input0, Wire* input1, Wire* output)
|
||||
: TwoInOneOutLogicGate(input0, input1, output)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
OrLogicGate::OrLogicGate(Wire* input0, Wire* input1, Wire* output)
|
||||
: TwoInOneOutLogicGate(input0, input1, output)
|
||||
{
|
||||
|
||||
}
|
45
plugins/circuits/src/gates/BasicLogicGates.h
Normal file
45
plugins/circuits/src/gates/BasicLogicGates.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include "LogicGate.h"
|
||||
|
||||
class AndLogicGate : public TwoInOneOutLogicGate
|
||||
{
|
||||
public:
|
||||
AndLogicGate(Wire* input0 = nullptr, Wire* input1 = nullptr, Wire* output = nullptr);
|
||||
|
||||
virtual ~AndLogicGate() = default;
|
||||
|
||||
const TruthTable& getTruthTable()
|
||||
{
|
||||
return mTable;
|
||||
}
|
||||
|
||||
GateType getGateType() const
|
||||
{
|
||||
return GateType::AND;
|
||||
}
|
||||
|
||||
private:
|
||||
TruthTable mTable{ TruthTable(2, 1) };
|
||||
};
|
||||
|
||||
class OrLogicGate : public TwoInOneOutLogicGate
|
||||
{
|
||||
public:
|
||||
OrLogicGate(Wire* input0 = nullptr, Wire* input1 = nullptr, Wire* output = nullptr);
|
||||
|
||||
virtual ~OrLogicGate() = default;
|
||||
|
||||
const TruthTable& getTruthTable()
|
||||
{
|
||||
return mTable;
|
||||
}
|
||||
|
||||
GateType getGateType() const
|
||||
{
|
||||
return GateType::OR;
|
||||
}
|
||||
|
||||
private:
|
||||
TruthTable mTable{ TruthTable(2, 1) };
|
||||
};
|
96
plugins/circuits/src/gates/LogicGate.cpp
Normal file
96
plugins/circuits/src/gates/LogicGate.cpp
Normal file
|
@ -0,0 +1,96 @@
|
|||
#include "LogicGate.h"
|
||||
|
||||
NInMOutLogicGate::NInMOutLogicGate(std::size_t numIn, std::size_t numOut, std::vector<Wire*> inputs, std::vector<Wire*> outputs)
|
||||
: LogicGate(),
|
||||
mNumIn(numIn),
|
||||
mNumOut(numOut)
|
||||
{
|
||||
if (inputs.size() == mNumIn)
|
||||
{
|
||||
mInputs = inputs;
|
||||
}
|
||||
else
|
||||
{
|
||||
mInputs = std::vector<Wire*>(numIn, nullptr);
|
||||
}
|
||||
|
||||
if (outputs.size() == mNumOut)
|
||||
{
|
||||
mOutputs = outputs;
|
||||
}
|
||||
else
|
||||
{
|
||||
mOutputs = std::vector<Wire*>(numOut, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t NInMOutLogicGate::getNumInputs() const
|
||||
{
|
||||
return mNumIn;
|
||||
}
|
||||
|
||||
std::size_t NInMOutLogicGate::getNumOutputputs() const
|
||||
{
|
||||
return mNumOut;
|
||||
}
|
||||
|
||||
Wire* NInMOutLogicGate::getInput(std::size_t idx) const
|
||||
{
|
||||
if (idx < mNumIn)
|
||||
{
|
||||
return mInputs[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Wire* NInMOutLogicGate::getOutput(std::size_t idx) const
|
||||
{
|
||||
if (idx < mNumOut)
|
||||
{
|
||||
return mOutputs[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NInMOutLogicGate::setAtInput(std::size_t idx, Wire* value)
|
||||
{
|
||||
if (idx < mInputs.size())
|
||||
{
|
||||
mInputs[idx] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void NInMOutLogicGate::setAtOutput(std::size_t idx, Wire* value)
|
||||
{
|
||||
if (idx < mOutputs.size())
|
||||
{
|
||||
mOutputs[idx] = value;
|
||||
}
|
||||
}
|
||||
|
||||
TwoInOneOutLogicGate::TwoInOneOutLogicGate(Wire* input0, Wire* input1, Wire* output)
|
||||
: NInMOutLogicGate(2, 1, { input0, input1 }, {output})
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TwoInOneOutLogicGate::setInput0(Wire* input)
|
||||
{
|
||||
setAtInput(0, input);
|
||||
}
|
||||
|
||||
void TwoInOneOutLogicGate::setInput1(Wire* input)
|
||||
{
|
||||
setAtInput(1, input);
|
||||
}
|
||||
|
||||
void TwoInOneOutLogicGate::setOutput(Wire* output)
|
||||
{
|
||||
setAtOutput(0, output);
|
||||
}
|
78
plugins/circuits/src/gates/LogicGate.h
Normal file
78
plugins/circuits/src/gates/LogicGate.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
#pragma once
|
||||
|
||||
#include "CircuitElement.h"
|
||||
#include "TruthTable.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class LogicGate : public CircuitElement
|
||||
{
|
||||
public:
|
||||
enum class GateType
|
||||
{
|
||||
NOT,
|
||||
AND,
|
||||
OR,
|
||||
XOR,
|
||||
UNKNOWN
|
||||
};
|
||||
virtual ~LogicGate() = default;
|
||||
|
||||
virtual std::size_t getNumInputs() const = 0;
|
||||
|
||||
virtual std::size_t getNumOutputputs() const = 0;
|
||||
|
||||
virtual Wire* getInput(std::size_t idx) const = 0;
|
||||
|
||||
virtual Wire* getOutput(std::size_t idx) const = 0;
|
||||
|
||||
virtual const TruthTable& getTruthTable() = 0;
|
||||
|
||||
virtual GateType getGateType() const = 0;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::LOGIC_GATE;
|
||||
}
|
||||
};
|
||||
|
||||
class NInMOutLogicGate : public LogicGate
|
||||
{
|
||||
public:
|
||||
NInMOutLogicGate(std::size_t numIn, std::size_t numOut, std::vector<Wire*> inputs = {}, std::vector<Wire*> outputs = {});
|
||||
|
||||
virtual ~NInMOutLogicGate() = default;
|
||||
|
||||
std::size_t getNumInputs() const override;
|
||||
|
||||
std::size_t getNumOutputputs() const override;
|
||||
|
||||
Wire* getInput(std::size_t idx) const override;
|
||||
|
||||
Wire* getOutput(std::size_t idx) const override;
|
||||
|
||||
void setAtInput(std::size_t idx, Wire* value);
|
||||
|
||||
void setAtOutput(std::size_t idx, Wire* value);
|
||||
|
||||
private:
|
||||
std::size_t mNumIn{ 1 };
|
||||
std::size_t mNumOut{ 1 };
|
||||
|
||||
std::vector<Wire*> mInputs;
|
||||
std::vector<Wire*> mOutputs;
|
||||
};
|
||||
|
||||
class TwoInOneOutLogicGate : public NInMOutLogicGate
|
||||
{
|
||||
public:
|
||||
TwoInOneOutLogicGate(Wire* input0 = nullptr, Wire* input1 = nullptr, Wire* output = nullptr);
|
||||
|
||||
void setInput0(Wire* input);
|
||||
|
||||
void setInput1(Wire* input);
|
||||
|
||||
void setOutput(Wire* output);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue