func.h 5.56 KB
Newer Older
Arturo Espinosa's avatar
Arturo Espinosa committed
1 2 3
#ifndef GNUMERIC_FUNC_H
#define GNUMERIC_FUNC_H

4 5 6
#include "expr.h"
#include "sheet.h"

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
extern void math_functions_init(void);
extern void sheet_functions_init(void);
extern void misc_functions_init(void);
extern void date_functions_init(void);
extern void string_functions_init(void);
extern void stat_functions_init(void);
extern void finance_functions_init(void);
extern void eng_functions_init(void);
extern void lookup_functions_init(void);
extern void logical_functions_init(void);
extern void database_functions_init(void);
extern void information_functions_init(void);

typedef int (*FunctionIterateCallback)(const EvalPosition *ep, Value *value,
				       ErrorMessage *error, void *);
Arturo Espinosa's avatar
Arturo Espinosa committed
22 23 24 25

/*
 * function_iterate_argument_values
 *
26
 * fp:               The position in a workbook at which to evaluate
Arturo Espinosa's avatar
Arturo Espinosa committed
27 28 29
 * callback:         The routine to be invoked for every value computed
 * callback_closure: Closure for the callback.
 * expr_node_list:   a GList of ExprTrees (what a Gnumeric function would get).
30
 * error:            a pointer to an ErrorMessage where an error description is stored.
Morten Welinder's avatar
Morten Welinder committed
31 32 33 34 35
 * strict:           If TRUE, the function is considered "strict".  This means
 *                   that if an error value occurs as an argument, the iteration
 *                   will stop and that error will be returned.  If FALSE, an
 *                   error will be passed on to the callback (as a NULL Value *
 *                   with error_string set).
Arturo Espinosa's avatar
Arturo Espinosa committed
36 37 38
 *
 * Return value:
 *    TRUE  if no errors were reported.
Morten Welinder's avatar
Morten Welinder committed
39 40
 *    FALSE if an error was found during strict evaluation, or if the callback
 *          requested termination of the iteration.
Arturo Espinosa's avatar
Arturo Espinosa committed
41 42 43 44 45 46 47
 *
 * This routine provides a simple way for internal functions with variable
 * number of arguments to be written: this would iterate over a list of
 * expressions (expr_node_list) and will invoke the callback for every
 * Value found on the list (this means that ranges get properly expaned).
 */
int
48
function_iterate_argument_values (const EvalPosition      *fp,
Arturo Espinosa's avatar
Arturo Espinosa committed
49 50 51
				  FunctionIterateCallback callback,
				  void                    *callback_closure,
				  GList                   *expr_node_list,
52
				  ErrorMessage            *error,
53
				  gboolean                strict);
Arturo Espinosa's avatar
Arturo Espinosa committed
54
				  
55 56 57
/*
 * function_call_with_values
 */
58 59 60 61 62
Value      *function_call_with_values     (const EvalPosition *ep,
					   const char         *name,
					   int                 argc,
					   Value              *values [],
					   ErrorMessage       *error);
63

64
Value      *function_def_call_with_values (const EvalPosition *ep,
65 66 67
					   FunctionDefinition *fd,
					   int                 argc,
					   Value              *values [],
68
					   ErrorMessage       *error);
69

Jukka-Pekka Iivonen's avatar
Jukka-Pekka Iivonen committed
70
int
71
function_iterate_do_value (const EvalPosition      *fp,
Jukka-Pekka Iivonen's avatar
Jukka-Pekka Iivonen committed
72 73 74
			   FunctionIterateCallback callback,
			   void                    *closure,
			   Value                   *value,
75
			   ErrorMessage            *error,
76
			   gboolean                strict);
Michael Meeks's avatar
Michael Meeks committed
77

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*
 * Gnumeric function defintion API.
 */
typedef struct _FunctionCategory FunctionCategory;
struct _FunctionCategory {
	gchar *name;
	GList *functions;
};
FunctionCategory   *function_get_category (gchar *description);
FunctionDefinition *function_add_args  (FunctionCategory *parent,
				        char *name,
				        char *args,
				        char *arg_names,
				        char **help,
				        FunctionArgs *fn);
FunctionDefinition *function_add_nodes (FunctionCategory *parent,
					char *name,
					char *args,
					char *arg_names,
					char **help,
					FunctionNodes *fn);

GList *function_categories_get (void);
Michael Meeks's avatar
Michael Meeks committed
101 102 103

typedef struct {
	GPtrArray *sections ;
104
	char      *help_copy ;
Michael Meeks's avatar
Michael Meeks committed
105
	FunctionDefinition *fd ;
106
} TokenizedHelp;
Michael Meeks's avatar
Michael Meeks committed
107

108 109
typedef struct {
	int N;
Jukka-Pekka Iivonen's avatar
Jukka-Pekka Iivonen committed
110
	float_t M, Q, sum;
111
        gboolean afun_flag;
112 113
} stat_closure_t;

114 115 116
TokenizedHelp *tokenized_help_new     (FunctionDefinition *fd);
const char    *tokenized_help_find    (TokenizedHelp *tok, const char *token);
void           tokenized_help_destroy (TokenizedHelp *tok);
117

118
float_t combin (int n, int k);
119
float_t fact   (int n);
120
void setup_stat_closure (stat_closure_t *cl);
121
int callback_function_stat (const EvalPosition *ep, Value *value, ErrorMessage *error,
122
			    void *closure);
123

124 125 126 127 128 129 130 131 132 133 134
Value *gnumeric_average     (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_count       (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_sum         (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_stdev       (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_stdevp      (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_var         (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_varp        (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_counta      (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_min         (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_max         (FunctionEvalInfo *s, GList *nodes);
Value *gnumeric_suma        (FunctionEvalInfo *s, GList *nodes);
135 136


137 138 139 140
/* Type definitions and function prototypes for criteria functions.
 * This includes the database functions and some mathematical functions
 * like COUNTIF, SUMIF...
 */
Michael Meeks's avatar
Michael Meeks committed
141
typedef int (*criteria_test_fun_t) (Value *x, Value *y);
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157

typedef struct {
        criteria_test_fun_t fun;
        Value                *x;
} func_criteria_t;

int criteria_test_equal(Value *x, Value *y);
int criteria_test_unequal(Value *x, Value *y);
int criteria_test_greater(Value *x, Value *y);
int criteria_test_less(Value *x, Value *y);
int criteria_test_greater_or_equal(Value *x, Value *y);
int criteria_test_less_or_equal(Value *x, Value *y);
void parse_criteria(char *criteria, criteria_test_fun_t *fun,
		    Value **test_value);


158 159
int solver_simplex(Workbook *wb, Sheet *sheet);

Arturo Espinosa's avatar
Arturo Espinosa committed
160
#endif /* GNUMERIC_FUNC_H */