File: read_xml.h

package info (click to toggle)
ggobi 2.1.9~20091212-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 19,340 kB
  • ctags: 5,083
  • sloc: ansic: 57,242; xml: 30,604; cpp: 833; makefile: 355; java: 225; perl: 201; sh: 122; python: 23
file content (206 lines) | stat: -rw-r--r-- 6,297 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* read_xml.h */
/*
 * ggobi
 * Copyright (C) AT&T, Duncan Temple Lang, Dianne Cook 1999-2005
 *
 * ggobi is free software; you may use, redistribute, and/or modify it
 * under the terms of the Common Public License, which is distributed
 * with the source code and displayed on the ggobi web site, 
 * www.ggobi.org.  For more information, contact the authors:
 *
 *   Deborah F. Swayne   dfs@research.att.com
 *   Di Cook             dicook@iastate.edu
 *   Duncan Temple Lang  duncan@wald.ucdavis.edu
 *   Andreas Buja        andreas.buja@wharton.upenn.edu
*/

#ifndef READ_XML_H
#define READ_XML_H

#include "vars.h"

#include <libxml/parser.h>

enum xmlDataState {
  TOP = 0,
  DATASET, DESCRIPTION,
  RECORD, RECORDS, VARIABLES, VARIABLE,
  COLORMAP, COLOR,
  REAL_VARIABLE, CATEGORICAL_VARIABLE,
  INTEGER_VARIABLE, COUNTER_VARIABLE, UNIFORM_VARIABLE,
  CATEGORICAL_LEVELS, CATEGORICAL_LEVEL,
  COLORSCHEME,
  BRUSHSTYLE,
  REAL, INTEGER, STRING, NA,
  QUICK_HELP,
  EDGES, EDGE,
/* HELP, DESCRIPTION */
  UNKNOWN
};

typedef enum xmlDataState XmlTagType;

typedef struct {

  int color;
  int glyphType;
  int glyphSize;
  int edgeWidth;  /*-- this has no home in ggobi --*/
  int hidden;

} DataOptions;

typedef struct _XMLUserData {
  enum xmlDataState state;
  gint current_variable;        /* Indexes the current variable. */
  gint current_record;          /* Indexes the record we are currently working on. */
  gint current_element;         /* Indexes the values within a record. */
  gint current_level;           /* */

  gint current_color;           /* The index of the current element
                                   being processed in the colormap */

  xmlChar *recordString;
  int recordStringLength;

  /* Flag that says we are reading color entries from another file via a
   * sub-parser.  This allows us to reuse the same instance of user data
   * and the same handlers.
   */
  gboolean reading_colormap_file_p;

  /* A boolean indicating whether the transformation name of a variable
     was stored as an attribute.
   */
  gboolean variable_transform_name_as_attribute;

  /* The ggobi instance that is being initialized. */
  ggobid *gg;

  InputDescription *input;

  /* The current data object to which new records are added. */
  GGobiData *current_data;
  // The list of all datad's read.
  GSList *dlist; 

  /* Flag indicating whether we should convert
     char arrays into null-terminated strings
     before passing them to the sub-handlers
     (e.g. setColorValue, setVariableName).
   */
  gboolean terminateStrings_p;

  /* The datasets global missing value identifier. */
  gchar *NA_identifier;
  /* The identifier for a missing value that is currently in effect.
     This might be specified per record and will be discarded
     at the end of that record.
     We could also do this columnwise.
   */
  gchar *current_NA_identifier;

  /* A set of values that apply to records when an attribute
     is not specified for that specific record but is set
     in the ggobidata tag.
   */
  DataOptions defaults;

  /* Local set of record identifiers that are used here
     for matching purposes when specifying edges.
     These are not set in the datad structure and 
     are different from the record's label attribute.
     Currently these are used to verify that the id's are unique
     within a dataset.
   */
  GHashTable *idNamesTable;

  GHashTable *idTable;
  gboolean usesStringIds;  /* this is now unused; it's always true */

  gint recordLabelsVariable;

  GHashTable **autoLevels;

  gint counterVariableIndex;

  /* Reference to the handlers being used as callbacks.
     Need this so that we can re-specify it when creating
     new sub-parsers.
   */
  xmlSAXHandlerPtr handlers;


  /*
     The number of datasets to expect within the file.
   */
  int expectedDatasetCount;

  xmlParserCtxtPtr parser;

} XMLParserData;


#ifdef __cplusplus
extern "C" {
#endif

  enum xmlDataState tagType(const xmlChar * name, gboolean endTag);
  gboolean newVariable(const xmlChar ** attrs, XMLParserData * data,
                       const xmlChar * tagName);
  gboolean newEdgeVariable(const xmlChar ** attrs, XMLParserData * data);
  gboolean setDatasetInfo(const xmlChar ** attrs, XMLParserData * data);
  gboolean setGeneralInfo(const xmlChar ** attrs, XMLParserData * data);
  gboolean allocVariables(const xmlChar ** attrs, XMLParserData * data);
  gboolean newRecord(const xmlChar ** attrs, XMLParserData * data);
  gboolean setDataset(const xmlChar ** attrs, XMLParserData * parserData, enum xmlDataState);
  gboolean setBrushStyle(const xmlChar ** attrs, XMLParserData * parserData);

  gboolean setRecordValues(XMLParserData * data, const xmlChar * line,
                           gint len, gint ncols);
  gboolean setVariableName(XMLParserData * data, const xmlChar * name,
                           gint len);

  gboolean setDefaultDatasetValues(const xmlChar ** attrs,
                                   XMLParserData * data);

  const xmlChar *skipWhiteSpace(const xmlChar * ch, gint * len);

  const gchar *getAttribute(const xmlChar ** attrs, gchar * name);


  void xml_warning(const gchar * attribute, const gchar * value,
                   const gchar * msg, XMLParserData * data);

  void initParserData(XMLParserData * data, xmlSAXHandlerPtr handler,
                      ggobid * gg);

  gboolean setGlyph(const xmlChar ** attrs, XMLParserData * data, gint i);
  gboolean setColor(const xmlChar ** attrs, XMLParserData * data, gint i);



  void categoricalLevels(const xmlChar ** attrs, XMLParserData * data);
  int setLevelIndex(const xmlChar ** attrs, XMLParserData * data);
  void addLevel(XMLParserData * data, const char *c, int len);

  GSList * data_xml_read(InputDescription * desc, ggobid * gg);

  gboolean setHidden(const xmlChar ** attrs, XMLParserData * data, gint i);

  int asInteger(const gchar * tmp);
  double asNumber(const char *sval);
  gboolean asLogical(const gchar * sval);

  GGobiData *getCurrentXMLData(XMLParserData * parserData);

  gboolean readXMLRecord(const xmlChar ** attrs, XMLParserData * data);

  gchar * intern(XMLParserData *, const char * el);
  
  gboolean isXMLFile (const gchar * fileName, ggobid * gg, GGobiPluginInfo * info);

#ifdef __cplusplus
}
#endif
#endif