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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
|
/*
pool - hierarchical storage object for PD and Max/MSP
Copyright (c) 2002-2008 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
$LastChangedRevision: 26 $
$LastChangedDate: 2008-01-03 16:14:29 +0100 (Thu, 03 Jan 2008) $
$LastChangedBy: thomas $
*/
#include "pool.h"
#include <string>
#include <map>
#define POOL_VERSION "0.2.2pre"
#define VCNT 32
#define DCNT 8
class pool:
public flext_base
{
FLEXT_HEADER_S(pool,flext_base,setup)
public:
pool(int argc,const t_atom *argv);
virtual ~pool();
static void setup(t_classid);
virtual bool Init();
pooldata *Pool() { return pl; }
protected:
// switch to other pool
void ms_pool(const AtomList &l);
void mg_pool(AtomList &l);
void mg_priv(bool &p) const { p = pl && pl->Private(); }
// print some help message
static void m_help() { post("pool " POOL_VERSION " - hierarchical storage object, (C)2002-2008 Thomas Grill"); }
// clear all data in pool
void m_reset();
// handle directories
void m_getdir();
void m_mkdir(int argc,const t_atom *argv,bool abs = true,bool chg = false); // make (and change) to dir
void m_mkchdir(int argc,const t_atom *argv) { m_mkdir(argc,argv,true,true); } // make and change to dir
void m_chdir(int argc,const t_atom *argv,bool abs = true); // change to dir
void m_rmdir(int argc,const t_atom *argv,bool abs = true); // remove dir
void m_updir(int argc,const t_atom *argv); // one or more levels up
void ms_curdir(const AtomList &l) { m_chdir(l.Count(),l.Atoms()); }
void m_mksub(int argc,const t_atom *argv) { m_mkdir(argc,argv,false); }
void m_mkchsub(int argc,const t_atom *argv) { m_mkdir(argc,argv,false,true); }
void m_chsub(int argc,const t_atom *argv) { m_chdir(argc,argv,false); }
void m_rmsub(int argc,const t_atom *argv) { m_rmdir(argc,argv,false); }
// handle data
void m_set(int argc,const t_atom *argv) { set(argc,argv,true); }
void m_seti(int argc,const t_atom *argv); // set value at index
void m_add(int argc,const t_atom *argv) { set(argc,argv,false); }
void m_clr(int argc,const t_atom *argv);
void m_clri(int ix); // clear value at index
void m_clrall(); // only values
void m_clrrec(); // also subdirectories
void m_clrsub(); // only subdirectories
void m_get(int argc,const t_atom *argv);
void m_geti(int ix); // get value at index
void m_getall(); // only values
void m_getrec(int argc,const t_atom *argv); // also subdirectories
void m_getsub(int argc,const t_atom *argv); // only subdirectories
void m_ogetall(int argc,const t_atom *argv); // only values (ordered)
void m_ogetrec(int argc,const t_atom *argv); // also subdirectories (ordered)
void m_ogetsub(int argc,const t_atom *argv); // only subdirectories (ordered)
void m_cntall(); // only values
void m_cntrec(int argc,const t_atom *argv); // also subdirectories
void m_cntsub(int argc,const t_atom *argv); // only subdirectories
// print directories
void m_printall(); // print values in current dir
void m_printrec(int argc,const t_atom *argv,bool fromroot = false); // print values recursively
void m_printroot() { m_printrec(0,NULL,true); } // print values recursively from root
// cut/copy/paste
void m_paste(int argc,const t_atom *argv) { paste(thisTag(),argc,argv,true); } // paste contents of clipboard
void m_pasteadd(int argc,const t_atom *argv) { paste(thisTag(),argc,argv,false); } // paste but don't replace
void m_clrclip(); // clear clipboard
void m_cut(int argc,const t_atom *argv) { copy(thisTag(),argc,argv,true); } // cut value into clipboard
void m_copy(int argc,const t_atom *argv) { copy(thisTag(),argc,argv,false); } // copy value into clipboard
void m_cutall() { copyall(thisTag(),true,0); } // cut all values in current directory into clipboard
void m_copyall() { copyall(thisTag(),false,0); } // copy all values in current directory into clipboard
void m_cutrec(int argc,const t_atom *argv) { copyrec(thisTag(),argc,argv,true); } // cut directory (and subdirs) into clipboard
void m_copyrec(int argc,const t_atom *argv) { copyrec(thisTag(),argc,argv,false); } // cut directory (and subdirs) into clipboard
// load/save from/to file
void m_load(int argc,const t_atom *argv) { load(argc,argv,false); }
void m_save(int argc,const t_atom *argv) { save(argc,argv,false); }
void m_loadx(int argc,const t_atom *argv) { load(argc,argv,true); } // XML
void m_savex(int argc,const t_atom *argv) { save(argc,argv,true); } // XML
// load directories
void m_lddir(int argc,const t_atom *argv) { lddir(argc,argv,false); } // load values into current dir
void m_ldrec(int argc,const t_atom *argv) { ldrec(argc,argv,false); } // load values recursively
void m_ldxdir(int argc,const t_atom *argv) { lddir(argc,argv,true); } // load values into current dir (XML)
void m_ldxrec(int argc,const t_atom *argv) { ldrec(argc,argv,true); } // load values recursively (XML)
// save directories
void m_svdir(int argc,const t_atom *argv) { svdir(argc,argv,false); } // save values in current dir
void m_svrec(int argc,const t_atom *argv) { svrec(argc,argv,false); } // save values recursively
void m_svxdir(int argc,const t_atom *argv) { svdir(argc,argv,true); } // save values in current dir (XML)
void m_svxrec(int argc,const t_atom *argv) { svrec(argc,argv,true); } // save values recursively (XML)
private:
static bool KeyChk(const t_atom &a);
static bool ValChk(int argc,const t_atom *argv);
static bool ValChk(const AtomList &l) { return ValChk(l.Count(),l.Atoms()); }
void ToOutAtom(int ix,const t_atom &a);
static const t_symbol *sym_echo;
static const t_symbol *sym_error;
enum get_t { get_norm,get_cnt,get_print };
void set(int argc,const t_atom *argv,bool over);
void getdir(const t_symbol *tag);
int getrec(const t_symbol *tag,int level,int order,bool rev,get_t how /*= get_norm*/,const AtomList &rdir);
int getsub(const t_symbol *tag,int level,int order,bool rev,get_t how /*= get_norm*/,const AtomList &rdir);
void paste(const t_symbol *tag,int argc,const t_atom *argv,bool repl);
void copy(const t_symbol *tag,int argc,const t_atom *argv,bool cut);
void copyall(const t_symbol *tag,bool cut,int lvls);
void copyrec(const t_symbol *tag,int argc,const t_atom *argv,bool cut);
void load(int argc,const t_atom *argv,bool xml);
void save(int argc,const t_atom *argv,bool xml);
void lddir(int argc,const t_atom *argv,bool xml); // load values into current dir
void ldrec(int argc,const t_atom *argv,bool xml); // load values recursively
void svdir(int argc,const t_atom *argv,bool xml); // save values in current dir
void svrec(int argc,const t_atom *argv,bool xml); // save values recursively
void echodir() { if(echo) getdir(sym_echo); }
bool absdir,echo;
int vcnt,dcnt;
pooldata *pl;
Atoms curdir;
pooldir *clip;
static const t_symbol *holdname; // used during initialization of new object (between constructor and Init method)
typedef std::map<const t_symbol *,pooldata *> PoolMap;
static PoolMap poolmap;
void SetPool(const t_symbol *s);
void FreePool();
static pooldata *GetPool(const t_symbol *s);
static void RmvPool(pooldata *p);
string MakeFilename(const char *fn) const;
FLEXT_CALLVAR_V(mg_pool,ms_pool)
FLEXT_ATTRGET_V(curdir)
FLEXT_CALLSET_V(ms_curdir)
FLEXT_ATTRVAR_B(absdir)
FLEXT_ATTRVAR_B(echo)
FLEXT_CALLGET_B(mg_priv)
FLEXT_ATTRVAR_I(vcnt)
FLEXT_ATTRVAR_I(dcnt)
FLEXT_CALLBACK(m_help)
FLEXT_CALLBACK(m_reset)
FLEXT_CALLBACK(m_getdir)
FLEXT_CALLBACK_V(m_mkdir)
FLEXT_CALLBACK_V(m_chdir)
FLEXT_CALLBACK_V(m_mkchdir)
FLEXT_CALLBACK_V(m_updir)
FLEXT_CALLBACK_V(m_rmdir)
FLEXT_CALLBACK_V(m_mksub)
FLEXT_CALLBACK_V(m_chsub)
FLEXT_CALLBACK_V(m_mkchsub)
FLEXT_CALLBACK_V(m_rmsub)
FLEXT_CALLBACK_V(m_set)
FLEXT_CALLBACK_V(m_seti)
FLEXT_CALLBACK_V(m_add)
FLEXT_CALLBACK_V(m_clr)
FLEXT_CALLBACK_I(m_clri)
FLEXT_CALLBACK(m_clrall)
FLEXT_CALLBACK(m_clrrec)
FLEXT_CALLBACK(m_clrsub)
FLEXT_CALLBACK_V(m_get)
FLEXT_CALLBACK_I(m_geti)
FLEXT_CALLBACK(m_getall)
FLEXT_CALLBACK_V(m_getrec)
FLEXT_CALLBACK_V(m_getsub)
FLEXT_CALLBACK_V(m_ogetall)
FLEXT_CALLBACK_V(m_ogetrec)
FLEXT_CALLBACK_V(m_ogetsub)
FLEXT_CALLBACK(m_cntall)
FLEXT_CALLBACK_V(m_cntrec)
FLEXT_CALLBACK_V(m_cntsub)
FLEXT_CALLBACK(m_printall)
FLEXT_CALLBACK_V(m_printrec)
FLEXT_CALLBACK(m_printroot)
FLEXT_CALLBACK_V(m_paste)
FLEXT_CALLBACK_V(m_pasteadd)
FLEXT_CALLBACK(m_clrclip)
FLEXT_CALLBACK_V(m_copy)
FLEXT_CALLBACK_V(m_cut)
FLEXT_CALLBACK(m_copyall)
FLEXT_CALLBACK(m_cutall)
FLEXT_CALLBACK_V(m_copyrec)
FLEXT_CALLBACK_V(m_cutrec)
FLEXT_CALLBACK_V(m_load)
FLEXT_CALLBACK_V(m_save)
FLEXT_CALLBACK_V(m_lddir)
FLEXT_CALLBACK_V(m_ldrec)
FLEXT_CALLBACK_V(m_svdir)
FLEXT_CALLBACK_V(m_svrec)
FLEXT_CALLBACK_V(m_loadx)
FLEXT_CALLBACK_V(m_savex)
FLEXT_CALLBACK_V(m_ldxdir)
FLEXT_CALLBACK_V(m_ldxrec)
FLEXT_CALLBACK_V(m_svxdir)
FLEXT_CALLBACK_V(m_svxrec)
};
FLEXT_NEW_V("pool",pool);
pool::PoolMap pool::poolmap;
const t_symbol *pool::sym_echo,*pool::sym_error;
const t_symbol *pool::holdname;
void pool::setup(t_classid c)
{
post("");
pool::m_help();
post("");
sym_echo = MakeSymbol("echo");
sym_error = MakeSymbol("error");
FLEXT_CADDATTR_VAR(c,"pool",mg_pool,ms_pool);
FLEXT_CADDATTR_VAR(c,"curdir",curdir,ms_curdir);
FLEXT_CADDATTR_VAR1(c,"absdir",absdir);
FLEXT_CADDATTR_VAR1(c,"echodir",echo);
FLEXT_CADDATTR_GET(c,"private",mg_priv);
FLEXT_CADDATTR_VAR1(c,"valcnt",vcnt);
FLEXT_CADDATTR_VAR1(c,"dircnt",dcnt);
FLEXT_CADDMETHOD_(c,0,"help",m_help);
FLEXT_CADDMETHOD_(c,0,"reset",m_reset);
FLEXT_CADDMETHOD_(c,0,"getdir",m_getdir);
FLEXT_CADDMETHOD_(c,0,"mkdir",m_mkdir);
FLEXT_CADDMETHOD_(c,0,"chdir",m_chdir);
FLEXT_CADDMETHOD_(c,0,"mkchdir",m_mkchdir);
FLEXT_CADDMETHOD_(c,0,"rmdir",m_rmdir);
FLEXT_CADDMETHOD_(c,0,"updir",m_updir);
FLEXT_CADDMETHOD_(c,0,"mksub",m_mksub);
FLEXT_CADDMETHOD_(c,0,"chsub",m_chsub);
FLEXT_CADDMETHOD_(c,0,"mkchsub",m_mkchsub);
FLEXT_CADDMETHOD_(c,0,"rmsub",m_rmsub);
FLEXT_CADDMETHOD_(c,0,"set",m_set);
FLEXT_CADDMETHOD_(c,0,"seti",m_seti);
FLEXT_CADDMETHOD_(c,0,"add",m_add);
FLEXT_CADDMETHOD_(c,0,"clr",m_clr);
FLEXT_CADDMETHOD_(c,0,"clri",m_clri);
FLEXT_CADDMETHOD_(c,0,"clrall",m_clrall);
FLEXT_CADDMETHOD_(c,0,"clrrec",m_clrrec);
FLEXT_CADDMETHOD_(c,0,"clrsub",m_clrsub);
FLEXT_CADDMETHOD_(c,0,"get",m_get);
FLEXT_CADDMETHOD_(c,0,"geti",m_geti);
FLEXT_CADDMETHOD_(c,0,"getall",m_getall);
FLEXT_CADDMETHOD_(c,0,"getrec",m_getrec);
FLEXT_CADDMETHOD_(c,0,"getsub",m_getsub);
FLEXT_CADDMETHOD_(c,0,"ogetall",m_ogetall);
FLEXT_CADDMETHOD_(c,0,"ogetrec",m_ogetrec);
FLEXT_CADDMETHOD_(c,0,"ogetsub",m_ogetsub);
FLEXT_CADDMETHOD_(c,0,"cntall",m_cntall);
FLEXT_CADDMETHOD_(c,0,"cntrec",m_cntrec);
FLEXT_CADDMETHOD_(c,0,"cntsub",m_cntsub);
FLEXT_CADDMETHOD_(c,0,"printall",m_printall);
FLEXT_CADDMETHOD_(c,0,"printrec",m_printrec);
FLEXT_CADDMETHOD_(c,0,"printroot",m_printroot);
FLEXT_CADDMETHOD_(c,0,"paste",m_paste);
FLEXT_CADDMETHOD_(c,0,"pasteadd",m_pasteadd);
FLEXT_CADDMETHOD_(c,0,"clrclip",m_clrclip);
FLEXT_CADDMETHOD_(c,0,"cut",m_cut);
FLEXT_CADDMETHOD_(c,0,"copy",m_copy);
FLEXT_CADDMETHOD_(c,0,"cutall",m_cutall);
FLEXT_CADDMETHOD_(c,0,"copyall",m_copyall);
FLEXT_CADDMETHOD_(c,0,"cutrec",m_cutrec);
FLEXT_CADDMETHOD_(c,0,"copyrec",m_copyrec);
FLEXT_CADDMETHOD_(c,0,"load",m_load);
FLEXT_CADDMETHOD_(c,0,"save",m_save);
FLEXT_CADDMETHOD_(c,0,"lddir",m_lddir);
FLEXT_CADDMETHOD_(c,0,"ldrec",m_ldrec);
FLEXT_CADDMETHOD_(c,0,"svdir",m_svdir);
FLEXT_CADDMETHOD_(c,0,"svrec",m_svrec);
FLEXT_CADDMETHOD_(c,0,"loadx",m_loadx);
FLEXT_CADDMETHOD_(c,0,"savex",m_savex);
FLEXT_CADDMETHOD_(c,0,"ldxdir",m_ldxdir);
FLEXT_CADDMETHOD_(c,0,"ldxrec",m_ldxrec);
FLEXT_CADDMETHOD_(c,0,"svxdir",m_svxdir);
FLEXT_CADDMETHOD_(c,0,"svxrec",m_svxrec);
}
pool::pool(int argc,const t_atom *argv):
absdir(true),echo(false),
pl(NULL),
clip(NULL),
vcnt(VCNT),dcnt(DCNT)
{
holdname = argc >= 1 && IsSymbol(argv[0])?GetSymbol(argv[0]):NULL;
AddInAnything("Commands in");
AddOutList();
AddOutAnything();
AddOutList();
AddOutAnything();
}
pool::~pool()
{
FreePool();
}
bool pool::Init()
{
if(flext_base::Init()) {
SetPool(holdname);
return true;
}
else return false;
}
void pool::SetPool(const t_symbol *s)
{
if(s) {
if(pl)
// check if new symbol equals the current one
if(pl->sym == s)
return;
else
FreePool();
pl = GetPool(s);
}
else {
if(pl) {
// if already private no need to allocate new storage
if(pl->Private())
return;
else
FreePool();
}
pl = new pooldata(NULL,vcnt,dcnt);
}
}
void pool::FreePool()
{
curdir(); // reset current directory
if(pl) {
if(!pl->Private())
RmvPool(pl);
else
delete pl;
pl = NULL;
}
if(clip) { delete clip; clip = NULL; }
}
void pool::ms_pool(const AtomList &l)
{
const t_symbol *s = NULL;
if(l.Count()) {
if(l.Count() > 1) post("%s - pool: superfluous arguments ignored",thisName());
s = GetASymbol(l[0]);
if(!s) post("%s - pool: invalid pool name, pool set to private",thisName());
}
SetPool(s);
}
void pool::mg_pool(AtomList &l)
{
if(!pl || pl->Private()) l();
else { l(1); SetSymbol(l[0],pl->sym); }
}
void pool::m_reset()
{
curdir();
pl->Reset();
}
void pool::getdir(const t_symbol *tag)
{
ToSysAnything(3,tag,0,NULL);
ToSysList(2,curdir);
}
void pool::m_getdir() { getdir(thisTag()); }
void pool::m_mkdir(int argc,const t_atom *argv,bool abs,bool chg)
{
// const char *nm = chg?"mkchdir":"mkdir";
if(!ValChk(argc,argv))
post("%s - %s: invalid directory name",thisName(),GetString(thisTag()));
else {
Atoms ndir;
if(abs) ndir(argc,argv);
else (ndir = curdir).Append(argc,argv);
if(!pl->MkDir(ndir,vcnt,dcnt)) {
post("%s - %s: directory couldn't be created",thisName(),GetString(thisTag()));
}
else if(chg)
// change to newly created directory
curdir = ndir;
}
echodir();
}
void pool::m_chdir(int argc,const t_atom *argv,bool abs)
{
if(!ValChk(argc,argv))
post("%s - %s: invalid directory name",thisName(),GetString(thisTag()));
else {
Atoms prv(curdir);
if(abs) curdir(argc,argv);
else curdir.Append(argc,argv);
if(!pl->ChkDir(curdir)) {
post("%s - %s: directory couldn't be changed",thisName(),GetString(thisTag()));
curdir = prv;
}
}
echodir();
}
void pool::m_updir(int argc,const t_atom *argv)
{
int lvls = 1;
if(argc > 0) {
if(CanbeInt(argv[0])) {
if(argc > 1)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
lvls = GetAInt(argv[0]);
if(lvls < 0)
post("%s - %s: invalid level specification - set to 1",thisName(),GetString(thisTag()));
}
else
post("%s - %s: invalid level specification - set to 1",thisName(),GetString(thisTag()));
}
Atoms prv(curdir);
if(lvls > curdir.Count()) {
post("%s - %s: level exceeds directory depth - corrected",thisName(),GetString(thisTag()));
curdir();
}
else
curdir.Part(0,curdir.Count()-lvls);
if(!pl->ChkDir(curdir)) {
post("%s - %s: directory couldn't be changed",thisName(),GetString(thisTag()));
curdir = prv;
}
echodir();
}
void pool::m_rmdir(int argc,const t_atom *argv,bool abs)
{
if(abs) curdir(argc,argv);
else curdir.Append(argc,argv);
if(!pl->RmDir(curdir))
post("%s - %s: directory couldn't be removed",thisName(),GetString(thisTag()));
curdir();
echodir();
}
void pool::set(int argc,const t_atom *argv,bool over)
{
if(!argc || !KeyChk(argv[0]))
post("%s - %s: invalid key",thisName(),GetString(thisTag()));
else if(!ValChk(argc-1,argv+1)) {
post("%s - %s: invalid data values",thisName(),GetString(thisTag()));
}
else
if(!pl->Set(curdir,argv[0],new AtomList(argc-1,argv+1),over))
post("%s - %s: value couldn't be set",thisName(),GetString(thisTag()));
echodir();
}
void pool::m_seti(int argc,const t_atom *argv)
{
if(!argc || !CanbeInt(argv[0]))
post("%s - %s: invalid index",thisName(),GetString(thisTag()));
else if(!ValChk(argc-1,argv+1)) {
post("%s - %s: invalid data values",thisName(),GetString(thisTag()));
}
else
if(!pl->Seti(curdir,GetAInt(argv[0]),new Atoms(argc-1,argv+1)))
post("%s - %s: value couldn't be set",thisName(),GetString(thisTag()));
echodir();
}
void pool::m_clr(int argc,const t_atom *argv)
{
if(!argc || !KeyChk(argv[0]))
post("%s - %s: invalid key",thisName(),GetString(thisTag()));
else {
if(argc > 1)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
if(!pl->Clr(curdir,argv[0]))
post("%s - %s: value couldn't be cleared",thisName(),GetString(thisTag()));
}
echodir();
}
void pool::m_clri(int ix)
{
if(ix < 0)
post("%s - %s: invalid index",thisName(),GetString(thisTag()));
else {
if(!pl->Clri(curdir,ix))
post("%s - %s: value couldn't be cleared",thisName(),GetString(thisTag()));
}
echodir();
}
void pool::m_clrall()
{
if(!pl->ClrAll(curdir,false))
post("%s - %s: values couldn't be cleared",thisName(),GetString(thisTag()));
echodir();
}
void pool::m_clrrec()
{
if(!pl->ClrAll(curdir,true))
post("%s - %s: values couldn't be cleared",thisName(),GetString(thisTag()));
echodir();
}
void pool::m_clrsub()
{
if(!pl->ClrAll(curdir,true,true))
post("%s - %s: directories couldn't be cleared",thisName(),GetString(thisTag()));
echodir();
}
void pool::m_get(int argc,const t_atom *argv)
{
if(!argc || !KeyChk(argv[0]))
post("%s - %s: invalid key",thisName(),GetString(thisTag()));
else {
if(argc > 1)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
poolval *r = pl->Ref(curdir,argv[0]);
ToSysAnything(3,thisTag(),0,NULL);
if(absdir)
ToSysList(2,curdir);
else
ToSysList(2,0,NULL);
if(r) {
ToOutAtom(1,r->key);
ToSysList(0,*r->data);
}
else {
ToSysBang(1);
ToSysBang(0);
}
}
echodir();
}
void pool::m_geti(int ix)
{
if(ix < 0)
post("%s - %s: invalid index",thisName(),GetString(thisTag()));
else {
poolval *r = pl->Refi(curdir,ix);
ToSysAnything(3,thisTag(),0,NULL);
if(absdir)
ToSysList(2,curdir);
else
ToSysList(2,0,NULL);
if(r) {
ToOutAtom(1,r->key);
ToSysList(0,*r->data);
}
else {
ToSysBang(1);
ToSysBang(0);
}
}
echodir();
}
// ---- some sorting stuff ----------------------------------
inline bool smaller(const t_atom &a,const t_atom &b,int index) { return a < b; }
inline void swap(t_atom &a,t_atom &b) { t_atom c = a; a = b; b = c; }
inline bool smaller(const t_atom *a,const t_atom *b,int index) { return *a < *b; }
inline void swap(t_atom *a,t_atom *b) { t_atom *c = a; a = b; b = c; }
inline bool smaller(const Atoms &a,const Atoms &b,int index)
{
if(a.Count()-1 < index)
return true;
else if(b.Count()-1 < index)
return false;
else
return a[index] < b[index];
}
inline void swap(Atoms &a,Atoms &b) { Atoms c(a); a = b; b = c; }
inline bool smaller(const Atoms *a,const Atoms *b,int index) { return smaller(*a,*b,index); }
inline void swap(Atoms *a,Atoms *b) { Atoms *c = a; a = b; b = c; }
template <typename T1,typename T2>
void sift(T1 *a,T2 *b,int start,int count,int index,bool rev)
{
int root = start; // Point to a root node
int child;
while((child = root * 2 + 1) < count) { // While the root has child(ren) point to its left child
// If the child has a sibling and the child's value is less than its sibling's...
if(child < count-1 && smaller(a[child],a[child+1],index) != rev)
child++; // ... point to the right child instead
if(smaller(a[root],a[child],index) == rev) break;
// If the value in root is less than in child...
swap(a[root], a[child]); // ... swap the values in root and child and...
if(b) swap(b[root], b[child]);
root = child; // ... make root point to its child
}
}
template <typename T1,typename T2>
void heapsort(T1 *a,T2 *b,int count,int index,bool rev)
{
int start = count/2-1;
int end = count-1;
for(; start >= 0; start--)
sift(a, b, start, count, index, rev);
for(; end > 0; --end) {
swap(a[end], a[0]);
if(b) swap(b[end], b[0]);
sift(a, b, 0, end, index, rev);
}
}
template <typename T1,typename T2>
static void orderpairs(T1 *keys,T2 *atoms,int count,int index,bool rev)
{
FLEXT_ASSERT(index >= 0);
if(!count) return;
if(index)
heapsort(atoms,keys,count,index-1,rev);
else
heapsort(keys,atoms,count,0,rev);
}
// ---- sorting stuff ends ----------------------------------
int pool::getrec(const t_symbol *tag,int level,int order,bool rev,get_t how,const AtomList &rdir)
{
Atoms gldir(curdir);
gldir.Append(rdir);
int ret = 0;
switch(how) {
case get_cnt:
ret = pl->CntAll(gldir);
break;
case get_print:
ret = pl->PrintAll(gldir);
break;
case get_norm: {
t_atom *k;
Atoms *r;
int cnt = pl->GetAll(gldir,k,r);
if(!k) {
FLEXT_ASSERT(!k);
post("%s - %s: error retrieving values",thisName(),GetString(tag));
}
else {
FLEXT_ASSERT(r);
if(order >= 0)
orderpairs(k,r,cnt,order,rev);
for(int i = 0; i < cnt; ++i) {
ToSysAnything(3,tag,0,NULL);
ToSysList(2,absdir?gldir:rdir);
ToOutAtom(1,k[i]);
ToSysList(0,r[i]);
}
delete[] k;
delete[] r;
}
ret = cnt;
}
}
if(level != 0) {
const t_atom **r;
int cnt = pl->GetSub(gldir,r);
if(!r)
post("%s - %s: error retrieving directories",thisName(),GetString(tag));
else {
if(order >= 0)
orderpairs(r,(Atoms *)NULL,cnt,order,rev);
int lv = level > 0?level-1:-1;
for(int i = 0; i < cnt; ++i) {
Atoms l(rdir); l.Append(*r[i]);
ret += getrec(tag,lv,order,rev,how,l);
}
delete[] r;
}
}
return ret;
}
void pool::m_getall()
{
AtomList l;
getrec(thisTag(),0,-1,false,get_norm,l);
ToSysBang(3);
echodir();
}
void pool::m_ogetall(int argc,const t_atom *argv)
{
int index = 0;
if(argc) {
if(!CanbeInt(*argv) || (index = GetAInt(*argv)) < 0) {
index = 0;
post("%s - %s: invalid sort index specification - set to 0",thisName(),GetString(thisTag()));
}
--argc,++argv;
}
bool rev = false;
if(argc) {
if(!CanbeBool(*argv))
post("%s - %s: invalid sort direction specification - set to forward",thisName(),GetString(thisTag()));
else
rev = GetABool(*argv);
--argc,++argv;
}
if(argc)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
AtomList l;
getrec(thisTag(),0,index,rev,get_norm,l);
ToSysBang(3);
echodir();
}
void pool::m_getrec(int argc,const t_atom *argv)
{
int lvls = -1;
if(argc) {
if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) {
lvls = -1;
post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls);
}
--argc,++argv;
}
if(argc)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
AtomList l;
getrec(thisTag(),lvls,-1,false,get_norm,l);
ToSysBang(3);
echodir();
}
void pool::m_ogetrec(int argc,const t_atom *argv)
{
int lvls = -1;
if(argc) {
if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) {
lvls = -1;
post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls);
}
--argc,++argv;
}
int index = 0;
if(argc) {
if(!CanbeInt(*argv) || (index = GetAInt(*argv)) < 0) {
index = 0;
post("%s - %s: invalid sort index specification - set to 0",thisName(),GetString(thisTag()));
}
--argc,++argv;
}
bool rev = false;
if(argc) {
if(!CanbeBool(*argv))
post("%s - %s: invalid sort direction specification - set to forward",thisName(),GetString(thisTag()));
else
rev = GetABool(*argv);
--argc,++argv;
}
if(argc)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
AtomList l;
getrec(thisTag(),lvls,index,rev,get_norm,l);
ToSysBang(3);
echodir();
}
int pool::getsub(const t_symbol *tag,int level,int order,bool rev,get_t how,const AtomList &rdir)
{
Atoms gldir(curdir);
gldir.Append(rdir);
int ret = 0;
const t_atom **r = NULL;
// CntSub is not used here because it doesn't allow checking for valid directory
int cnt = pl->GetSub(gldir,r);
if(!r)
post("%s - %s: error retrieving directories",thisName(),GetString(tag));
else {
if(order >= 0)
orderpairs(r,(Atoms *)NULL,cnt,order,rev);
int lv = level > 0?level-1:-1;
for(int i = 0; i < cnt; ++i) {
Atoms ndir(absdir?gldir:rdir);
ndir.Append(*r[i]);
++ret;
if(how == get_norm) {
ToSysAnything(3,tag,0,NULL);
ToSysList(2,curdir);
ToSysList(1,ndir);
ToSysBang(0);
}
if(level != 0) {
AtomList l(rdir); l.Append(*r[i]);
ret += getsub(tag,lv,order,rev,how,l);
}
}
delete[] r;
}
return ret;
}
void pool::m_getsub(int argc,const t_atom *argv)
{
int lvls = 0;
if(argc) {
if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) {
lvls = 0;
post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls);
}
--argc,++argv;
}
if(argc)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
AtomList l;
getsub(thisTag(),lvls,-1,false,get_norm,l);
ToSysBang(3);
echodir();
}
void pool::m_ogetsub(int argc,const t_atom *argv)
{
int lvls = 0;
if(argc) {
if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) {
lvls = 0;
post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls);
}
--argc,++argv;
}
int index = 0;
if(argc) {
if(!CanbeInt(*argv) || (index = GetAInt(*argv)) < 0) {
index = 0;
post("%s - %s: invalid sort index specification - set to 0",thisName(),GetString(thisTag()));
}
--argc,++argv;
}
bool rev = false;
if(argc) {
if(!CanbeBool(*argv))
post("%s - %s: invalid sort direction specification - set to forward",thisName(),GetString(thisTag()));
else
rev = GetABool(*argv);
--argc,++argv;
}
if(argc)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
AtomList l;
getsub(thisTag(),lvls,index,rev,get_norm,l);
ToSysBang(3);
echodir();
}
void pool::m_cntall()
{
AtomList l;
int cnt = getrec(thisTag(),0,-1,false,get_cnt,l);
ToSysSymbol(3,thisTag());
ToSysBang(2);
ToSysBang(1);
ToSysInt(0,cnt);
echodir();
}
void pool::m_cntrec(int argc,const t_atom *argv)
{
int lvls = -1;
if(argc) {
if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) {
lvls = -1;
post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls);
}
--argc,++argv;
}
if(argc)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
AtomList l;
int cnt = getrec(thisTag(),lvls,-1,false,get_cnt,l);
ToSysSymbol(3,thisTag());
ToSysBang(2);
ToSysBang(1);
ToSysInt(0,cnt);
echodir();
}
void pool::m_cntsub(int argc,const t_atom *argv)
{
int lvls = 0;
if(argc) {
if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) {
lvls = 0;
post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls);
}
--argc,++argv;
}
if(argc)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
AtomList l;
int cnt = getsub(thisTag(),lvls,-1,false,get_cnt,l);
ToSysSymbol(3,thisTag());
ToSysBang(2);
ToSysBang(1);
ToSysInt(0,cnt);
echodir();
}
void pool::m_printall()
{
AtomList l;
int cnt = getrec(thisTag(),0,-1,false,get_print,l);
post("");
}
void pool::m_printrec(int argc,const t_atom *argv,bool fromroot)
{
const t_symbol *tag = thisTag();
int lvls = -1;
if(argc) {
if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) {
lvls = 0;
post("%s - %s: invalid level specification - set to %i",thisName(),GetString(tag),lvls);
}
--argc,++argv;
}
if(argc)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(tag));
Atoms svdir(curdir);
if(fromroot) curdir.Clear();
AtomList l;
int cnt = getrec(tag,lvls,-1,false,get_print,l);
post("");
curdir = svdir;
}
void pool::paste(const t_symbol *tag,int argc,const t_atom *argv,bool repl)
{
if(clip) {
bool mkdir = true;
int depth = -1;
if(argc >= 1) {
if(CanbeInt(argv[0])) depth = GetAInt(argv[1]);
else
post("%s - %s: invalid depth argument - set to -1",thisName(),GetString(tag));
if(argc >= 2) {
if(CanbeBool(argv[1])) mkdir = GetABool(argv[1]);
else
post("%s - %s: invalid mkdir argument - set to true",thisName(),GetString(tag));
if(argc > 2) post("%s - %s: superfluous arguments ignored",thisName(),GetString(tag));
}
}
pl->Paste(curdir,clip,depth,repl,mkdir);
}
else
post("%s - %s: clipboard is empty",thisName(),GetString(tag));
echodir();
}
void pool::m_clrclip()
{
if(clip) { delete clip; clip = NULL; }
}
void pool::copy(const t_symbol *tag,int argc,const t_atom *argv,bool cut)
{
if(!argc || !KeyChk(argv[0]))
post("%s - %s: invalid key",thisName(),GetString(tag));
else {
if(argc > 1)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(tag));
m_clrclip();
clip = pl->Copy(curdir,argv[0],cut);
if(!clip)
post("%s - %s: Copying into clipboard failed",thisName(),GetString(tag));
}
echodir();
}
void pool::copyall(const t_symbol *tag,bool cut,int depth)
{
m_clrclip();
clip = pl->CopyAll(curdir,depth,cut);
if(!clip)
post("%s - %s: Copying into clipboard failed",thisName(),GetString(tag));
echodir();
}
void pool::copyrec(const t_symbol *tag,int argc,const t_atom *argv,bool cut)
{
int lvls = -1;
if(argc > 0) {
if(CanbeInt(argv[0])) {
if(argc > 1)
post("%s - %s: superfluous arguments ignored",thisName(),GetString(tag));
lvls = GetAInt(argv[0]);
}
else
post("%s - %s: invalid level specification - set to infinite",thisName(),GetString(tag));
}
copyall(tag,cut,lvls);
}
void pool::load(int argc,const t_atom *argv,bool xml)
{
const char *flnm = NULL;
if(argc > 0) {
if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
if(IsString(argv[0])) flnm = GetString(argv[0]);
}
bool ok = false;
if(!flnm)
post("%s - %s: no filename given",thisName(),GetString(thisTag()));
else {
string file(MakeFilename(flnm));
ok = xml?pl->LoadXML(file.c_str()):pl->Load(file.c_str());
if(!ok)
post("%s - %s: error loading data",thisName(),GetString(thisTag()));
}
t_atom at; SetBool(at,ok);
ToOutAnything(GetOutAttr(),thisTag(),1,&at);
echodir();
}
void pool::save(int argc,const t_atom *argv,bool xml)
{
const char *flnm = NULL;
if(argc > 0) {
if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
if(IsString(argv[0])) flnm = GetString(argv[0]);
}
bool ok = false;
if(!flnm)
post("%s - %s: no filename given",thisName(),GetString(thisTag()));
else {
string file(MakeFilename(flnm));
ok = xml?pl->SaveXML(file.c_str()):pl->Save(file.c_str());
if(!ok)
post("%s - %s: error saving data",thisName(),GetString(thisTag()));
}
t_atom at; SetBool(at,ok);
ToOutAnything(GetOutAttr(),thisTag(),1,&at);
echodir();
}
void pool::lddir(int argc,const t_atom *argv,bool xml)
{
const char *flnm = NULL;
if(argc > 0) {
if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
if(IsString(argv[0])) flnm = GetString(argv[0]);
}
bool ok = false;
if(!flnm)
post("%s - %s: invalid filename",thisName(),GetString(thisTag()));
else {
string file(MakeFilename(flnm));
ok = xml?pl->LdDirXML(curdir,file.c_str(),0):pl->LdDir(curdir,file.c_str(),0);
if(!ok)
post("%s - %s: directory couldn't be loaded",thisName(),GetString(thisTag()));
}
t_atom at; SetBool(at,ok);
ToOutAnything(GetOutAttr(),thisTag(),1,&at);
echodir();
}
void pool::ldrec(int argc,const t_atom *argv,bool xml)
{
const char *flnm = NULL;
int depth = -1;
bool mkdir = true;
if(argc >= 1) {
if(IsString(argv[0])) flnm = GetString(argv[0]);
if(argc >= 2) {
if(CanbeInt(argv[1])) depth = GetAInt(argv[1]);
else
post("%s - %s: invalid depth argument - set to -1",thisName(),GetString(thisTag()));
if(argc >= 3) {
if(CanbeBool(argv[2])) mkdir = GetABool(argv[2]);
else
post("%s - %s: invalid mkdir argument - set to true",thisName(),GetString(thisTag()));
if(argc > 3) post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
}
}
}
bool ok = false;
if(!flnm)
post("%s - %s: invalid filename",thisName(),GetString(thisTag()));
else {
string file(MakeFilename(flnm));
ok = xml?pl->LdDirXML(curdir,file.c_str(),depth,mkdir):pl->LdDir(curdir,file.c_str(),depth,mkdir);
if(!ok)
post("%s - %s: directory couldn't be saved",thisName(),GetString(thisTag()));
}
t_atom at; SetBool(at,ok);
ToOutAnything(GetOutAttr(),thisTag(),1,&at);
echodir();
}
void pool::svdir(int argc,const t_atom *argv,bool xml)
{
const char *flnm = NULL;
if(argc > 0) {
if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
if(IsString(argv[0])) flnm = GetString(argv[0]);
}
bool ok = false;
if(!flnm)
post("%s - %s: invalid filename",thisName(),GetString(thisTag()));
else {
string file(MakeFilename(flnm));
ok = xml?pl->SvDirXML(curdir,file.c_str(),0,absdir):pl->SvDir(curdir,file.c_str(),0,absdir);
if(!ok)
post("%s - %s: directory couldn't be saved",thisName(),GetString(thisTag()));
}
t_atom at; SetBool(at,ok);
ToOutAnything(GetOutAttr(),thisTag(),1,&at);
echodir();
}
void pool::svrec(int argc,const t_atom *argv,bool xml)
{
const char *flnm = NULL;
if(argc > 0) {
if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag()));
if(IsString(argv[0])) flnm = GetString(argv[0]);
}
bool ok = false;
if(!flnm)
post("%s - %s: invalid filename",thisName(),GetString(thisTag()));
else {
string file(MakeFilename(flnm));
ok = xml?pl->SvDirXML(curdir,file.c_str(),-1,absdir):pl->SvDir(curdir,file.c_str(),-1,absdir);
if(!ok)
post("%s - %s: directory couldn't be saved",thisName(),GetString(thisTag()));
}
t_atom at; SetBool(at,ok);
ToOutAnything(GetOutAttr(),thisTag(),1,&at);
echodir();
}
bool pool::KeyChk(const t_atom &a)
{
return IsSymbol(a) || IsFloat(a) || IsInt(a);
}
bool pool::ValChk(int argc,const t_atom *argv)
{
for(int i = 0; i < argc; ++i) {
const t_atom &a = argv[i];
if(!IsSymbol(a) && !IsFloat(a) && !IsInt(a)) return false;
}
return true;
}
void pool::ToOutAtom(int ix,const t_atom &a)
{
if(IsSymbol(a))
ToSysSymbol(ix,GetSymbol(a));
else if(IsFloat(a))
ToSysFloat(ix,GetFloat(a));
else if(IsInt(a))
ToSysInt(ix,GetInt(a));
else
post("%s - %s type not supported!",thisName(),GetString(thisTag()));
}
pooldata *pool::GetPool(const t_symbol *s)
{
PoolMap::iterator it = poolmap.find(s);
pooldata *p;
if(it != poolmap.end())
p = it->second;
else
poolmap[s] = p = new pooldata(s);
p->Push();
return p;
}
void pool::RmvPool(pooldata *p)
{
FLEXT_ASSERT(p->sym);
PoolMap::iterator it = poolmap.find(p->sym);
FLEXT_ASSERT(it != poolmap.end());
FLEXT_ASSERT(p == it->second);
if(!p->Pop()) {
poolmap.erase(it);
delete p;
}
}
string pool::MakeFilename(const char *fn) const
{
#if FLEXT_SYS == FLEXT_SYS_PD
// / and \ must not be mixed!
// (char *) type casts for BorlandC++
char *sl = strchr((char *)fn,'/');
if(!sl) sl = strchr((char *)fn,'\\');
if(!sl || (sl != fn
#if FLEXT_OS == FLEXT_OS_WIN
&& sl[-1] != ':' // look for drive specification with ":/" or ":\\"
#endif
)) {
// prepend absolute canvas path if filename has no absolute path
const char *p = GetString(canvas_getdir(thisCanvas()));
return string(p)+'/'+fn;
}
else
return fn;
#else
#pragma message("Relative file paths not implemented")
return fn;
#endif
}
|