-
Notifications
You must be signed in to change notification settings - Fork 16
/
XYPlotParam.H
256 lines (210 loc) · 5.82 KB
/
XYPlotParam.H
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// -------------------------------------------------------------------
// XYPlotParam.H
// -------------------------------------------------------------------
#ifndef _XYPLOT_PARAM_H
#define _XYPLOT_PARAM_H
#include <X11/X.h>
#include <X11/Xlib.h>
#include <cctype>
#define ST_DEFAULT_MAX_DENSITY 5
#define ST_DEFAULT_INIT_TABLE_SIZE 11
#define ST_DEFAULT_GROW_FACTOR 2.0
#define ST_DEFAULT_REORDER_FLAG 0
#define ISO_FONT "*-*-%s-medium-r-normal-*-*-%d-*-*-*-*-iso8859-*"
typedef enum param_types_defn {
INT, STR, PIXEL, FONT, STYLE, BOOL, DBL
} param_types;
typedef struct params_int_defn { // INT
param_types type;
int value;
} param_int;
typedef struct params_str_defn { // STR
param_types type;
char *value;
} param_str;
typedef struct params_pix_defn { // PIXEL
param_types type;
XColor value;
int iColorMapSlot;
} param_pix;
typedef struct params_font_defn { // FONT
param_types type;
XFontStruct *value;
} param_font;
typedef struct params_style_defn { // STYLE
param_types type;
int len;
char *dash_list;
} param_style;
typedef struct params_bool_defn { // BOOL
param_types type;
int value;
} param_bool;
typedef struct params_dbl_defn { // DOUBLE
param_types type;
double value;
} param_dbl;
typedef union params_defn {
param_types type;
param_int intv; // INT
param_str strv; // STR
param_pix pixv; // PIXEL
param_font fontv; // FONT
param_style stylev; // STYLE
param_bool boolv; // BOOL
param_dbl dblv; // DBL
} params;
typedef struct param_full_defn {
param_types type;
char *text_form;
params *real_form;
} param_full;
typedef struct st_table_entry_defn {
char *key;
param_full *record;
struct st_table_entry_defn *next;
} st_table_entry;
typedef struct st_table_defn {
int num_bins;
int num_entries;
int max_density;
int reorder_flag;
double grow_factor;
st_table_entry **bins;
} st_table;
#include <XYPlotDefaults.H>
#include <XYPlotWin.H>
class GraphicsAttributes;
class Palette;
class XYPlotParameters {
public:
XYPlotParameters(Palette *palPtr, GraphicsAttributes *gaptr, char *name);
~XYPlotParameters();
//
// Sets the parameter with the given name to have the type
// _type_ and the text value _value_. This will be evaluated
// to its full form the first time it is referenced using
// Get_Parameter(). If it is already filled, the old value
// will be reclaimed.
//
void Set_Parameter(const char *name, param_types type, const char *val);
//
// This routine sets the value of an existing parameter to a new
// value. The type of the parameter remains the same. Changes
// in type should be done by using param_set() directly.
//
void Reset_Parameter(char *name, char *val);
//
// Retrieves a value from the parameter table. The value
// is placed in val. If successful, the routine will
// return 1. Otherwise, it will return 0.
//
int Get_Parameter(char *name, params *val);
//
// Writes the current settings out to a file.
//
void WriteToFile(char *filename);
//
// Reads in from a file.
//
void ReadFromFile(const char *filename);
//
// Resets the palette and its dependent parameters.
//
void ResetPalette(Palette *newPalPtr);
private:
params param_temp;
int param_ok;
st_table param_table;
Palette *param_palette;
GraphicsAttributes *gaPtr;
char *title;
//
// Reads in defaults defined by yours truly.
//
void GetHardWiredDefaults(void);
//
// Reclaims a resource based on its type
//
void free_resource(params *val);
//
// Allocates and returns an appropriate parameter structure
// by translating form into its native type as given by type.
// If it cant translate the given form, it will fall back onto
// the default.
//
params *resolve_entry(char *name, param_types type, char *form);
//
// Translates name into a color and attempts to get the pixel
// for the color using XAllocColor().
//
int do_color(const char *name, XColor *color, int &cmSlot);
//
// This routine translates a font name into a font structure. The
// font name can be in two forms. The first form is <family>-<size>.
// The family is a family name (like helvetica) and the size is
// in points (like 12). If the font is not in this form, it
// is assumed to be a regular X font name specification and
// is looked up using the standard means.
//
int do_font(const char *name, XFontStruct **font_info);
//
// Translates a string representation of a dash specification into
// a form suitable for use in XSetDashes(). Assumes list
// is a null terminated string of ones and zeros.
//
int do_style(const char *list, param_style *val);
//
// Translates a string representation into a suitable binary value.
// Can parse all kinds of interesting boolean type words.
//
int do_bool(const char *name, int *val);
//
// Look up item in table -- return zero if not found
//
param_full * st_lookup(char *key);
//
// Insert an item into the table - replacing if it already exists
//
int st_insert(char *key, param_full *value);
//
// Dumps a single parameter
//
void dump_it (char *key, char *value);
//
// Grows table
//
void rehash(void);
int strihash(char *xypstring) {
int val = 0;
int c;
int i = 0;
while ((c = *xypstring++) != '\0') {
if(isupper(c)) {
c = tolower(c);
}
val = (val - ++i) + 997 * c;
}
return ((val < 0) ? -val : val) % param_table.num_bins;
}
int string_compare(const char *s1, const char *s2) {
char c, d;
while ((c = *s1) != '\0') {
if(isupper(c)) {
c = tolower(c);
}
d = *s2;
if(isupper(d)) {
d = tolower(d);
}
if(c != d) {
return 1;
}
++s1;
++s2;
}
if(*s2 != '\0') return 1;
return 0;
}
};
#endif