mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 17:20:53 +01:00
[poincare] Add Hierarchy::detachOperand to detach a single operand
This commit is contained in:
@@ -11,8 +11,11 @@ public:
|
||||
const Expression * operand(int i) const override;
|
||||
void swapOperands(int i, int j) override;
|
||||
void replaceOperand(const Expression * oldOperand, Expression * newOperand, bool deleteOldOperand = true) override;
|
||||
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;
|
||||
private:
|
||||
void detachOperandAtIndex(int i);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -21,14 +21,17 @@ void Hierarchy::swapOperands(int i, int j) {
|
||||
op[j] = temp;
|
||||
}
|
||||
|
||||
void Hierarchy::detachOperands() {
|
||||
Expression ** op = const_cast<Expression **>(operands());
|
||||
void Hierarchy::detachOperand(const Expression * e) {
|
||||
for (int i=0; i<numberOfOperands(); i++) {
|
||||
// When detachOperands is called, it's very likely that said operands have been stolen
|
||||
if (op[i]->parent() == this) {
|
||||
const_cast<Expression *>(op[i])->setParent(nullptr);
|
||||
if (operand(i) == e) {
|
||||
detachOperandAtIndex(i);
|
||||
}
|
||||
op[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Hierarchy::detachOperands() {
|
||||
for (int i=0; i<numberOfOperands(); i++) {
|
||||
detachOperandAtIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +54,13 @@ void Hierarchy::replaceOperand(const Expression * oldOperand, Expression * newOp
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
if (op[i]->parent() == this) {
|
||||
const_cast<Expression *>(op[i])->setParent(nullptr);
|
||||
}
|
||||
op[i] = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user