forked from therion/therion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thdatabase.cxx
896 lines (730 loc) · 22.4 KB
/
thdatabase.cxx
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
/**
* @file thdatabase.cxx
*/
/* 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
* --------------------------------------------------------------------
*/
#include "thdatabase.h"
#include "thsurvey.h"
#include "thendsurvey.h"
#include "thobjectid.h"
#include "thexception.h"
#include "thdata.h"
#include "thcmdline.h"
#include "thparse.h"
#include "thdatastation.h"
#include "thlookup.h"
#include "thgrade.h"
#include "thcomment.h"
#include "thlayout.h"
#include "thscrap.h"
#include "th2ddataobject.h"
#include "thscrap.h"
#include "thpoint.h"
#include "thline.h"
#include "tharea.h"
#include "thjoin.h"
#include "thmap.h"
#include "thimport.h"
#include "thsurface.h"
#include "thendscrap.h"
#include "thconfig.h"
#include "thproj.h"
const char * thlibrarydata_init_text =
"/**\n"
" * @file librarydata.cxx\n"
" *\n"
" * THIS FILE IS GENERATED AUTOMATICALLY, DO NOT MODIFY IT !!!\n"
" */\n\n\n"
"#include \"thdatabase.h\"\n"
"#include \"thobjectsrc.h\"\n"
"#include \"thinfnan.h\"\n"
"#include \"thchencdata.h\"\n"
"#include \"thlayout.h\"\n"
"#include \"thlang.h\"\n"
"#include \"thgrade.h\"\n\n\n";
const char * thlibrarydata_grades_text =
"void thlibrary_init_grades()\n"
"{\n"
"\tstd::unique_ptr<thgrade> pgrade;\n"
"\tthbuffer oname;\n";
const char * thlibrarydata_layouts_text =
"void thlibrary_init_layouts()\n"
"{\n"
"\tstd::unique_ptr<thlayout> playout;\n"
"\tthbuffer oname;\n";
bool operator < (const class thsurveyname & n1, const class thsurveyname & n2)
{
if (strcmp(n1.n,n2.n) < 0)
return true;
else
return false;
}
bool operator < (const class threvision & r1, const class threvision & r2)
{
if (r1.id < r2.id)
return true;
else if (r1.id == r2.id) {
if (r1.r < r2.r)
return true;
}
return false;
}
void thdatabase::reset_context()
{
this->ccontext = THCTX_SURVEY;
this->objid = 0;
this->nscraps = 0;
this->fsurveyptr = NULL;
this->csurveyptr = NULL;
this->csurveylevel = 0;
this->lcsobjectptr = NULL;
this->cscrapptr = NULL;
this->lcscrapoptr = NULL;
}
thdatabase::thdatabase()
{
this->reset_context();
this->db1d.assigndb(this);
this->db2d.assigndb(this);
}
void thdatabase::clear()
{
// delete all objects
this->object_list.clear();
// clear search hashes
this->object_map.clear();
this->survey_map.clear();
// reset other variables
this->reset_context();
// create top level survey
auto top = this->create<thsurvey>(thobjectsrc("error",0));
top->name = "";
this->insert(std::move(top));
}
void thdatabase::check_context(class thdataobject * optr) {
if (optr == NULL)
return;
// Let's check the object context
const char * cmdname = optr->get_cmd_name();
const char * misscmd = "some";
if ((optr->get_context() & this->ccontext) == 0) {
switch (optr->get_context()) {
case (THCTX_SURVEY | THCTX_SCRAP):
misscmd = "survey or scrap";
break;
case THCTX_SURVEY:
misscmd = "survey";
break;
case THCTX_SCRAP:
misscmd = "scrap";
break;
}
ththrow("missing {} before {} command", misscmd, cmdname);
}
}
void thdatabase::insert(std::unique_ptr<thdataobject> unique_optr)
{
thsurvey * survey_optr;
thscrap * scrap_optr;
th2ddataobject * th2ddo_optr;
const char * optr_name;
int optr_class_id;
unsigned long csurvey_id = (this->csurveyptr == NULL) ? 0 : csurveyptr->get_nss()->id;
auto* optr = unique_optr.get();
// Call start_insert object method.
optr->start_insert();
this->check_context(optr);
// Let's take case of insertion of special objects
bool is_special_o = false;
switch (optr->get_class_id()) {
case TT_GRADE_CMD:
this->insert_grade(std::move(unique_optr));
is_special_o = true;
break;
case TT_LAYOUT_CMD:
this->insert_layout(std::move(unique_optr));
is_special_o = true;
break;
case TT_LOOKUP_CMD:
this->insert_lookup(std::move(unique_optr));
is_special_o = true;
break; }
if (is_special_o)
return;
optr_class_id = optr->get_class_id();
// Let's check, if name already not defined.
if ((strlen(optr->name) > 0) &&
(optr_class_id != TT_ENDSURVEY_CMD) &&
(optr_class_id != TT_ENDSCRAP_CMD)) {
if (this->object_map.find(thobjectid(optr->name,csurvey_id)) !=
this->object_map.end()) {
optr_name = optr->get_name();
ththrow("duplicate object name -- {}", optr_name);
}
}
// First let's select objects that have to be deleted (end...)
switch (optr_class_id) {
// end of survey
case TT_ENDSURVEY_CMD:
// let's check, if name of endsurvey is correct
if (strlen(optr->name) > 0) {
if (strcmp(optr->name, csurveyptr->name) != 0)
ththrow("survey - endsurvey names don't match -- {} - {}",
csurveyptr->name, optr->name);
}
if ((optr->get_class_id() == TT_ENDSURVEY_CMD) && (this->fsurveyptr->id == this->csurveyptr->id)) {
ththrow("missing survey before endsurvey command");
}
// whether csurvey is not the first one
//if (csurveyptr->fsptr->id == this->fsurveyptr->id) {
// this->lcsobjectptr = csurveyptr;
// this->ccontext = THCTX_NONE;
// this->csurveyptr = NULL;
//}
//else {
this->csurveyptr = csurveyptr->fsptr;
this->lcsobjectptr = csurveyptr->loptr;
//}
this->csurveylevel--;
this->csrc.context = csurveyptr;
break;
// end of scrap
case TT_ENDSCRAP_CMD:
// let's check, if name of endsurvey is correct
if (strlen(optr->name) > 0) {
if (strcmp(optr->name, cscrapptr->name) != 0)
ththrow("scrap - endscrap names don't match -- {} - {}",
cscrapptr->name, optr->name);
}
this->ccontext = THCTX_SURVEY;
this->cscrapptr = NULL;
this->lcscrapoptr = NULL;
this->csrc.context = csurveyptr;
break;
// other objects that has to be inserted into database
default:
this->csrc.context = optr;
// let's insert object into database
this->object_list.push_back(std::move(unique_optr));
this->object_map[thobjectid(optr->name, csurvey_id)] = optr;
if (this->lcsobjectptr != NULL) {
this->lcsobjectptr->nsptr = optr;
optr->psptr = this->lcsobjectptr;
}
this->lcsobjectptr = optr;
if(this->csurveyptr != NULL) {
optr->fsptr = this->csurveyptr;
if (this->csurveyptr->foptr == NULL)
this->csurveyptr->foptr = optr;
this->csurveyptr->loptr = optr;
}
// let's take care of 2d object
if(optr->is(TT_2DDATAOBJECT_CMD)) {
th2ddo_optr = (th2ddataobject *) optr;
if (this->lcscrapoptr != NULL)
this->lcscrapoptr->nscrapoptr = th2ddo_optr;
else
this->cscrapptr->fs2doptr = th2ddo_optr;
th2ddo_optr->pscrapoptr = this->lcscrapoptr;
this->cscrapptr->ls2doptr = th2ddo_optr;
th2ddo_optr->fscrapptr = this->cscrapptr;
this->lcscrapoptr = th2ddo_optr;
}
// let's take care of special objects
switch (optr_class_id) {
case TT_SURVEY_CMD:
survey_optr = (thsurvey *) optr;
survey_optr->level = ++this->csurveylevel;
if (this->fsurveyptr == NULL) {
this->fsurveyptr = survey_optr;
this->csurveyptr = survey_optr;
}
//if (this->csurveyptr == NULL) {
if (this->csurveyptr->id == this->fsurveyptr->id) {
//this->ccontext = THCTX_SURVEY;
survey_optr->full_name = survey_optr->name;
survey_optr->reverse_full_name = survey_optr->name;
} else {
this->buff_tmp.strcpy(survey_optr->name);
this->buff_tmp.strcat(".");
this->buff_tmp.strcat(this->csurveyptr->full_name);
survey_optr->full_name = this->strstore(this->buff_tmp.get_buffer());
survey_optr->reverse_full_name = this->strstore(survey_optr->full_name);
survey_optr->full_name_reverse();
}
this->survey_map[thsurveyname(survey_optr->full_name)] = survey_optr;
this->csurveyptr = survey_optr;
this->lcsobjectptr = survey_optr->loptr;
break;
case TT_SCRAP_CMD:
scrap_optr = (thscrap *) optr;
this->ccontext = THCTX_SCRAP;
this->cscrapptr = scrap_optr;
this->nscraps++;
break;
} // end of special objects insertion
} // end of other objects
// insert sub-objects
switch(optr_class_id) {
case TT_SURVEY_CMD:
this->insert(std::move(((thsurvey*)(optr))->tmp_data_holder));
break;
}
} // end of object inserion
thsurvey * thdatabase::get_survey(const char * sn, thsurvey * ps)
{
thsurvey * xxx = this->get_survey_noexc(sn, ps);
if (xxx != NULL)
return xxx;
else
ththrow("survey does not exist -- {}", sn);
}
thsurvey * thdatabase::get_survey_noexc(const char * sn, thsurvey * ps)
{
thdb_survey_map_type::iterator si;
if (sn != NULL) {
this->buff_tmp.strcpy(sn);
if ((ps != NULL) && (ps->id != this->fsurveyptr->id)) {
this->buff_tmp.strcat(".");
this->buff_tmp.strcat(ps->full_name);
}
si = this->survey_map.find(thsurveyname(this->buff_tmp.get_buffer()));
if (si != this->survey_map.end())
return si->second->get_nss();
else
return NULL;
}
else {
if (ps == NULL)
return this->fsurveyptr;
else
return ps->get_nss();
}
}
thsurvey * thdatabase::get_exact_survey_noexc(const char * sn, thsurvey * ps)
{
thdb_survey_map_type::iterator si;
if (sn != NULL) {
this->buff_tmp.strcpy(sn);
if ((ps != NULL) && (ps->id != this->fsurveyptr->id)) {
this->buff_tmp.strcat(".");
this->buff_tmp.strcat(ps->full_name);
}
si = this->survey_map.find(thsurveyname(this->buff_tmp.get_buffer()));
if (si != this->survey_map.end())
return si->second;
else
return NULL;
}
else {
if (ps == NULL)
return this->fsurveyptr;
else
return ps;
}
}
unsigned long thdatabase::get_survey_id(const char * sn, thsurvey * ps)
{
thsurvey * sptr = this->get_survey(sn, ps);
if (sptr == NULL)
return 0;
else
return sptr->id;
}
thdataobject * thdatabase::get_object(thobjectname on, thsurvey * ps)
{
unsigned long csurvey_id;
if ((ps != NULL) || ((on.survey != NULL) && (strlen(on.survey) > 0)))
csurvey_id = this->get_survey_id(on.survey, ps);
else
csurvey_id = this->fsurveyptr->id;
thdb_object_map_type::iterator oi;
oi = this->object_map.find(thobjectid(on.name,csurvey_id));
if (oi == this->object_map.end()) {
return this->get_exact_survey_noexc(on.name, (ps == NULL) ? this->fsurveyptr : ps);
}
else
return oi->second;
}
bool thdatabase::insert_datastation(thobjectname on, thsurvey * ps)
{
static thdatastation ds;
unsigned long csurvey_id = this->get_survey_id(on.survey, ps);
if (this->object_map.find(thobjectid(on.name,csurvey_id)) !=
this->object_map.end())
return false;
this->object_map[thobjectid(on.name, csurvey_id)] = & ds;
return true;
} // end of datastation inserion
std::unique_ptr<thdataobject> thdatabase::create(const char * oclass,
thobjectsrc osrc)
{
switch (thmatch_token(oclass, thtt_commands)) {
case TT_SURVEY_CMD:
return create<thsurvey>(osrc);
case TT_ENDSURVEY_CMD:
return create<thendsurvey>(osrc);
case TT_SCRAP_CMD:
return create<thscrap>(osrc);
case TT_ENDSCRAP_CMD:
return create<thendscrap>(osrc);
case TT_DATA_CMD:
return create<thdata>(osrc);
case TT_COMMENT_CMD:
return create<thcomment>(osrc);
case TT_GRADE_CMD:
return create<thgrade>(osrc);
case TT_LAYOUT_CMD:
return create<thlayout>(osrc);
case TT_LOOKUP_CMD:
return create<thlookup>(osrc);
case TT_POINT_CMD:
return create<thpoint>(osrc);
case TT_LINE_CMD:
return create<thline>(osrc);
case TT_AREA_CMD:
return create<tharea>(osrc);
case TT_JOIN_CMD:
return create<thjoin>(osrc);
case TT_MAP_CMD:
return create<thmap>(osrc);
case TT_IMPORT_CMD:
return create<thimport>(osrc);
case TT_SURFACE_CMD:
return create<thsurface>(osrc);
default:
return nullptr;
}
}
const char * thdatabase::strstore(const char * src, bool use_dic)
{
if (use_dic) {
thdb_dictionary_type::iterator ii =
this->dictionary.find(thsurveyname(src));
if (ii != this->dictionary.end())
return ii->n;
else {
ii = this->dictionary.insert(thsurveyname(this->buff_strings.append(src))).first;
return ii->n;
}
}
else
return this->buff_strings.append(src);
}
void thdatabase::end_insert()
{
if (this->csurveyptr->id != this->fsurveyptr->id) {
thdb_revision_set_type::iterator ii =
this->revision_set.find(threvision(this->csurveyptr->id, 0));
therror(("%s [%d] -- incomplete survey - endsurvey pair -- %s",
ii->srcf.name, ii->srcf.line, this->csurveyptr->full_name))
}
}
class thdataobject * thdatabase::revise(char * nn, class thsurvey * fathersptr,
thobjectsrc osrc)
{
char ** divname;
char * objname, * sfullname;
unsigned long fsid;
thdb_survey_map_type::iterator iii;
thdb_object_map_type::iterator jjj;
thsplit_strings(& this->mbuff_tmp, nn, '@');
if ((this->mbuff_tmp.get_size() == 2)) {
divname = this->mbuff_tmp.get_buffer();
objname = divname[0];
this->buff_tmp.strcpy(divname[1]);
if ((fathersptr != NULL) && (fathersptr->level > 1)) {
this->buff_tmp.strcat(".");
this->buff_tmp.strcat(fathersptr->full_name);
}
sfullname = this->buff_tmp.get_buffer();
thsurveyname xxx = thsurveyname(sfullname);
iii = this->survey_map.find(xxx);
if (iii == this->survey_map.end())
ththrow("unknown survey -- {}",nn);
else {
fsid = iii->second->id;
}
}
else {
objname = nn;
if (fathersptr != NULL)
fsid = fathersptr->id;
else
fsid = 0;
}
jjj = this->object_map.find(thobjectid(objname,fsid));
if (jjj == this->object_map.end()) {
/* jjj = this->object_map.begin();
while (jjj != this->object_map.end()) {
thprintf("%d:%s\n",jjj->first.sid,jjj->first.name);
jjj++;
}*/
return NULL;
}
else {
jjj->second->revision++;
this->revision_set.insert(threvision(jjj->second->id,
jjj->second->revision, osrc));
return jjj->second;
}
}
void thdatabase::self_print(FILE * outf)
{
thdb_object_list_type::iterator oli = this->object_list.begin();
while (oli != this->object_list.end()) {
fprintf(outf, "\n");
(*oli)->self_print(outf);
oli++;
}
fprintf(outf, "\n");
this->db1d.self_print(outf);
this->db2d.self_print(outf);
}
class thsurvey * thdatabase::get_current_survey()
{
return this->csurveyptr;
}
class thscrap * thdatabase::get_current_scrap()
{
return this->cscrapptr;
}
void thdatabase::insert_grade(std::unique_ptr<thdataobject> optr)
{
// thdb_grade_map_type::iterator gi =
// this->grade_map.find(thsurveyname(optr->get_name()));
// if ((gi == this->grade_map.end()) ||
// (thcmdln.get_print_state() == THPS_LIB_SRC)) {
// insert grade
this->grade_map[thsurveyname(optr->get_name())] = optr.get();
this->object_list.push_back(std::move(optr));
// }
// else
// ththrow("survey grade already exists -- {}",optr->get_name());
}
void thdatabase::insert_layout(std::unique_ptr<thdataobject> optr)
{
// thdb_layout_map_type::iterator gi =
// this->layout_map.find(thsurveyname(optr->get_name()));
// if ((gi == this->layout_map.end()) ||
// (thcmdln.get_print_state() == THPS_LIB_SRC)) {
// insert grade
this->layout_map[thsurveyname(optr->get_name())] = optr.get();
this->object_list.push_back(std::move(optr));
// }
// else
// ththrow("map layout already exists -- {}",optr->get_name());
}
void thdatabase::insert_lookup(std::unique_ptr<thdataobject> optr)
{
// thdb_layout_map_type::iterator gi =
// this->layout_map.find(thsurveyname(optr->get_name()));
// if ((gi == this->layout_map.end()) ||
// (thcmdln.get_print_state() == THPS_LIB_SRC)) {
// insert grade
this->lookup_map[thsurveyname(optr->get_name())] = optr.get();
this->object_list.push_back(std::move(optr));
// }
// else
// ththrow("map layout already exists -- {}",optr->get_name());
}
class thgrade * thdatabase::get_grade(char * gname)
{
thdb_grade_map_type::iterator gi =
this->grade_map.find(gname);
if (gi == this->grade_map.end())
return NULL;
else
return (thgrade *)(gi->second);
}
class thlayout * thdatabase::get_layout(const char * gname)
{
thdb_layout_map_type::iterator gi =
this->layout_map.find(gname);
if (gi == this->layout_map.end())
return NULL;
else
return (thlayout *)(gi->second);
}
class thlookup * thdatabase::get_lookup(const char * gname)
{
thdb_layout_map_type::iterator gi =
this->lookup_map.find(gname);
if (gi == this->lookup_map.end())
return NULL;
else
return (thlookup *)(gi->second);
}
void thdatabase::self_print_library()
{
thprintf(thlibrarydata_init_text);
// print survey grades
thprintf(thlibrarydata_grades_text);
thdb_grade_map_type::iterator gi = this->grade_map.begin();
while (gi != this->grade_map.end()) {
thprintf("\n\tpgrade = thdb.create<thgrade>(thobjectsrc(\"therion\",0));\n");
((thgrade *)(gi->second))->self_print_library();
gi++;
thprintf("\tthdb.insert(std::move(pgrade));\n");
}
thprintf("}\n\n");
// print map layouts
thprintf(thlibrarydata_layouts_text);
thdb_layout_map_type::iterator li = this->layout_map.begin();
while (li != this->layout_map.end()) {
thprintf("\n\tplayout = thdb.create<thlayout>(thobjectsrc(\"therion\",0));\n");
((thlayout *)(li->second))->self_print_library();
li++;
thprintf("\tthdb.insert(std::move(playout));\n");
}
thprintf("}\n\n");
}
void thdb_object_rename_persons(thdataobject * op, thsurveyp2pmap * rmap) {
if ((rmap == NULL) || (rmap->size() == 0))
return;
thsurveyp2pmap::iterator mi;
thdataobject_author tmpa;
thdo_author_map_type::iterator aii;
thdate tmpdt;
thdata * dp;
for (mi = rmap->begin(); mi != rmap->end(); mi++) {
tmpa.name = mi->first;
tmpa.rev = 0;
aii = op->author_map.find(tmpa);
if (aii != op->author_map.end()) {
tmpdt = aii->second;
op->author_map.erase(aii->first);
tmpa.name = mi->second;
op->author_map[tmpa].join(tmpdt);
}
if (op->get_class_id() == TT_DATA_CMD) {
dp = (thdata*) op;
if (dp->team_set.erase(mi->first) > 0) {
dp->team_set.insert(mi->second);
}
if (dp->discovery_team_set.erase(mi->first) > 0) {
dp->discovery_team_set.insert(mi->second);
}
}
}
}
void thdb_survey_rename_persons(thsurvey * cs, thsurveyp2pmap * rmap) {
thsurveyp2pmap cmap;
thsurveyp2pmap::iterator mi;
cmap.clear();
if ((rmap != NULL) && (rmap->size() > 0)) {
mi = rmap->begin();
while (mi != rmap->end()) {
cmap[mi->first] = mi->second;
mi++;
}
}
if (cs->person_renames.size() > 0) {
mi = cs->person_renames.begin();
while (mi != cs->person_renames.end()) {
if (cs->person_renames.find(mi->first) != cs->person_renames.end())
cmap[mi->first] = mi->second;
mi++;
}
}
thdb_object_rename_persons(cs, &cmap);
thdataobject * op;
op = cs->foptr;
while (op != NULL) {
if (op->get_class_id() == TT_SURVEY_CMD) {
thdb_survey_rename_persons((thsurvey*)op, &cmap);
} else {
thdb_object_rename_persons(op, &cmap);
}
op = op->nsptr;
}
}
void thdatabase::preprocess() {
#ifdef THDEBUG
thprintf("\n\npreprocessing database\n");
#else
thprintf("preprocessing database ... ");
thtext_inline = true;
#endif
thdb_object_list_type::iterator obi = this->object_list.begin();
while (obi != this->object_list.end()) {
try {
switch ((*obi)->get_class_id()) {
case TT_IMPORT_CMD:
((thimport*)(*obi).get())->import_file();
break;
}
} catch (...) {
(*obi)->throw_source();
switch ((*obi)->get_class_id()) {
case TT_IMPORT_CMD:
threthrow("file import");
break;
}
}
obi++;
}
// CS conversions
if (thcfg.ibbx_def) {
thcs_cfg.bbox.push_back(thcfg.ibbx[0] / THPI * 180.0);
thcs_cfg.bbox.push_back(thcfg.ibbx[2] / THPI * 180.0);
thcs_cfg.bbox.push_back(thcfg.ibbx[1] / THPI * 180.0);
thcs_cfg.bbox.push_back(thcfg.ibbx[3] / THPI * 180.0);
}
obi = this->object_list.begin();
while (obi != this->object_list.end()) {
(*obi)->convert_all_cs();
obi++;
}
thsurvey * cs = this->fsurveyptr;
while (cs != NULL) {
thdb_survey_rename_persons(cs, NULL);
cs = (thsurvey*)(cs->nsptr);
}
#ifdef THDEBUG
#else
thprintf("done\n");
thtext_inline = false;
#endif
}
void thdatabase::insert_equate(int nargs, char ** args)
{
if (this->csurveyptr == NULL)
ththrow("missing survey before equate command");
this->csurveyptr->data->set_data_equate(nargs, args);
}
void thdatabase::add_data(thdataobject* obj, const thobjectsrc& osrc)
{
if (auto* survey = dynamic_cast<thsurvey*>(obj))
{
auto retdata = std::make_unique<thdata>();
retdata->assigndb(this);
// set object id and mark revision
retdata->id = ++this->objid;
retdata->source = osrc;
this->revision_set.insert(threvision(retdata->id, 0, osrc));
survey->data = retdata.get();
survey->tmp_data_holder = std::move(retdata);
}
}
thdatabase thdb;