![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
00001 #include "gurls++/optfunction.h" 00002 00003 #include <ostream> 00004 00005 namespace gurls 00006 { 00007 00008 00009 OptFunction::OptFunction(): GurlsOption(FunctionOption), f(NULL){} 00010 00011 00012 OptFunction::OptFunction(std::string func_name): GurlsOption(FunctionOption) 00013 { 00014 setValue(func_name); 00015 } 00016 00017 OptFunction::~OptFunction() 00018 { 00019 if(f != NULL) 00020 delete f; 00021 } 00022 00023 OptFunction& OptFunction::operator=(const OptFunction& other) 00024 { 00025 if(f != NULL) 00026 delete f; 00027 00028 setValue(other.name); 00029 return *this; 00030 } 00031 00032 std::string OptFunction::getName() const 00033 { 00034 return name; 00035 } 00036 00037 bool OptFunction::isA(OptTypes id) const 00038 { 00039 return (id == FunctionOption); 00040 } 00041 00042 OptFunction* OptFunction::dynacast(GurlsOption* opt) 00043 { 00044 if (opt->isA(FunctionOption) ) 00045 return static_cast<OptFunction*>(opt); 00046 00047 throw gException(gurls::Exception_Illegal_Dynamic_Cast); 00048 } 00049 00050 const OptFunction* OptFunction::dynacast(const GurlsOption* opt) 00051 { 00052 if (opt->isA(FunctionOption) ) 00053 return static_cast<const OptFunction*>(opt); 00054 00055 throw gException(gurls::Exception_Illegal_Dynamic_Cast); 00056 } 00057 00058 GURLS_EXPORT std::ostream& OptFunction::operator<<(std::ostream& os) const 00059 { 00060 os << "Pointer to the function <" << this->getName() 00061 << "> whose signature is: T (*func)(T*, int)" ; 00062 return os; 00063 } 00064 00065 void OptFunction::setValue(std::string func_name) 00066 { 00067 name = func_name; 00068 00069 if(func_name == "mean") 00070 f = new Mean(); 00071 else if(func_name == "min") 00072 f = new Min(); 00073 else if(func_name == "max") 00074 f = new Max(); 00075 else if(func_name == "median") 00076 f = new Median(); 00077 else 00078 { 00079 f = NULL; 00080 throw gException(Exception_Unknown_Function); 00081 } 00082 } 00083 00084 }