00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SCALAR_FUNCTION_CFUNCTION_HPP
00021 #define SCALAR_FUNCTION_CFUNCTION_HPP
00022
00023 #include <ScalarFunctionBase.hpp>
00024 #include <iostream>
00025 #include <string>
00026
00035 class ScalarFunctionCFunction
00036 : public ScalarFunctionBase
00037 {
00038 private:
00039 const std::string __cFunctionName;
00040 ConstReferenceCounting<ScalarFunctionBase>
00041 __function;
00043 real_t (*__cfunction)(real_t x);
00052 std::ostream& __put(std::ostream& os) const
00053 {
00054 os << __cFunctionName << '(' << *__function << ')';
00055 return os;
00056 }
00057
00058 public:
00064 real_t operator()(const TinyVector<3, real_t>& X) const
00065 {
00066 const ScalarFunctionBase& function = *__function;
00067 return __cfunction(function(X));
00068 }
00069
00075 bool canBeSimplified() const
00076 {
00077 return false;
00078 }
00079
00086 ScalarFunctionCFunction(const std::string& cfunction,
00087 ConstReferenceCounting<ScalarFunctionBase> function)
00088 : ScalarFunctionBase(ScalarFunctionBase::cfunction),
00089 __cFunctionName(cfunction),
00090 __function(function)
00091 {
00092 if (__cFunctionName == "abs") {
00093 __cfunction = &std::abs;
00094 return;
00095 }
00096 if (__cFunctionName == "sin") {
00097 __cfunction = &std::sin;
00098 return;
00099 }
00100 if (__cFunctionName == "cos") {
00101 __cfunction = &std::cos;
00102 return;
00103 }
00104 if (__cFunctionName == "tan") {
00105 __cfunction = &std::tan;
00106 return;
00107 }
00108 if (__cFunctionName == "asin") {
00109 __cfunction = &std::asin;
00110 return;
00111 }
00112 if (__cFunctionName == "acos") {
00113 __cfunction = &std::acos;
00114 return;
00115 }
00116 if (__cFunctionName == "atan") {
00117 __cfunction = &std::atan;
00118 return;
00119 }
00120 if (__cFunctionName == "sqrt") {
00121 __cfunction = &std::sqrt;
00122 return;
00123 }
00124 if (__cFunctionName == "exp") {
00125 __cfunction = &std::exp;
00126 return;
00127 }
00128 if (__cFunctionName == "log") {
00129 __cfunction = &std::log;
00130 return;
00131 }
00132 throw ErrorHandler(__FILE__,__LINE__,
00133 "not implemented",
00134 ErrorHandler::unexpected);
00135 }
00136
00142 ScalarFunctionCFunction(const ScalarFunctionCFunction& f)
00143 : ScalarFunctionBase(f),
00144 __cFunctionName(f.__cFunctionName),
00145 __function(f.__function),
00146 __cfunction(f.__cfunction)
00147 {
00148 ;
00149 }
00150
00155 ~ScalarFunctionCFunction()
00156 {
00157 ;
00158 }
00159 };
00160
00161 #endif // SCALAR_FUNCTION_CFUNCTION_HPP