-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjMethods.cpp
1755 lines (1269 loc) · 52.4 KB
/
objMethods.cpp
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
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <math.h>
#include "objMethods.h"
#include "miscTools.h"
//################ GJYE OBJ METHODS ################//
//class FuncObj
/* protected */
bool FuncObj::isValidLevel(std::string strCheck) {
if (vocab.count(strCheck) > 0) {return true;}
return false;
}
/* public */
FuncObj::FuncObj(DataStorageStack * storage) {
this->isSTDL = true;
this->levelPointer = 0;
this->isPostFixFunc = false;
this->dataStructure = storage;
}
FuncObj::~FuncObj() {}
void FuncObj::importDataStack(DataStorageStack * storage) {
this->dataStructure = storage;
}
std::string FuncObj::getLevelData(std::string strCheck) {
return vocab[strCheck];
}
bool FuncObj::setLevelData(std::string lName, std::string lContents) {
if (this->isValidLevel(lName) == true) {
vocab[lName] = lContents;
return true;
}
return false;
}
/// ### ///
// ## //
//class Add_Obj : public FuncObj
/* private */
std::string Add_Obj::addToStringVar() {
std::string addThisData = "", addType = "", toThisData = "";
if (vocab["Prefix"] != "") {addThisData = tools::prepareVectorData(dataStructure, vocab["Prefix"]);addType = "prefix";}
else if (vocab["Postfix"] != "") {addThisData = tools::prepareVectorData(dataStructure, vocab["Postfix"]);addType = "postfix";}
else {addThisData = tools::prepareVectorData(dataStructure, vocab["Add"]);addType = "postfix";}
toThisData = tools::prepareVectorData(dataStructure, vocab["to"]);
if (vocab["before"] != "") {toThisData.insert((int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["before"])), addThisData);} // inherent precedence
else if (vocab["after"] != "") {toThisData.insert((int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["after"]))+1, addThisData);}
else if (vocab["at"] != "") {toThisData.insert((int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["at"])), addThisData);}
else if (addType == "prefix") {toThisData = addThisData.append(toThisData);}
else if (addType == "postfix") {toThisData.append(addThisData);}
std::string varData = vocab["to"];
if (varData.at(0) == '%') { // it's a (scalar) vector level (we checked to make sure in exec)
VariableStorage * vectorStorage = NULL;
varData = varData.substr(1,varData.length()-1);
vectorStorage = dataStructure->vecStringToVector(&varData); // jump to the vector object we want to check (modifies varData to make it the highest level)
varData = tools::prepareVectorData(dataStructure, varData); // this is the highest level! ie) %topName[index][varData]; or %varData;
if(vectorStorage->addVariable(varData,toThisData) != true) {return "-1";}
}
else { // just a plain old variable
varData = varData.substr(1,varData.length()-1);
if(dataStructure->addVariable(varData,toThisData) != true) {return "-1";}
}
return tools::intToString(toThisData.length());
}
std::string Add_Obj::addToVector(VariableStorage * toVectorStorage) { // to is indeed a vector (not a scalar level of a vector) (already jumped)
std::string addThisData = "", addType = "";
if (vocab["Prefix"] != "") {addThisData = vocab["Prefix"];addType = "prefix";}
else if (vocab["Postfix"] != "") {addThisData = vocab["Postfix"];addType = "postfix";}
else {addThisData = vocab["Add"];addType = "postfix";}
VariableStorage * addVectorStorage = NULL;
std::string addData = addThisData.substr(1,addThisData.length()-1);
addVectorStorage = dataStructure->vecStringToVector(&addData); // jump to the vector object we want to check (modifies varData to make it the highest level)
addData = tools::prepareVectorData(dataStructure, addData, false); // this is the highest level! ie) %topName[index][varData]; or %varData;
if(addVectorStorage->type(addData) == 0) { // add a scalar to a vector
if (vocab["before"] != "") {toVectorStorage->addVariable("", tools::prepareVectorData(dataStructure, addThisData), (int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["before"])));} // inherent precedence
else if (vocab["after"] != "") {toVectorStorage->addVariable("", tools::prepareVectorData(dataStructure, addThisData), (int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["after"]))+1);}
else if (vocab["at"] != "") {toVectorStorage->addVariable("", tools::prepareVectorData(dataStructure, addThisData), (int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["at"])));}
else if (addType == "prefix") {toVectorStorage->addVariable("", tools::prepareVectorData(dataStructure, addThisData), 0);}
else if (addType == "postfix") {toVectorStorage->addVariable("", tools::prepareVectorData(dataStructure, addThisData));}
} else { // add a vector to a vector
addVectorStorage = addVectorStorage->getVector(addData, false);
if (vocab["before"] != "") {toVectorStorage->addVector("", *addVectorStorage, (int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["before"])));} // inherent precedence
else if (vocab["after"] != "") {toVectorStorage->addVector("", *addVectorStorage, (int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["after"]))+1);}
else if (vocab["at"] != "") {toVectorStorage->addVector("", *addVectorStorage, (int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["at"])));}
else if (addType == "prefix") {toVectorStorage->addVector("", *addVectorStorage, 0);}
else if (addType == "postfix") {toVectorStorage->addVector("", *addVectorStorage);}
}
return tools::intToString(toVectorStorage->size());
}
/* public */
Add_Obj::Add_Obj(DataStorageStack * storage) : FuncObj(storage) { // Put in (alias)
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["Add"] = "";
tempMap["Insert"] = ""; // alias
tempMap["Prefix"] = "";
tempMap["Prepend"] = ""; // alias
tempMap["Postfix"] = "";
tempMap["Append"] = ""; // alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2ND PARAMETER
tempMap["to"] = "";
tempMap["in"] = ""; // alias
tempMap["into"] = ""; // alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 3RD PARAMETER
tempMap["before"] = "";
tempMap["after"] = ""; // level alias
tempMap["at"] = ""; // level alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(true);
// 3 DEFINITIONS IN ONE CLASS
this->returnType.push_back("$");
this->returnType.push_back("$");
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
tempVec.push_back("$"); // PARA2
tempVec.push_back("$"); // PARA3
this->paramType.push_back(tempVec);
tempVec.clear();
// PARTYPE DEF #2
tempVec.push_back("$"); // VERB
tempVec.push_back("%"); // PARA2
tempVec.push_back("$"); // PARA3
this->paramType.push_back(tempVec);
tempVec.clear();
// PARTYPE DEF #3
tempVec.push_back("%"); // VERB
tempVec.push_back("%"); // PARA2
tempVec.push_back("$"); // PARA3
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["Add"] = "";
vocab["Insert"] = ""; // alias
vocab["Prefix"] = "";
vocab["Prepend"] = ""; // alias
vocab["Postfix"] = "";
vocab["Append"] = ""; // alias
vocab["to"] = "";
vocab["in"] = ""; // alias
vocab["into"] = ""; // alias
vocab["before"] = "";
vocab["after"] = "";
vocab["at"] = "";
}
std::string Add_Obj::executeCode() {
std::string returnValue = "";
if (vocab["Prepend"] != "") {vocab["Prefix"] = vocab["Prepend"];}
else if (vocab["Append"] != "") {vocab["Postfix"] = vocab["Append"];}
else if (vocab["Insert"] != "") {vocab["Add"] = vocab["Insert"];}
if (vocab["in"] != "") {vocab["to"] = vocab["in"];}
else if (vocab["into"] != "") {vocab["to"] = vocab["into"];}
if (vocab["to"].length() > 0 && vocab["to"].at(0) == '%') {
VariableStorage * vectorStorage = NULL;
std::string toData = vocab["to"].substr(1,vocab["to"].length()-1);
vectorStorage = dataStructure->vecStringToVector(&toData); // jump to the vector object we want to check (modifies toData to make it the highest level)
toData = tools::prepareVectorData(dataStructure, toData, false); // this is the highest level! ie) %topName[index][toData]; or %toData;
if (vectorStorage->type(toData) == 0) {returnValue = this->addToStringVar();} // it's actually a scalar
else { // it is indeed a vector
vectorStorage = vectorStorage->getVector(toData, false);
returnValue = this->addToVector(vectorStorage);
}
} // vectors
else if (vocab["to"] != "") {
returnValue = this->addToStringVar();
} // stringVar
// turn return string into a variable
std::string tokenQualifier = dataStructure->variableReferencer("_STRING_");
dataStructure->addVariable(tokenQualifier,returnValue, -1, true);
tokenQualifier.insert(0,"$");
return tokenQualifier;
}
/// ### ///
// ## //
//class beginsWith_Obj : public FuncObj
/* private */
std::string beginsWith_Obj::beginsWithStringVar(int type) { // type 0 is begins with, 1 is endswith
std::string tmpSto, beWithData;
std::string thisData = tools::prepareVectorData(dataStructure, vocab["left"]);
if (type == 0) {
beWithData = tools::prepareVectorData(dataStructure, vocab["beginsWith"]); // must be a scalar (so we force it)
tmpSto = thisData.substr(0,beWithData.length());
}
else {
beWithData = tools::prepareVectorData(dataStructure, vocab["endsWith"]); // must be a scalar (so we force it)
tmpSto = thisData.substr(thisData.length()-beWithData.length(),beWithData.length());
}
if (tmpSto == beWithData) return "1";
else return "0";
}
std::string beginsWith_Obj::beginsWithVector(int type, VariableStorage * leftVector) {
std::string beWithData;
std::map<std::string, InternalDataType *, strCmp> * leftNodes = leftVector->getVectorNodes();
if (type == 0) {
beWithData = tools::prepareVectorData(dataStructure, vocab["beginsWith"]); // must be a scalar (so we force it) this might be ambiguous in the case of %VEC beginsWith %VEC
std::map<std::string, InternalDataType *>::const_iterator iter = leftNodes->begin();
if (leftVector->getData(iter->first) == beWithData) return "1";
else return "0";
}
else {
beWithData = tools::prepareVectorData(dataStructure, vocab["endsWith"]); // must be a scalar (so we force it)
std::map<std::string, InternalDataType *>::reverse_iterator iter = leftNodes->rbegin();
if (leftVector->getData(iter->first) == beWithData) return "1";
else return "0";
}
}
/* public */
beginsWith_Obj::beginsWith_Obj(DataStorageStack * storage) : FuncObj(storage) {
this->isPostFixFunc = true;
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["beginsWith"] = "";
tempMap["endsWith"] = ""; // alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2ND PARAMETER
tempMap["left"] = "";
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2 DEFINITIONS IN ONE CLASS
this->returnType.push_back("$");
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
tempVec.push_back("$"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
// PARTYPE DEF #2
tempVec.push_back("$"); // VERB
tempVec.push_back("%"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["beginsWith"] = "";
vocab["endsWith"] = "";
vocab["left"] = "";
}
std::string beginsWith_Obj::executeCode() {
std::string returnValue = "";
if (vocab["left"].length() > 0 && vocab["left"].at(0) == '%') {
VariableStorage * vectorStorage = NULL;
std::string toData = vocab["left"].substr(1,vocab["left"].length()-1);
vectorStorage = dataStructure->vecStringToVector(&toData); // jump to the vector object we want to check (modifies toData to make it the highest level)
toData = tools::prepareVectorData(dataStructure, toData, false); // this is the highest level! ie) %topName[index][toData]; or %toData;
int type = (vocab["beginsWith"] != ""?0:1);
if (vectorStorage->type(toData) == 0) { // it's actually a scalar
returnValue = this->beginsWithStringVar(type);
}
else { // it is indeed a vector
vectorStorage = vectorStorage->getVector(toData, false);
returnValue = this->beginsWithVector(type, vectorStorage);
}
} // vectors
else if (vocab["left"] != "") {
int type = (vocab["beginsWith"] != ""?0:1);
returnValue = beginsWithStringVar(type);
} // stringVar
// turn return string into a variable
std::string tokenQualifier = dataStructure->variableReferencer("_STRING_");
dataStructure->addVariable(tokenQualifier,returnValue, -1, true);
tokenQualifier.insert(0,"$");
return tokenQualifier;
}
/// ### ///
// ## // maybe rename (or alias) ElementAt? does CharAt work with vectors?
//class CharAt_Obj : public FuncObj // non-destructive
/* private */
std::string CharAt_Obj::charAtInStringVar() {
std::string inData = tools::prepareVectorData(dataStructure, vocab["in"]), returnString = "";
int charAtData = (int) tools::stringToInt(tools::prepareVectorData(dataStructure, vocab["CharAt"]));
if (charAtData < 0 || (unsigned int) charAtData >= inData.length()) {return "";} // out of bounds
returnString = inData.at(charAtData);
return returnString;
}
/* public */
CharAt_Obj::CharAt_Obj(DataStorageStack * storage) : FuncObj(storage) {
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["CharAt"] = "";
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2ND PARAMETER
tempMap["in"] = "";
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 1 DEFINITION
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
tempVec.push_back("$"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["CharAt"] = "";
vocab["in"] = "";
}
std::string CharAt_Obj::executeCode() {
std::string returnValue = "";
if (vocab["in"].length() > 0 && vocab["in"].at(0) == '%') {
VariableStorage * vectorStorage = NULL;
std::string toData = vocab["in"].substr(1,vocab["in"].length()-1);
vectorStorage = dataStructure->vecStringToVector(&toData); // jump to the vector object we want to check (modifies toData to make it the highest level)
toData = tools::prepareVectorData(dataStructure, toData, false); // this is the highest level! ie) %topName[index][toData]; or %toData;
if (vectorStorage->type(toData) == 0) { // it's actually a scalar
returnValue = this->charAtInStringVar();
} else {} // it is indeed a vector
} // VECTOR
else if (vocab["in"] != "") {returnValue = this->charAtInStringVar();} // stringVar
// turn return string into a variable
std::string tokenQualifier = dataStructure->variableReferencer("_STRING_");
dataStructure->addVariable(tokenQualifier,returnValue, -1, true);
tokenQualifier.insert(0,"$");
return tokenQualifier;
}
/// ### ///
// ## //
//class Contains_Obj : public FuncObj
/* private */
std::string Contains_Obj::containsStringVar(int type) { // type 0 is contains, 1 is lacks
std::string thisData = tools::prepareVectorData(dataStructure, vocab["left"]), containsData;
if (type == 0) {
containsData = tools::prepareVectorData(dataStructure, vocab["contains"]);
if (thisData.find(containsData) == std::string::npos) {return "0";}
else {return "1";}
} else {
containsData = tools::prepareVectorData(dataStructure, vocab["lacks"]);
if (thisData.find(containsData) == std::string::npos) {return "1";}
else {return "0";}
}
}
std::string Contains_Obj::containsVector(int type, VariableStorage * leftVector) {
std::map<std::string, InternalDataType *, strCmp> * leftNodes = leftVector->getVectorNodes();
std::string containsData;
bool contains = false;
if (type == 0) containsData = tools::prepareVectorData(dataStructure, vocab["contains"]);
else containsData = tools::prepareVectorData(dataStructure, vocab["lacks"]);
std::map<std::string, InternalDataType *>::const_iterator iter;
for (iter = leftNodes->begin(); iter != leftNodes->end(); ++iter) {
if ((*leftNodes)[iter->first]->getType() == 0) { // we can only compare scalars/strings (don't convert -- ambiguous)
if (leftVector->getData(iter->first) == containsData) contains = true;
}
}
if (type == 1) contains = !contains;
if (contains) return "1"; else return "0";
}
/* public */
Contains_Obj::Contains_Obj(DataStorageStack * storage) : FuncObj(storage) {
this->isPostFixFunc = true;
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["contains"] = "";
tempMap["lacks"] = ""; // level alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2ND PARAMETER
tempMap["left"] = "";
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2 DEFINITIONS IN ONE CLASS
this->returnType.push_back("$");
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
tempVec.push_back("$"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
// PARTYPE DEF #2
tempVec.push_back("$"); // VERB
tempVec.push_back("%"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["contains"] = "";
vocab["lacks"] = "";
vocab["left"] = "";
}
std::string Contains_Obj::executeCode() {
std::string returnValue = "";
if (vocab["left"].length() > 0 && vocab["left"].at(0) == '%') {
VariableStorage * vectorStorage = NULL;
std::string toData = vocab["left"].substr(1,vocab["left"].length()-1);
vectorStorage = dataStructure->vecStringToVector(&toData); // jump to the vector object we want to check (modifies toData to make it the highest level)
toData = tools::prepareVectorData(dataStructure, toData, false); // this is the highest level! ie) %topName[index][toData]; or %toData;
int type = (vocab["contains"] != ""?0:1);
if (vectorStorage->type(toData) == 0) { // it's actually a scalar
returnValue = this->containsStringVar(type);
}
else { // it is indeed a vector
vectorStorage = vectorStorage->getVector(toData, false);
if (vectorStorage->type() >= 0) returnValue = this->containsVector(type, vectorStorage); // arrays only
else return "";
}
} // vectors
else if (vocab["left"] != "") {
int type = (vocab["contains"] != ""?0:1);
returnValue = this->containsStringVar(type);
} // stringVar
// turn return string into a variable
std::string tokenQualifier = dataStructure->variableReferencer("_STRING_");
dataStructure->addVariable(tokenQualifier,returnValue, -1, true);
tokenQualifier.insert(0,"$");
return tokenQualifier;
}
/// ### ///
// ## //
//class Exit_Obj : public FuncObj
/* public */
Exit_Obj::Exit_Obj(DataStorageStack * storage) : FuncObj(storage) {
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["Exit"] = "";
tempMap["Die"] = ""; // alias
tempMap["Quit"] = ""; // alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(true);
// 1 DEFINITION
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["Exit"] = "";
vocab["Die"] = ""; // alias
vocab["Quit"] = ""; // alias
}
std::string Exit_Obj::executeCode() {
exit(0);
return "";
}
/// ### ///
// ## //
//class IndexOf_Obj : public FuncObj
/* private */
std::string IndexOf_Obj::indexOfInStringVar(int type) { // type 0 is indexof, 1 is lastindexof
int returnInt;
std::string findData, varData = tools::prepareVectorData(dataStructure, vocab["in"]);
if (type == 0) {
findData = tools::prepareVectorData(dataStructure, vocab["IndexOf"]);
returnInt = varData.find(findData);
}
else {
findData = tools::prepareVectorData(dataStructure, vocab["LastIndexOf"]);
returnInt = varData.rfind(findData);
}
if ((unsigned int) returnInt == std::string::npos) {returnInt = -1;}
return tools::intToString(returnInt);
}
std::string IndexOf_Obj::indexOfInVector(int type, VariableStorage * inVector) {
std::map<std::string, InternalDataType *, strCmp> * inNodes = inVector->getVectorNodes();
if (type == 0) {
std::string findData = tools::prepareVectorData(dataStructure, vocab["IndexOf"]);
std::map<std::string, InternalDataType *>::const_iterator iter;
for (iter = inNodes->begin(); iter != inNodes->end(); ++iter) {
if (inVector->type(iter->first) == 0) { // we can only compare scalars/strings (don't convert -- ambiguous)
if (inVector->getData(iter->first) == findData) return iter->first;
}
}
}
else {
std::string findData = tools::prepareVectorData(dataStructure, vocab["LastIndexOf"]);
std::map<std::string, InternalDataType *>::reverse_iterator iter;
for (iter = inNodes->rbegin(); iter != inNodes->rend(); ++iter) {
if (inVector->type(iter->first) == 0) { // we can only compare scalars/strings (don't convert -- ambiguous)
if (inVector->getData(iter->first) == findData) return iter->first;
}
}
}
return "-1";
}
/* public */
IndexOf_Obj::IndexOf_Obj(DataStorageStack * storage) : FuncObj(storage) {
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["IndexOf"] = "";
tempMap["LastIndexOf"] = ""; // level alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2ND PARAMETER
tempMap["in"] = "";
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2 DEFINITIONS IN ONE CLASS
this->returnType.push_back("$");
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
tempVec.push_back("$"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
// PARTYPE DEF #2
tempVec.push_back("$"); // VERB
tempVec.push_back("%"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["IndexOf"] = "";
vocab["LastIndexOf"] = "";
vocab["in"] = "";
}
std::string IndexOf_Obj::executeCode() {
std::string returnValue = "";
if (vocab["in"].length() > 0 && vocab["in"].at(0) == '%') {
VariableStorage * vectorStorage = NULL;
std::string toData = vocab["in"].substr(1,vocab["in"].length()-1);
vectorStorage = dataStructure->vecStringToVector(&toData); // jump to the vector object we want to check (modifies toData to make it the highest level)
toData = tools::prepareVectorData(dataStructure, toData, false); // this is the highest level! ie) %topName[index][toData]; or %toData;
int type = (vocab["IndexOf"] != ""?0:1);
if (vectorStorage->type(toData) == 0) { // it's actually a scalar
returnValue = this->indexOfInStringVar(type);
}
else { // it is indeed a vector
vectorStorage = vectorStorage->getVector(toData, false);
if (vectorStorage->type() >= 0) returnValue = this->indexOfInVector(type, vectorStorage); // arrays only (there is no first and last in a vector)
else return "";
}
} // vectors
else if (vocab["in"].length() > 0 && vocab["in"].at(0) == '#') {} // FH
else if (vocab["in"] != "") {
int type = (vocab["IndexOf"] != ""?0:1);
returnValue = this->indexOfInStringVar(type);
} // stringVar
// turn return string into a variable
std::string tokenQualifier = dataStructure->variableReferencer("_STRING_");
dataStructure->addVariable(tokenQualifier,returnValue, -1, true);
tokenQualifier.insert(0,"$");
return tokenQualifier;
}
/// ### ///
// ## //
//class isDefined_Obj : public FuncObj
/* public */
isDefined_Obj::isDefined_Obj(DataStorageStack * storage) : FuncObj(storage) {
this->isPostFixFunc = true;
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["isDefined"] = "";
tempMap["exists"] = ""; // alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(true);
// 2ND PARAMETER
tempMap["left"] = "";
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2 DEFINITIONS IN ONE CLASS
this->returnType.push_back("$");
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
tempVec.push_back("$"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
// PARTYPE DEF #2
tempVec.push_back("$"); // VERB
tempVec.push_back("%"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["isDefined"] = "";
vocab["exists"] = ""; // alias
vocab["left"] = "";
}
std::string isDefined_Obj::executeCode() {
std::string returnValue = "0";
if (vocab["left"].length() > 0 && vocab["left"].at(0) == '%') {
std::string thisData = vocab["left"].substr(1,vocab["left"].length()-1);
VariableStorage * vectorStorage = dataStructure->vecStringToVector(&thisData, false, true); // a don't die version
thisData = tools::prepareVectorData(dataStructure, thisData);
if (vectorStorage != NULL && vectorStorage->variableExists(thisData)) returnValue = "1";
} // vectors
else if (vocab["left"].length() > 0 && vocab["left"].at(0) == '#') {} // FH
else if (vocab["left"] != "") {
std::string thisData = vocab["left"].substr(1,vocab["left"].length()-1);
if (dataStructure->variableExists(thisData)) returnValue = "1";
} // var
// needs clean-up (delete transients ...)
// turn return string into a variable
std::string tokenQualifier = dataStructure->variableReferencer("_STRING_");
dataStructure->addVariable(tokenQualifier,returnValue, -1, true);
tokenQualifier.insert(0,"$");
return tokenQualifier;
}
/// ### ///
// ## //
//class Join_Obj : public FuncObj
/* public */
Join_Obj::Join_Obj(DataStorageStack * storage) : FuncObj(storage) {
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["Join"] = "";
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2ND PARAMETER
tempMap["by"] = "";
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 1 DEFINITION
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("%"); // VERB
tempVec.push_back("$"); // PARA2
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["Join"] = "";
vocab["by"] = "";
}
std::string Join_Obj::executeCode() {
std::string returnValue = "";
if (vocab["Join"].length() > 0 && vocab["Join"].at(0) == '%') { // vectors only
VariableStorage * vectorStorage = NULL;
std::string joinData = vocab["Join"].substr(1,vocab["Join"].length()-1);
vectorStorage = dataStructure->vecStringToVector(&joinData); // jump to the vector object we want to check (modifies toData to make it the highest level)
joinData = tools::prepareVectorData(dataStructure, joinData); // this is the highest level! ie) %topName[index][toData]; or %toData;
if (vectorStorage->type(joinData) > 0) { // it's a vector
vectorStorage = vectorStorage->getVector(joinData);
std::map<std::string, InternalDataType *, strCmp> * inNodes = vectorStorage->getVectorNodes();
std::string juncture = tools::prepareVectorData(dataStructure, vocab["by"]);
std::map<std::string, InternalDataType *>::const_iterator iter;
for (iter = inNodes->begin(); iter != inNodes->end(); ++iter) {
returnValue += vectorStorage->getData(iter->first) + juncture; // only the values (strip keys for vectors)
}
returnValue.erase(returnValue.length()-juncture.length(), juncture.length());
}
}
// turn return string into a variable
std::string tokenQualifier = dataStructure->variableReferencer("_STRING_");
dataStructure->addVariable(tokenQualifier,returnValue, -1, true);
tokenQualifier.insert(0,"$");
return tokenQualifier;
}
/// ### ///
// ## //
//class Local_Obj : public FuncObj
/* public */
Local_Obj::Local_Obj(DataStorageStack * storage) : FuncObj(storage) {
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["Local"] = "";
tempMap["My"] = ""; // alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 2 DEFINITIONS IN ONE CLASS
this->returnType.push_back("$");
this->returnType.push_back("%");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
this->paramType.push_back(tempVec);
tempVec.clear();
// PARTYPE DEF #2
tempVec.push_back("%"); // VERB
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["Local"] = "";
vocab["My"] = ""; // alias
}
std::string Local_Obj::executeCode() {
std::string tokenQualifier = "";
if (vocab["My"] != "") {vocab["Local"] = vocab["My"];}
if (vocab["Local"].at(0) == '$') { // create (localized) (VARIABLE)
std::string varName = vocab["Local"].substr(1,vocab["Local"].length()-1);
//std::cout << varName <<std::endl;
dataStructure->addVariable(varName,"", -1, true);
tokenQualifier = "$" + varName;
}
else if (vocab["Local"].at(0) == '%') { // create (localized) (VECTOR)
std::string vecName = vocab["Local"].substr(1,vocab["Local"].length()-1);
VariableStorage * tmp = new VariableStorage;
dataStructure->addVector(vecName, *tmp, -1, true);
delete tmp;
tokenQualifier = "%" + vecName;
}
else {std::cout << "WARNING :: Assignation: Unknown Data Type!" <<std::endl;}
return tokenQualifier;
}
/// ### ///
// ## //
//class LowerUpperCase_Obj : public FuncObj
/* private */
std::string LowerUpperCase_Obj::lowerUpperStringVar() {
std::string luCaseData = "";
if (vocab["Lc"] != "") {luCaseData = tools::prepareVectorData(dataStructure, vocab["Lc"]);}
else if (vocab["Uc"] != "") {luCaseData = tools::prepareVectorData(dataStructure, vocab["Uc"]);}
for(unsigned int i=0; i < luCaseData.length(); ++i) {
if (vocab["Lc"] != "") {luCaseData[i] = tolower(luCaseData[i]);}
else {luCaseData[i] = toupper(luCaseData[i]);}
}
return luCaseData;
}
/* public */
LowerUpperCase_Obj::LowerUpperCase_Obj(DataStorageStack * storage) : FuncObj(storage) {
// VERB DECLARATION
std::map<std::string, std::string> tempMap;
tempMap["Lc"] = "";
tempMap["Lower"] = ""; // alias
tempMap["Lowercase"] = ""; // alias
tempMap["Uc"] = "";
tempMap["Upper"] = ""; // alias
tempMap["Uppercase"] = ""; // alias
this->vocabulary.push_back( tempMap );
tempMap.clear();
this->isOptional.push_back(false);
// 1 DEFINITION
this->returnType.push_back("$");
// PARTYPE DEF #1
std::vector<std::string> tempVec;
tempVec.push_back("$"); // VERB
this->paramType.push_back(tempVec);
tempVec.clear();
vocab["Lc"] = "";
vocab["Lower"] = ""; // alias
vocab["Lowercase"] = ""; // alias
vocab["Uc"] = "";
vocab["Upper"] = ""; // alias
vocab["Uppercase"] = ""; // alias
}
std::string LowerUpperCase_Obj::executeCode() {
std::string returnValue = "", typeValue = "";
if (vocab["Lower"] != "") {vocab["Lc"] = vocab["Lower"];}
else if (vocab["Lowercase"] != "") {vocab["Lc"] = vocab["Lowercase"];}
else if (vocab["Upper"] != "") {vocab["Uc"] = vocab["Upper"];}
else if (vocab["Uppercase"] != "") {vocab["Uc"] = vocab["Uppercase"];}
if (vocab["Lc"] != "") {typeValue = vocab["Lc"];}
else if (vocab["Uc"] != "") {typeValue = vocab["Uc"];}