00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023 #ifndef libmath_library_h
00024 #define libmath_library_h
00025
00026 #include <math++/error.h>
00027
00028 #include <list>
00029 #include <map>
00030 #include <string>
00031
00032 namespace math {
00033
00034 template<class> class TNode;
00035 template<class> class TLibrary;
00036
00040 template<typename T>
00041 class TFunction {
00042 private:
00043 std::string FName;
00044 TNode<T> *FExpression;
00045
00046 public:
00047 TFunction();
00048 TFunction(const TFunction<T>&);
00049 TFunction(const std::string& AName, const std::string& AExprStr = std::string());
00050 TFunction(const std::string& AName, const TNode<T> *AExprTree);
00051 ~TFunction();
00052
00053 T call(const T& AParam, const TLibrary<T>& ALibrary, unsigned ALimit = 64) const;
00054
00055 void name(const std::string&);
00056 std::string name() const;
00057
00058 void expression(const TNode<T> *ACopyOf);
00059 void expression(const std::string& AExprStr);
00060 TNode<T> *expression() const;
00061 };
00062
00066 template<typename T>
00067 class TConstant {
00068 private:
00069 std::string FName;
00070 T FValue;
00071
00072 public:
00073 TConstant();
00074 TConstant(const TConstant<T>&);
00075 TConstant(const std::string& AName, const T& AValue = T());
00076
00077 void name(const std::string&);
00078 std::string name() const;
00079
00080 void value(const T&);
00081 T value() const;
00082 };
00083
00088 class ELibraryLookup : public EMath {
00089 public:
00090 ELibraryLookup(const std::string& AMsg) : EMath(AMsg) {}
00091 };
00092
00093
00099 template<typename T>
00100 class TLibrary {
00101 private:
00102 typedef std::list<TFunction<T> > TFunctionList;
00103 typedef std::list<TConstant<T> > TConstantList;
00104
00105 TFunctionList FFunctions;
00106 TConstantList FConstants;
00107
00108 void removeIf(const std::string& AName, bool AReplaceIfExists);
00109
00110 public:
00111 TLibrary();
00112 TLibrary(const TLibrary<T>&);
00113
00115 void insert(const TFunction<T>&, bool AReplaceIfExists = false);
00117 void insert(const TConstant<T>&, bool AReplaceIfExists = false);
00118
00120 void remove(const std::string& AName);
00121
00123 TFunction<T> function(const std::string& AName) const;
00124
00126 TConstant<T> constant(const std::string& AName) const;
00127
00129 bool hasFunction(const std::string& AName) const;
00130
00132 bool hasConstant(const std::string& AName) const;
00133
00135 T call(const std::string& AName, const T& AParam) const;
00137 T value(const std::string& AName) const;
00138
00140 unsigned functions() const;
00142 unsigned constants() const;
00143 };
00144
00145 }
00146
00147 template<typename T> std::ostream& operator<<(std::ostream&, const math::TFunction<T>&);
00148
00149 #include <math++/library.tcc>
00150
00151 #endif