mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-21 23:00:45 +01:00
[poincare] Add a shortcut constructor in Hierarchy
Change-Id: I2b0de8ab43ae6a0503814a48a20991b4c92572ea
This commit is contained in:
@@ -10,6 +10,8 @@ class DynamicHierarchy : public Hierarchy {
|
||||
public:
|
||||
DynamicHierarchy();
|
||||
DynamicHierarchy(const Expression * const * operands, int numberOfOperands, bool cloneOperands = true);
|
||||
DynamicHierarchy(const Expression * operand1, const Expression * operand2, bool cloneOperands = true) :
|
||||
DynamicHierarchy(ExpressionArray(operand1, operand2), 2, cloneOperands) {}
|
||||
~DynamicHierarchy();
|
||||
DynamicHierarchy(const DynamicHierarchy & other) = delete;
|
||||
DynamicHierarchy(DynamicHierarchy && other) = delete;
|
||||
|
||||
@@ -14,6 +14,8 @@ public:
|
||||
void detachOperand(const Expression * e); // Removes an operand WITHOUT deleting it
|
||||
void detachOperands(); // Removes all operands WITHOUT deleting them
|
||||
virtual const Expression * const * operands() const = 0;
|
||||
protected:
|
||||
static const Expression * const * ExpressionArray(const Expression * e1, const Expression * e2);
|
||||
private:
|
||||
void detachOperandAtIndex(int i);
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ class StaticHierarchy : public Hierarchy {
|
||||
public:
|
||||
StaticHierarchy();
|
||||
StaticHierarchy(const Expression * const * operands, bool cloneOperands = true);
|
||||
StaticHierarchy(const Expression * expression1, const Expression * expression2, bool cloneOperands = true); // Specialized constructor for StaticHierarchy<2>
|
||||
~StaticHierarchy();
|
||||
StaticHierarchy(const StaticHierarchy & other) = delete;
|
||||
StaticHierarchy(StaticHierarchy && other) = delete;
|
||||
|
||||
@@ -59,6 +59,13 @@ void Hierarchy::replaceOperand(const Expression * oldOperand, Expression * newOp
|
||||
}
|
||||
}
|
||||
|
||||
const Expression * const * Hierarchy::ExpressionArray(const Expression * e1, const Expression * e2) {
|
||||
static const Expression * result[2] = {nullptr, nullptr};
|
||||
result[0] = e1;
|
||||
result[1] = e2;
|
||||
return result;
|
||||
}
|
||||
|
||||
void Hierarchy::detachOperandAtIndex(int i) {
|
||||
Expression ** op = const_cast<Expression **>(operands());
|
||||
// When detachOperands is called, it's very likely that said operands have been stolen
|
||||
|
||||
@@ -19,6 +19,12 @@ StaticHierarchy<T>::StaticHierarchy(const Expression * const * operands, bool cl
|
||||
build(operands, T, cloneOperands);
|
||||
}
|
||||
|
||||
template<>
|
||||
StaticHierarchy<2>::StaticHierarchy(const Expression * e1, const Expression * e2, bool cloneOperands) :
|
||||
StaticHierarchy(ExpressionArray(e1, e2), cloneOperands)
|
||||
{
|
||||
}
|
||||
|
||||
template<int T>
|
||||
StaticHierarchy<T>::~StaticHierarchy() {
|
||||
for (int i = 0; i < T; i++) {
|
||||
|
||||
Reference in New Issue
Block a user