work on docs
[pspp] / src / data / spreadsheet-reader.h
index 5cfd81d7e1caf84b3eab536171bc98203bc878e7..d7783bab7fdf12eb88ae6697e6c12ffd987370d5 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2010, 2016 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@
 #define SPREADSHEET_READ_H 1
 
 #include <stdbool.h>
+#include <libpspp/compiler.h>
 
 struct casereeader;
 
@@ -30,9 +31,10 @@ struct casereeader;
 */
 struct spreadsheet_read_options
 {
-  const char *sheet_name ; /* The name of the sheet to open (in UTF-8) */
-  int sheet_index ;        /* The index of the sheet to open (only used if sheet_name is NULL) */
-  const char *cell_range ; /* The cell range (in UTF-8) */
+  char *sheet_name ;       /* The name of the sheet to open (in UTF-8) */
+  int sheet_index ;        /* The index of the sheet to open (only used if sheet_name is NULL).
+                             The first index is 1 NOT 0 */
+  char *cell_range ;       /* The cell range (in UTF-8) */
   bool read_names ;        /* True if the first row is to be used as the names of the variables */
   int asw ;                /* The width of string variables in the created dictionary */
 };
@@ -45,44 +47,78 @@ bool convert_cell_ref (const char *ref,
                       int *coli, int *rowi);
 
 
-#define _xml(X) (CHAR_CAST (const xmlChar *, X))
+#define _xml(X) (CHAR_CAST (const xmlChar *, (X)))
 
-#define _xmlchar_to_int(X) (atoi(CHAR_CAST (const char *, X)))
-
-enum spreadsheet_type
-  {
-    SPREADSHEET_NONE,
-    SPREADSHEET_GNUMERIC,
-    SPREADSHEET_ODS
-  };
+#define _xmlchar_to_int(X) ((X) ? atoi (CHAR_CAST (const char *, (X))) : -1)
 
+struct sheet_detail
+{
+  /* The name of the sheet (utf8 encoding) */
+  char *name;
+
+  /* The extents of the sheet.  */
+  int first_col;
+  int last_col;
+  int first_row;
+  int last_row;
+};
 
 struct spreadsheet
 {
-  const char *file_name;
+  /** General spreadsheet object related things.  */
+  int ref_cnt;
 
-  enum spreadsheet_type type;
+  /* A 3 letter string (null terminated) which identifies the type of
+     spreadsheet (eg: "ODS" for opendocument; "GNM" for gnumeric etc).  */
+  char type[4];
 
-  /* The total number of sheets in the "workbook" */
-  int n_sheets;
+  void (*destroy) (struct spreadsheet *);
+  struct casereader* (*make_reader) (struct spreadsheet *,
+                                   const struct spreadsheet_read_options *);
+  const char * (*get_sheet_name) (struct spreadsheet *, int);
+  char * (*get_sheet_range) (struct spreadsheet *, int);
+  int (*get_sheet_n_sheets) (struct spreadsheet *);
+  unsigned int (*get_sheet_n_rows) (struct spreadsheet *, int);
+  unsigned int (*get_sheet_n_columns) (struct spreadsheet *, int);
+  char * (*get_sheet_cell) (struct spreadsheet *, int , int , int);
 
-  /* The dictionary */
-  struct dictionary *dict;
-};
+  char *file_name;
 
+  struct sheet_detail *sheets;
 
-struct casereader * spreadsheet_make_reader (struct spreadsheet *, const struct spreadsheet_read_options *);
 
-const char * spreadsheet_get_sheet_name (struct spreadsheet *s, int n);
-char * spreadsheet_get_sheet_range (struct spreadsheet *s, int n);
+  /** Things specific to casereaders.  */
 
+  /* The dictionary for client's reference.
+     Client must ref or clone it if it needs a permanent or modifiable copy. */
+  struct dictionary *dict;
+  struct caseproto *proto;
+  struct ccase *first_case;
+  bool used_first_case;
+
+  /* Where the reader should start and stop.  */
+  int start_row;
+  int start_col;
+  int stop_row;
+  int stop_col;
+};
 
-char *create_cell_ref (int col0, int row0, int coli, int rowi);
 
-void spreadsheet_close (struct spreadsheet *);
+struct casereader * spreadsheet_make_reader (struct spreadsheet *, const struct spreadsheet_read_options *);
+
+const char * spreadsheet_get_sheet_name (struct spreadsheet *s, int n) OPTIMIZE(2);
+char * spreadsheet_get_sheet_range (struct spreadsheet *s, int n) OPTIMIZE(2);
+int  spreadsheet_get_sheet_n_sheets (struct spreadsheet *s) OPTIMIZE(2);
+unsigned int  spreadsheet_get_sheet_n_rows (struct spreadsheet *s, int n) OPTIMIZE(2);
+unsigned int  spreadsheet_get_sheet_n_columns (struct spreadsheet *s, int n) OPTIMIZE(2);
 
+char * spreadsheet_get_cell (struct spreadsheet *s, int n, int row, int column);
 
+char * create_cell_ref (int col0, int row0);
+char *create_cell_range (int col0, int row0, int coli, int rowi);
 
+struct spreadsheet * spreadsheet_ref (struct spreadsheet *s) WARN_UNUSED_RESULT;
+void spreadsheet_unref (struct spreadsheet *);
 
 
 #define SPREADSHEET_CAST(X) ((struct spreadsheet *)(X))