File: thdataobject.h

package info (click to toggle)
therion 5.3.9-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 16,956 kB
  • sloc: ansic: 127,467; cpp: 89,790; tcl: 24,110; perl: 2,051; makefile: 1,003; asm: 201; python: 54; sh: 4
file content (477 lines) | stat: -rw-r--r-- 8,895 bytes parent folder | download | duplicates (2)
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/**
 * @file thdataobject.h
 * Main data class module.
 */
  
/* Copyright (C) 2000 Stacho Mudrak
 * 
 * $Date: $
 * $RCSfile: $
 * $Revision: $
 *
 * -------------------------------------------------------------------- 
 * 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
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * --------------------------------------------------------------------
 */
 
#ifndef thdataobject_h
#define thdataobject_h


#include "thdatabase.h"
#include "thperson.h"
#include "thparse.h"
#include "thdate.h"
#include "thdataleg.h"
#include <stdio.h>
#include <map>

/**
 * Command tokens.
 */

enum {
  TT_UNKNOWN_CMD,
  TT_DATAOBJECT_CMD, TT_DATASTATION_CMD, TT_2DDATAOBJECT_CMD,
  TT_SURVEY_CMD, TT_ENDSURVEY_CMD,
  TT_GRADE_CMD, TT_LAYOUT_CMD,
  TT_SCRAP_CMD, TT_ENDSCRAP_CMD,
  TT_POINT_CMD, TT_LINE_CMD, TT_AREA_CMD,
  TT_JOIN_CMD, TT_MAP_CMD, TT_SURFACE_CMD,
  TT_DATA_CMD, TT_IMPORT_CMD, TT_SKETCH_CMD,
};


/**
 * Command parsing table.
 */
 
static const thstok thtt_commands[] = {
  {"area", TT_AREA_CMD},
  {"centerline", TT_DATA_CMD},
  {"centreline", TT_DATA_CMD},
  {"endscrap", TT_ENDSCRAP_CMD},
  {"endsurvey", TT_ENDSURVEY_CMD},
  {"grade", TT_GRADE_CMD},
  {"import", TT_IMPORT_CMD},
  {"join", TT_JOIN_CMD},
  {"layout", TT_LAYOUT_CMD},
  {"line", TT_LINE_CMD},
  {"map", TT_MAP_CMD},
  {"point", TT_POINT_CMD},
  {"scrap", TT_SCRAP_CMD},
  {"sketch", TT_SKETCH_CMD},
  {"surface", TT_SURFACE_CMD},
  {"survey", TT_SURVEY_CMD},
	{NULL, TT_UNKNOWN_CMD},
};


/**
 * Dataobject command options tokens.
 */
 
enum {
  TT_DATAOBJECT_UNKNOWN = 1000,
  TT_DATAOBJECT_NAME = 1001,
  TT_DATAOBJECT_TITLE = 1002,
  TT_DATAOBJECT_AUTHOR = 1003,
  TT_DATAOBJECT_COPYRIGHT = 1004,
  TT_DATAOBJECT_STNS = 1005,
  TT_DATAOBJECT_CS = 1006,
  TT_DATAOBJECT_ATTR = 1007,
};


/**
 * Dataobject command options parsing table.
 */
 
static const thstok thtt_dataobject_opt[] = {
  {"attr", TT_DATAOBJECT_ATTR},
  {"author", TT_DATAOBJECT_AUTHOR},
  {"copyright", TT_DATAOBJECT_COPYRIGHT},
  {"cs", TT_DATAOBJECT_CS},
  {"id", TT_DATAOBJECT_NAME},
  {"station-names", TT_DATAOBJECT_STNS},
  {"title", TT_DATAOBJECT_TITLE},
	{NULL, TT_DATAOBJECT_UNKNOWN},
};


/**
 * Option description class.
 */
 
class thcmd_option_desc {

  public:

  
  int id, ///< Option identifier.
      nargs; ///< Number of option arguments.
  
  /**
   * Standard constructor.
   */
   
  thcmd_option_desc() : id(TT_DATAOBJECT_UNKNOWN), nargs(1) {}
  

  /**
   * Constructor.
   *
   * @param oid Option id.
   */
   
  thcmd_option_desc(int oid) : id(oid), nargs(1) {}
  
  
  /**
   * Constructor.
   *
   * @param oid Option id.
   * @param nas Number of arguments.
   */
   
  thcmd_option_desc(int oid, int nas) : id(oid), nargs(nas) {}
    
    
};


/**
 * Dataobject author class.
 */
 
class thdataobject_author {

  /**
   * Comparison operator.
   */
   
  friend bool operator < (const thdataobject_author & a1, 
      const thdataobject_author & a2);
  
  public:

  thperson name;  ///< Author's name
  unsigned long rev;  ///< Object's revision.
  
  /**
   * Standard constructor.
   */
   
  thdataobject_author() : name(), rev(0) {}


  /**
   * Default constructor.
   */
   
  thdataobject_author(thperson an, unsigned long rv) : name(an), rev(rv) {}
  
  
};


/* *
 * Dataobject copyright class.
 */
 
class thdataobject_copyright {

  /**
   * Comparison operator.
   */
   
  friend bool operator < (const thdataobject_copyright & c1, 
      const thdataobject_copyright & c2);
  
  public:

  const char * name;  ///< Author's name
  unsigned long rev;  ///< Object's revision.
  
  /**
   * Standard constructor.
   */
   
  thdataobject_copyright() : name(""), rev(0) {}
   
  
  /**
   * Default constructor.
   */
   
  thdataobject_copyright(const char * nn, unsigned long rv) : name(nn), rev(rv) {}
  
  
};


typedef std::map <thdataobject_author, thdate> thdo_author_map_type;  ///< Author's map type
typedef std::map <thdataobject_copyright, thdate> thdo_copyright_map_type;  ///< Copyright's map type


/**
 * Main data object class.
 *
 * Father object of all data object. Main database item.
 */

class thdataobject {

  public:
  
  friend class thdatabase;
  friend class thdb1d;
  friend class thdb2d;
  friend class thselector;

  class thdatabase * db;

  const char * name,  ///< Object name.
    * title,  ///< Object title.
    * stnpref, ///< Station names prefix;
    * stnsuff; ///< Station names suffix;
  
  unsigned long id;  ///< Object identifier.
  
  bool selected,  ///< Whether object is selected.
    tmp_bool;  ///< Temporary variable for some algorithms
    
  unsigned long selected_number,  ///< Number of selection.
    tmp_ulong;  ///< Temporary variable for some algorithms
  
  thdataobject * nsptr,  ///< Next object in survey.
    * psptr;  ///< Previous object in survey.
  class thsurvey * fsptr;  ///< Father survey ptr.
  
  unsigned long revision;  ///< Object revision.
	thobjectsrc source;  ///< Object source.

  thperson dotmp_person;  ///< Temporary person.
  thdate dotmp_date;  ///< Temporary date.
  thdataobject_author dotmp_author; ///< Temporary author.
  thdataobject_copyright dotmp_copyright; ///< Temporary author.
  thdo_author_map_type author_map;  ///< Author map.
  thdo_copyright_map_type copyright_map;  ///< Copyright map.

  int cs;  ///< Coordinate system.
	thobjectsrc cs_source;  ///< Coordinate system source.

  public:

  /**
   * Standard constructor.
   */
  
  thdataobject();
  
  
  /**
   * Standard destructor.
   */
   
  virtual ~thdataobject();
  
  
  /**
   * Assign database to object.
   */
   
  void assigndb(thdatabase * pdb);
  
  
  /**
   * Return class identifier.
   */
  
  virtual int get_class_id();
  
  
  /**
   * Return class name.
   */
   
  virtual const char * get_class_name() {return "thdataobject";};
  
  
  /**
   * Return true, if son of given class.
   */
  
  virtual bool is(int class_id);
  
  
  /**
   * Return number of command arguments.
   */
   
  virtual int get_cmd_nargs();
  
  
  /**
   * Return command end option.
   */
   
  virtual const char * get_cmd_end();
  
  
  /**
   * Whether multiple ends.
   */
   
  virtual bool get_cmd_ends_state();


  /**
   * Whether cmd is end.
   */
   
  virtual bool get_cmd_ends_match(char * cmd);
  
  
  /**
   * Return command name.
   */
   
  virtual const char * get_cmd_name();
  
  
  /**
   * Return option description.
   */
   
  virtual thcmd_option_desc get_cmd_option_desc(const char * opts);
  
  
  /**
   * Set command option.
   *
   * @param cod Command option description.
   * @param args Option arguments arry.
   * @param argenc Arguments encoding.
   */
   
  virtual void set(thcmd_option_desc cod, char ** args, int argenc, unsigned long indataline);
  
  
  /**
   * Returns object id.
   */
   
  virtual int get_id();
  
  
  /**
   * Return object name.
   */
   
  virtual const char * get_name();
  
  
  /**
   * Return object title.
   */
   
  const char * get_title();
  
  
  /**
   * Delete this object.
   *
   * @warn Always use this methos instead of delete function.
   */
   
  virtual void self_delete();
  
  
  /**
   * Get context for object.
   */
   
  virtual int get_context();
  
  
  /**
   * Print object contents into file.
   */
   
  void self_print(FILE * outf);
  
  
  /**
   * Print object contents into file.
   */
   
  virtual void self_print_properties(FILE * outf);
  
    
  /**
   * Write object source to exception description.
   */
   
  virtual void throw_source();
  
  
  /**
   * Complete object settings.
   *
   * This method is called, before object is inserted into database,
   * or configuration is ended.
   */
   
  virtual void start_insert();
  
  
  /**
   * Return father survey.
   */
   
  class thsurvey * get_father_survey() {return this->fsptr;}
  
  
  /**
   * Whether object is selected.
   */
   
  bool is_selected() {return this->selected;}
  
  /**
   * Is inside other survey.
   */
 
  bool is_in_survey(thsurvey * psearch);

  /**
   * Convert coordinates according to current CS specification.
   */

  void convert_cs(char * src_x, char * src_y, double & dst_x, double & dst_y);

  /**
   * Parse object attributes.
   */

  void parse_attribute(char * name, char * value);

};


#endif