dependent.h 3.4 KB
Newer Older
1 2
#ifndef GNUMERIC_EVAL_H
#define GNUMERIC_EVAL_H
Arturo Espinosa's avatar
Arturo Espinosa committed
3

4
#include "gnumeric.h"
Jody Goldberg's avatar
Jody Goldberg committed
5
#include <stdio.h>
6

Jody Goldberg's avatar
Jody Goldberg committed
7 8 9 10 11
struct _Dependent
{
	guint	  flags;
	Sheet	 *sheet;
	ExprTree *expression;
12 13

	/* Double-linked list.  */
14
	struct _Dependent *next_dep, *prev_dep;
Jody Goldberg's avatar
Jody Goldberg committed
15 16 17 18
};

typedef struct {
	void (*eval) (Dependent *dep);
19
	void (*set_expr) (Dependent *dep, ExprTree *new_expr);
Jody Goldberg's avatar
Jody Goldberg committed
20 21 22 23 24 25 26
	void (*debug_name) (Dependent const *dep, FILE *out);
} DependentClass;

typedef enum {
	/* Linked into the workbook wide expression list */
	DEPENDENT_IN_EXPR_LIST     = 0x00001000,
	DEPENDENT_NEEDS_RECALC	   = 0x00002000,
27
	DEPENDENT_BEING_CALCULATED = 0x00004000,
Jody Goldberg's avatar
Jody Goldberg committed
28 29 30 31 32 33

	/* Types */
	DEPENDENT_CELL 		  = 0x00000001,
	DEPENDENT_TYPE_MASK	  = 0x00000fff,
} DependentFlags;

34 35
#define dependent_type(dep)		((dep)->flags & DEPENDENT_TYPE_MASK)
#define dependent_is_cell(dep)		(dependent_type (dep) == DEPENDENT_CELL)
Jody Goldberg's avatar
Jody Goldberg committed
36
#define dependent_needs_recalc(dep)	((dep)->flags & DEPENDENT_NEEDS_RECALC)
37
#define dependent_is_linked(dep)	((dep)->flags & DEPENDENT_IN_EXPR_LIST)
38 39 40 41

struct _DependencyContainer {
	Dependent *dependent_list;

42 43
	/* Large ranges hashed on 'range' to accelerate duplicate culling. This
	 * is tranversed by g_hash_table_foreach mostly.
44
	 */
45
	GHashTable **range_hash;
46 47

	/* Single ranges, this maps an EvalPos * to a GSList of its
48 49 50
	 * dependencies.
	 */
	GHashTable *single_hash;
51 52 53

	/* All of the ExprNames that refer to this sheet */
	GHashTable *names;
54
};
55

Jody Goldberg's avatar
Jody Goldberg committed
56 57 58 59 60 61
typedef void (*DepFunc) (Dependent *dep, gpointer user);

guint32 dependent_type_register  (DependentClass const *klass);
void dependent_types_init	 (void);
void dependent_types_shutdown	 (void);

62
void	 dependent_set_expr	   (Dependent *dependent, ExprTree *new_expr);
Jody Goldberg's avatar
Jody Goldberg committed
63
void	 dependent_set_sheet	   (Dependent *dependent, Sheet *sheet);
64 65 66 67 68 69
void	 dependent_link		   (Dependent *dep, CellPos const *pos);
void	 dependent_unlink	   (Dependent *dep, CellPos const *pos);
void	 dependent_unlink_sheet	   (Sheet *sheet);
gboolean dependent_eval		   (Dependent *dep);
void	 dependent_changed	   (Dependent *dep, gboolean queue_recalc);
void	 cb_dependent_queue_recalc (Dependent *dep, gpointer ignore);
Jody Goldberg's avatar
Jody Goldberg committed
70 71 72 73 74

void cell_add_dependencies	 (Cell *cell);
void cell_drop_dependencies	 (Cell *cell);
void cell_queue_recalc		 (Cell const *cell);
void cell_foreach_dep		 (Cell const *cell, DepFunc func, gpointer user);
75
void cell_eval		 	 (Cell *cell);
Jody Goldberg's avatar
Jody Goldberg committed
76 77 78 79 80 81 82

void sheet_region_queue_recalc	 (Sheet const *sheet, Range const *range);
/* Do we need this ?
void sheet_foreach_dep		 (Sheet *sheet, DepFunc func, gpointer user);
 */
void sheet_deps_destroy		 (Sheet *sheet);
void workbook_deps_destroy	 (Workbook *wb);
83
void workbook_queue_all_recalc	 (Workbook *wb);
Jody Goldberg's avatar
Jody Goldberg committed
84

85
DependencyContainer *dependency_data_new (void);
Jody Goldberg's avatar
Jody Goldberg committed
86 87 88

void sheet_dump_dependencies	 (Sheet const *sheet);
void dependent_debug_name	 (Dependent const *dep, FILE *out);
Arturo Espinosa's avatar
Arturo Espinosa committed
89

90 91 92 93 94 95 96 97 98 99 100
#define DEPENDENT_CONTAINER_FOREACH_DEPENDENT(dc, dep, code)	\
  do {								\
	Dependent *dep = (dc)->dependent_list;			\
	while (dep) {						\
		Dependent *_next = dep->next_dep;		\
		code;						\
		dep = _next;					\
	}							\
  } while (0)


101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
#define DEPENDENT_MAKE_TYPE(t, set_expr_handler)		\
guint								\
t ## _get_dep_type (void)					\
{								\
	static guint32 type = 0;				\
	if (type == 0) {					\
		static DependentClass klass;			\
		klass.eval	 = &t ## _eval;			\
		klass.set_expr	 = set_expr_handler;		\
		klass.debug_name = &t ## _debug_name;		\
		type = dependent_type_register (&klass);	\
	}							\
	return type;						\
}

116
#endif /* GNUMERIC_EVAL_H */