00001
00011 #ifndef _FunctionTree_h
00012 #define _FunctionTree_h
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "VariableNames.h"
00023
00024
00025
00026
00027
00028 class FunctionTree
00029 {
00030 private:
00032 enum Type { VALUE, VARIABLE_NAME, VARIABLE_INDEX, BINARY, UNARY };
00033
00034 public:
00035
00037 typedef double (*UnaryOperator)(double);
00038
00040 typedef double (*BinaryOperator)(double, double);
00041
00042
00043
00046 FunctionTree(double value);
00047
00050 FunctionTree(const wxString& variableName);
00051
00054 FunctionTree(unsigned variableIndex);
00055
00058 FunctionTree(const UnaryOperator unaryOperator,
00059 std::auto_ptr<const FunctionTree> apOperand);
00060
00063 FunctionTree(const BinaryOperator binaryOperator,
00064 std::auto_ptr<const FunctionTree> apLeftOperand,
00065 std::auto_ptr<const FunctionTree> apRightOperand);
00066
00069 FunctionTree(const FunctionTree& from);
00070
00073 ~FunctionTree(void);
00074
00075
00076
00077
00084 FunctionTree& operator=(const FunctionTree& from);
00085
00086
00087
00096 double Evaluate(const ColumnVector& point,
00097 const VariableNames& variables) const;
00098
00106 std::auto_ptr<const FunctionTree> Optimize(const VariableNames& variables)
00107 const;
00108
00109
00110
00119 void SetArgument(std::auto_ptr<const FunctionTree> apArgument);
00120
00121
00122
00126 bool ContainsUnknown(const VariableNames& variables) const;
00127
00130 VariableNames PresentVariables() const;
00131
00132 protected:
00133
00134 private:
00135
00136
00138 union Data
00139 {
00140 double mValue;
00141 wxString* mpVariableName;
00142 unsigned mVariableIndex;
00143 UnaryOperator mUnaryOperator;
00144 BinaryOperator mBinaryOperator;
00145
00146
00147 Data(double value) : mValue(value) { };
00148 Data(unsigned variableIndex) : mVariableIndex(variableIndex) { };
00149 Data(wxString* pVariableName) : mpVariableName(pVariableName) { };
00150 Data(UnaryOperator unaryOperator) : mUnaryOperator(unaryOperator) { };
00151 Data(BinaryOperator binaryOperator) : mBinaryOperator(binaryOperator) { };
00152 };
00153
00154 const Type mNodeType;
00155 Data mNodeData;
00156 std::auto_ptr<const FunctionTree> mLeftNode;
00157 std::auto_ptr<const FunctionTree> mRightNode;
00158 };
00159
00160
00161
00162
00163
00164
00165
00166 #endif // _FunctionTree_h