functions.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "formula.h"
00021 #include "functions.h"
00022 #include "valueconverter.h"
00023
00024 #include <qdict.h>
00025 #include <qvaluevector.h>
00026
00027 #include <kstaticdeleter.h>
00028
00029 #include <math.h>
00030
00031 namespace KSpread
00032 {
00033
00034 class Function::Private
00035 {
00036 public:
00037 QString name;
00038 FunctionPtr ptr;
00039 };
00040
00041 class FunctionRepository::Private
00042 {
00043 public:
00044 QDict<Function> functions;
00045 };
00046
00047 }
00048
00049
00050 using namespace KSpread;
00051
00052 Function::Function( const QString& name, FunctionPtr ptr )
00053 {
00054 d = new Private;
00055 d->name = name;
00056 d->ptr = ptr;
00057 }
00058
00059 Function::~Function()
00060 {
00061 delete d;
00062 }
00063
00064 QString Function::name() const
00065 {
00066 return d->name;
00067 }
00068
00069 KSpreadValue Function::exec( const Formula* formula, QValueVector<KSpreadValue> args )
00070 {
00071 if( !d->ptr ) return KSpreadValue::errorVALUE();
00072 return (*d->ptr)( formula, args );
00073 }
00074
00075 static KStaticDeleter<FunctionRepository> fr_sd;
00076 FunctionRepository* FunctionRepository::s_self = 0;
00077
00078 FunctionRepository* FunctionRepository::self()
00079 {
00080 if( !s_self )
00081 fr_sd.setObject( s_self, new FunctionRepository() );
00082
00083 return s_self;
00084 }
00085
00086 KSpreadValue function_sin( const Formula* formula, QValueVector<KSpreadValue> args )
00087 {
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 return KSpreadValue::errorVALUE();
00107 }
00108
00109 FunctionRepository::FunctionRepository()
00110 {
00111 d = new Private;
00112
00113 d->functions.setAutoDelete( true );
00114
00115
00116
00117 add( new Function( "SIN", function_sin ) );
00118
00119
00120 }
00121
00122 FunctionRepository::~FunctionRepository()
00123 {
00124 delete d;
00125 }
00126
00127 void FunctionRepository::add( Function* function )
00128 {
00129 if( !function ) return;
00130 d->functions.insert( function->name().upper(), function );
00131 }
00132
00133 Function* FunctionRepository::function( const QString& name )
00134 {
00135 return d->functions.find( name.upper() );
00136 }
This file is part of the documentation for kspread Library Version 1.4.2.