Files
Upsilon/expression_reference.h
2018-06-28 17:59:06 +02:00

50 lines
1.3 KiB
C++

#ifndef EXPRESSION_REFERENCE_H
#define EXPRESSION_REFERENCE_H
#include "tree_reference.h"
#include "expression_node.h"
#include <stdio.h>
template <class T>
class ExpressionReference : public TreeReference<T> {
public:
using TreeReference<T>::TreeReference;
// Allow every ExpressionReference<T> to be transformed into an ExpressionReference<ExpressionNode>, i.e. Expression
operator ExpressionReference<ExpressionNode>() {
return ExpressionReference<ExpressionNode>(this->node());
}
static ExpressionReference<ExpressionNode> failedAllocationRef();
static TreeNode * failedAllocationNode();
void addChild(ExpressionReference<ExpressionNode> e) {
if (!this->node()->isAllocationFailure()) {
TreeReference<T>::addTreeChild(e);
}
}
ExpressionReference<ExpressionNode> childAtIndex(int i) {
return ExpressionReference<ExpressionNode>(TreeReference<T>::treeChildAtIndex(i).node());
}
void replaceChildAtIndex(int oldChildIndex, ExpressionReference<ExpressionNode> newChild) {
TreeReference<T>::replaceChildAtIndex(oldChildIndex, newChild);
}
float approximate() {
return this->castedNode()->approximate();
}
/*
ExpressionReference<ExpressionNode> simplify() {
return node()->simplify();
}
*/
};
typedef ExpressionReference<ExpressionNode> ExpressionRef;
#endif