aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Circuit.h16
-rw-r--r--Exception.h16
-rw-r--r--GateNot.h1
-rw-r--r--Node.h6
-rw-r--r--NodeFactory.h7
-rw-r--r--NodeInput.h1
-rw-r--r--NodeOutput.h1
-rw-r--r--NodeOutputVisitor.h2
-rw-r--r--Parser.h3
-rw-r--r--docs/class-diag.puml22
-rw-r--r--readme.md6
11 files changed, 49 insertions, 32 deletions
diff --git a/Circuit.h b/Circuit.h
index 6819a6f..05fae49 100644
--- a/Circuit.h
+++ b/Circuit.h
@@ -18,18 +18,20 @@ public:
virtual ~Circuit();
public:
- //! Auto-magically creates either a new node or net
+ //! create a new node or net
virtual void create(string label, vector<string> nodes);
- //! Create new node (internal function)
- virtual void new_node(string label, string type);
- //! Create new net (internal function)
- virtual void new_net(string src, vector<string> dests);
- //! Simulate the circuit
+ //! simulate the circuit
virtual void sim();
- //! Get simulation results (probe measure values)
+ //! get simulation results as formatted string (probe measure values)
virtual string result();
private:
+ //! specifically create new node
+ virtual void new_node(string label, string type);
+ //! specifically create a new net
+ virtual void new_net(string src, vector<string> dests);
+
+private:
std::map<string, Node *> nodes = {};
vector<Net *> nets = {};
diff --git a/Exception.h b/Exception.h
index ab9cfce..5c84aad 100644
--- a/Exception.h
+++ b/Exception.h
@@ -7,32 +7,42 @@
class Exception : public std::exception {
public:
+ //! create an exception using printf-syntax
Exception(const char * fmt, ...);
virtual ~Exception();
+ //! get the formatted string
virtual const char * what();
protected:
Exception() = default;
+ //! internal variadic argument format handling
void va_format(va_list args, const char * fmt);
+ //! pointer to string returned by \p what()
char * error = NULL;
};
class ParserException : public Exception {
-public:
using Exception::Exception;
+
+public:
+ //! create an exception related to file format parsing
ParserException(const char * fmt, ...);
};
class CircuitException : public Exception {
-public:
using Exception::Exception;
+
+public:
+ //! create an exception related to the Circuit
CircuitException(const char * fmt, ...);
Node * node = nullptr;
};
class NodeException : public CircuitException {
-public:
using CircuitException::CircuitException;
+
+public:
+ //! create an exception related to a specific node in a Circuit
NodeException(Node * node, const char * fmt, ...);
};
diff --git a/GateNot.h b/GateNot.h
index 0f79a0d..b87f598 100644
--- a/GateNot.h
+++ b/GateNot.h
@@ -6,6 +6,7 @@ class GateNot : public Node {
using Node::Node;
public:
+ // \note max_inputs is overwritten here
GateNot();
virtual ~GateNot() = default;
virtual GateNot * clone() const;
diff --git a/Node.h b/Node.h
index 34e1895..3cc166e 100644
--- a/Node.h
+++ b/Node.h
@@ -19,13 +19,15 @@ public:
public:
//! alias to \p sim() for Observer
void update();
+ //! add input to node
virtual void addInput(Net *);
+ //! set output net
virtual void setOutput(Net *);
- //! validate and simulate
+ //! simulate node behavior (calculate new level and notify outputs)
virtual void sim();
public:
- //! logical implementation of the node/gate
+ //! calculate the new logic level
virtual SignalLevel level() = 0;
protected:
diff --git a/NodeFactory.h b/NodeFactory.h
index 3c8c4f4..484ed03 100644
--- a/NodeFactory.h
+++ b/NodeFactory.h
@@ -15,14 +15,21 @@ public:
virtual ~NodeFactory() = default;
public:
+ //! check if there is a node with type \p type
static bool has_type(const char * type);
+ //! check if there is a node with type \p type
static bool has_type(string type);
+ //! create a node with type \p type
static Node * create(string type);
private:
+ //! register a node with a type into the factory map
static void assign(const char * type, const Node * node);
+ //! retrieve the factory map
static NodeFactoryMap & get_map();
+ //! convert the type string for case insensitive matching
static string normalize_type(string type);
+ //! find a Node prototype by \p type
static const Node * find_type(string type);
private:
diff --git a/NodeInput.h b/NodeInput.h
index 4317e0c..074e400 100644
--- a/NodeInput.h
+++ b/NodeInput.h
@@ -9,6 +9,7 @@ public:
NodeInput();
~NodeInput() = default;
+ //! override: throw exception
virtual void addInput(Net *);
};
diff --git a/NodeOutput.h b/NodeOutput.h
index 8b3eb44..9110e93 100644
--- a/NodeOutput.h
+++ b/NodeOutput.h
@@ -11,6 +11,7 @@ public:
virtual NodeOutput * clone() const;
virtual void sim();
+ //! override: throw exception
virtual void setOutput(Net *);
public:
diff --git a/NodeOutputVisitor.h b/NodeOutputVisitor.h
index 710711c..d1abca4 100644
--- a/NodeOutputVisitor.h
+++ b/NodeOutputVisitor.h
@@ -11,7 +11,9 @@ public:
virtual void visit(Node & node);
virtual void visit(NodeOutput & node);
+ //! is the visited node a NodeOutput?
bool output_node = false;
+ //! input[0] level of NodeOutput
SignalLevel level = UNDEFINED;
};
diff --git a/Parser.h b/Parser.h
index 221e14e..3480fc9 100644
--- a/Parser.h
+++ b/Parser.h
@@ -15,7 +15,9 @@ public:
Parser(Circuit & circuit);
virtual ~Parser() = default;
+ //! parse from std::string
void parse(string input);
+ //! parse from std::istream
void parse(istream & input);
/**
@@ -25,6 +27,7 @@ public:
*/
static size_t filter(char * input);
+ //! inject Circuit instance
void set_circuit(Circuit & circuit);
private:
diff --git a/docs/class-diag.puml b/docs/class-diag.puml
index 6d338c8..d634c32 100644
--- a/docs/class-diag.puml
+++ b/docs/class-diag.puml
@@ -44,38 +44,33 @@ interface Observer {
}
class GateAnd {
- GateAnd()
clone() : GateAnd*
- #level() : SignalLevel
+ level() : SignalLevel
}
class GateNand {
clone() : GateNand*
- #level() : SignalLevel
+ level() : SignalLevel
}
class GateNor {
clone() : GateNor*
- #level() : SignalLevel
+ level() : SignalLevel
}
class GateNot {
- GateNot()
- GateNot(const GateNot* prototype)
clone() : GateNot*
+ level() : SignalLevel
}
class GateOr {
- GateOr()
- GateOr(const GateOr* prototype)
clone() : GateOr*
- #level() : SignalLevel
+ level() : SignalLevel
}
class GateXor {
- GateXor()
- GateXor(const GateXor* prototype)
clone() : GateXor*
+ level() : SignalLevel
}
class NodeInput {
@@ -91,17 +86,16 @@ enum SignalLevel {
class NodeInputLow {
clone() : NodeInputLow*
- #level() : SignalLevel
+ level() : SignalLevel
}
class NodeInputHigh {
clone() : NodeInputHigh*
- #level() : SignalLevel
+ level() : SignalLevel
}
class NodeOutput {
NodeOutput()
- NodeOutput(const NodeOutput* prototype)
clone() : NodeOutput*
level() : SignalLevel
accept(NodeVisitor& visitor) : void
diff --git a/readme.md b/readme.md
index f65826d..e77bbfc 100644
--- a/readme.md
+++ b/readme.md
@@ -13,9 +13,3 @@ make
- Dependency injection
- vast meer!
-## TODO
-
-- is de scope (public/private/protected) van alle members lekker
- consistent?
-- klassendiagram
-