00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef O2SCL_COLLECTION_H
00024 #define O2SCL_COLLECTION_H
00025
00026 #include <iostream>
00027 #include <fstream>
00028 #include <string>
00029 #include <vector>
00030 #include <map>
00031 #include <set>
00032 #include <sstream>
00033 #include <o2scl/misc.h>
00034 #include <o2scl/err_hnd.h>
00035 #include <o2scl/test_mgr.h>
00036 #include <o2scl/text_file.h>
00037 #include <o2scl/file_format.h>
00038 #include <o2scl/file_detect.h>
00039 #include <o2scl/ovector_tlate.h>
00040 #include <o2scl/omatrix_tlate.h>
00041 #include <o2scl/ovector_cx_tlate.h>
00042 #include <o2scl/omatrix_cx_tlate.h>
00043
00044
00045
00046
00047 #ifndef DOXYGENP
00048 namespace o2scl {
00049 #endif
00050
00051
00052 typedef struct {
00053
00054 void *data;
00055
00056 int size;
00057
00058 int size2;
00059
00060 bool owner;
00061
00062 class io_base *iop;
00063 } collection_entry;
00064
00065
00066 typedef struct {
00067
00068 std::string name;
00069
00070 collection_entry *ep;
00071
00072 bool output;
00073 } pointer_output;
00074
00075
00076 typedef struct {
00077
00078 std::string name;
00079
00080 void **ptr;
00081
00082 std::string stype;
00083 } pointer_input;
00084
00085 class cinput;
00086 class coutput;
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 class io_base {
00099
00100 #ifndef DOXYGEN_INTERNAL
00101
00102 protected:
00103
00104 friend class io_type_info;
00105
00106
00107 friend class collection;
00108
00109 friend class cinput;
00110 friend class coutput;
00111 friend class io_manager;
00112
00113
00114 static class io_manager *iom;
00115
00116
00117 static int objs_count;
00118
00119
00120 virtual int stat_in_noobj(cinput *co, in_file_format *ins);
00121
00122
00123 virtual int stat_out_noobj(coutput *co, out_file_format *outs);
00124
00125
00126
00127 virtual int in_wrapper(cinput *co, in_file_format *ins, void *&vp);
00128
00129
00130
00131 virtual int in_wrapper(cinput *co, in_file_format *ins, void *&vp,
00132 int &sz);
00133
00134
00135
00136 virtual int in_wrapper(cinput *co, in_file_format *ins, void *&vp,
00137 int &sz, int &sz2);
00138
00139
00140
00141
00142 virtual int out_wrapper(coutput *co, out_file_format *outs,
00143 void *vp, int sz, int sz2);
00144
00145
00146 virtual int object_in_void(cinput *cin, in_file_format *ins, void *op,
00147 std::string &name);
00148
00149
00150 virtual int object_in_void(cinput *cin, in_file_format *ins, void *op,
00151 int sz, std::string &name);
00152
00153
00154 virtual int object_in_void(cinput *cin, in_file_format *ins, void *op,
00155 int sz, int sz2, std::string &name);
00156
00157
00158 virtual int object_in_mem_void(cinput *cin, in_file_format *ins,
00159 void *&op, std::string &name);
00160
00161
00162 virtual int object_in_mem_void(cinput *cin, in_file_format *ins,
00163 void *&op, int &sz, std::string &name);
00164
00165
00166 virtual int object_in_mem_void(cinput *cin, in_file_format *ins,
00167 void *&op, int &sz, int &sz2,
00168 std::string &name);
00169
00170
00171 virtual int object_out_void(coutput *cout, out_file_format *outs,
00172 void *op, int sz, int sz2,
00173 std::string name="");
00174
00175
00176
00177
00178 int sw_store;
00179
00180
00181
00182
00183
00184 virtual int remove(void *vp) { return 0; }
00185
00186
00187 virtual int remove_arr(void *vp) {
00188 return 0;
00189 }
00190
00191
00192 virtual int remove_2darr(void *vp, int sz) { return 0; }
00193
00194
00195 #endif
00196
00197 public:
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 io_base(int sw=0);
00210
00211
00212
00213
00214 io_base(const char *t);
00215
00216 virtual ~io_base();
00217
00218
00219
00220
00221 virtual const char *type() { return "io_base"; }
00222
00223
00224 virtual bool has_static_data() { return false; }
00225
00226
00227
00228
00229
00230
00231 virtual int pointer_in(cinput *co, in_file_format *ins, void **pp,
00232 std::string &stype);
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 virtual int pointer_out(coutput *co, out_file_format *outs, void *ptr,
00244 std::string stype);
00245
00246
00247 };
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 class io_manager {
00258
00259 public:
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 int add_type(io_base *iop);
00270
00271
00272 int is_type(io_base *iop);
00273
00274
00275 int add_type(io_base *iop, const char *t);
00276
00277
00278 int remove_type(io_base *iop);
00279
00280 #ifndef DOXYGEN_INTERNAL
00281
00282 protected:
00283
00284
00285 friend class io_base;
00286
00287
00288 friend class collection;
00289
00290
00291 friend class cinput;
00292
00293
00294 friend class coutput;
00295
00296
00297 friend class io_type_info;
00298
00299
00300 io_base *get_ptr(std::string stype);
00301
00302
00303 std::vector<io_base *> tlist;
00304
00305
00306 typedef std::vector<io_base *>::iterator titer;
00307
00308
00309 io_manager() {};
00310
00311 #endif
00312
00313 };
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 class io_type_info : public io_base {
00325
00326 #ifndef DOXYGEN_INTERNAL
00327
00328 protected:
00329
00330
00331 friend class collection;
00332
00333
00334 int static_fout(coutput *co, out_file_format *out);
00335
00336
00337 int static_fout_restricted(coutput *co, out_file_format *out,
00338 std::set<std::string,string_comp> list);
00339
00340
00341 typedef std::vector<io_base *>::iterator titer;
00342
00343 #endif
00344
00345 public:
00346
00347 io_type_info();
00348
00349 virtual ~io_type_info();
00350
00351
00352
00353
00354
00355
00356 int is_type(std::string stype);
00357
00358
00359
00360
00361
00362
00363
00364
00365 int remove_type(std::string stype);
00366
00367
00368
00369
00370
00371
00372
00373 virtual int clear_types();
00374
00375
00376 void type_summary(std::ostream *outs, bool pointers=false);
00377
00378
00379 int add_type(io_base *iop) { return iom->add_type(iop); }
00380
00381
00382 };
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 class collection : public io_base {
00458
00459 #ifndef DOXYGEN_INTERNAL
00460
00461 protected:
00462
00463 friend class io_base;
00464 friend class cinput;
00465 friend class coutput;
00466
00467
00468 typedef std::map<std::string,collection_entry,string_comp>::iterator
00469 piter;
00470
00471
00472 std::map<std::string,collection_entry,string_comp> plist;
00473
00474 #endif
00475
00476 public:
00477
00478 collection() : io_base(1) {
00479 };
00480 ~collection();
00481
00482
00483
00484
00485
00486 int fout(out_file_format *outs);
00487
00488
00489 int fout(std::string filename);
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 int fin(std::string file_name, bool overwrt=false, int verbose=0);
00503
00504
00505 int fin(in_file_format *ins, bool overwrt=false, int verbose=0);
00506
00507
00508
00509
00510
00511
00512
00513 int test_type(o2scl::test_mgr &t, std::string stype, void *obj,
00514 void *&newobj, bool scrout=false);
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525 int rewrite(std::string in_name, std::string out_name);
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536 int disown(std::string name);
00537
00538
00539
00540 int summary(std::ostream *out, bool show_addresses=false);
00541
00542
00543
00544
00545
00546
00547
00548 int remove(std::string name);
00549
00550
00551
00552 void clear();
00553
00554
00555
00556 int npa();
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569 int add(std::string name, io_base *tio, void *vec, int sz=0, int sz2=0,
00570 bool overwrt=true, bool owner=false);
00571
00572 int add(std::string name, std::string stype,
00573 void *vec, int sz=0, int sz2=0,
00574 bool overwrt=true, bool owner=false);
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584 int get(std::string tname, void *&vec);
00585
00586
00587
00588 int get(std::string tname, void *&vec, int &sz);
00589
00590
00591
00592 int get(std::string tname, void *&vec, int &sz, int &sz2);
00593
00594
00595
00596 int get(std::string tname, std::string &stype, void *&vec);
00597
00598
00599
00600 int get(std::string tname, std::string &stype, void *&vec, int &sz);
00601
00602
00603
00604 int get(std::string tname, std::string &stype, void *&vec, int &sz,
00605 int &sz2);
00606
00607
00608
00609 void *get(std::string name) {
00610 void *vp;
00611 get(name,vp);
00612 return vp;
00613 }
00614
00615
00616
00617 int get_type(text_out_file &tof, std::string stype, std::string name);
00618
00619
00620 int get(text_out_file &tof, std::string &stype, std::string name);
00621
00622
00623 int set(std::string name, text_in_file &tif);
00624
00625
00626 int set(std::string name, std::string val);
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 int out_one(out_file_format *outs, std::string stype, std::string name,
00638 void *vp, int sz=0, int sz2=0);
00639
00640
00641
00642
00643
00644
00645
00646
00647 int out_one(std::string fname, std::string stype, std::string name,
00648 void *vp, int sz=0, int sz2=0);
00649
00650
00651
00652
00653
00654
00655
00656
00657 int in_one_name(in_file_format *ins, std::string stype, std::string name,
00658 void *&vp, int &sz, int &sz2);
00659
00660
00661
00662
00663
00664
00665
00666
00667 int in_one(in_file_format *ins, std::string stype, std::string &name,
00668 void *&vp, int &sz, int &sz2);
00669
00670
00671
00672
00673
00674
00675
00676
00677 int in_one(std::string fname, std::string stype, std::string &name,
00678 void *&vp, int &sz, int &sz2);
00679
00680
00681
00682
00683
00684 class iterator {
00685
00686 #ifndef DOXYGEN_INTERNAL
00687
00688 protected:
00689
00690 friend class collection;
00691
00692
00693 iterator(piter p) { pit=p; }
00694
00695
00696 piter pit;
00697
00698 #endif
00699
00700 public:
00701
00702
00703 iterator operator++() {
00704 pit++;
00705 return *this;
00706 }
00707
00708
00709 iterator operator++(int unused) {
00710 pit++;
00711 return *this;
00712 }
00713
00714
00715 iterator operator--() {
00716 pit--;
00717 return *this;
00718 }
00719
00720
00721 collection_entry *operator->() const {
00722 return &(pit->second);
00723 };
00724
00725
00726 std::string name() {
00727 return pit->first;
00728 }
00729
00730 friend int operator==(const iterator &i1, const iterator &i2);
00731
00732 friend int operator!=(const iterator &i1, const iterator &i2);
00733
00734 };
00735
00736
00737
00738
00739
00740 class type_iterator {
00741
00742 #ifndef DOXYGEN_INTERNAL
00743
00744 protected:
00745
00746 friend class collection;
00747
00748
00749 std::string ltype;
00750
00751
00752 collection *lcop;
00753
00754
00755 type_iterator(piter p, std::string type, collection *cop) {
00756 pit=p;
00757 ltype=type;
00758 lcop=cop;
00759 while (pit!=lcop->plist.end() &&
00760 pit->second.iop->type()!=ltype) pit++;
00761 }
00762
00763
00764 piter pit;
00765
00766 #endif
00767
00768 public:
00769
00770
00771 type_iterator operator++() {
00772 if (pit!=lcop->plist.end()) pit++;
00773 while (pit!=lcop->plist.end() &&
00774 pit->second.iop->type()!=ltype) pit++;
00775 return *this;
00776 }
00777
00778
00779 type_iterator operator++(int unused) {
00780 if (pit!=lcop->plist.end()) pit++;
00781 while (pit!=lcop->plist.end() &&
00782 pit->second.iop->type()!=ltype) pit++;
00783 return *this;
00784 }
00785
00786
00787 collection_entry *operator->() const {
00788 return &(pit->second);
00789 };
00790
00791
00792 std::string name() {
00793 return pit->first;
00794 }
00795
00796 friend int operator==(const type_iterator &i1, const type_iterator &i2);
00797
00798 friend int operator!=(const type_iterator &i1, const type_iterator &i2);
00799
00800 };
00801
00802
00803
00804
00805
00806 iterator begin() {
00807 return iterator(plist.begin());
00808 }
00809
00810
00811 iterator end() {
00812 return iterator(plist.end());
00813 }
00814
00815
00816
00817
00818 type_iterator begin(std::string utype) {
00819 return type_iterator(plist.begin(),utype,this);
00820 }
00821
00822
00823 type_iterator end(std::string utype) {
00824 return type_iterator(plist.end(),utype,this);
00825 }
00826
00827
00828 };
00829
00830
00831
00832
00833
00834 int operator==(const collection::iterator &i1,
00835 const collection::iterator &i2);
00836
00837
00838 int operator!=(const collection::iterator &i1,
00839 const collection::iterator &i2);
00840
00841
00842 int operator==(const collection::type_iterator &i1,
00843 const collection::type_iterator &i2);
00844
00845
00846 int operator!=(const collection::type_iterator &i1,
00847 const collection::type_iterator &i2);
00848
00849
00850
00851
00852
00853
00854 class cinput {
00855
00856 public:
00857
00858
00859 int object_in(std::string type, in_file_format *ins, void *vp,
00860 std::string &name);
00861
00862
00863 int object_in(std::string type, in_file_format *ins, void *vp,
00864 int sz, std::string &name);
00865
00866
00867 int object_in(std::string type, in_file_format *ins, void *vp,
00868 int sz, int sz2, std::string &name);
00869
00870
00871 int object_in_mem(std::string type, in_file_format *ins, void *&vp,
00872 std::string &name);
00873
00874
00875 int object_in_mem(std::string type, in_file_format *ins, void *&vp,
00876 int &sz, std::string &name);
00877
00878
00879 int object_in_mem(std::string type, in_file_format *ins, void *&vp,
00880 int &sz, int &sz2, std::string &name);
00881
00882 #ifndef DOXYGEN_INTERNAL
00883
00884 protected:
00885
00886
00887 cinput(collection *co) {
00888 cop=co;
00889 }
00890
00891 friend class collection;
00892 friend class io_base;
00893
00894
00895 std::vector<pointer_input> input_ptrs;
00896
00897
00898 typedef std::vector<pointer_input>::iterator ipiter;
00899
00900
00901 int assign_pointers(collection *co);
00902
00903
00904 collection *cop;
00905
00906 #endif
00907
00908 };
00909
00910
00911
00912
00913
00914
00915 class coutput {
00916
00917 public:
00918
00919
00920 int object_out(std::string type, out_file_format *outs,
00921 void *op, int sz=0, int sz2=0, std::string name="");
00922
00923 #ifndef DOXYGEN_INTERNAL
00924
00925 protected:
00926
00927 friend class collection;
00928 friend class io_base;
00929
00930
00931 coutput(class collection *co) {
00932 cop=co;
00933 npointers=0;
00934 };
00935
00936
00937 struct ltptr {
00938
00939 bool operator()(const void * p1, const void * p2) const {
00940 return p1<p2;
00941 }
00942 };
00943
00944
00945 std::map<void *,pointer_output,ltptr> ptr_map;
00946
00947
00948 typedef std::map<void *,pointer_output,ltptr>::iterator pmiter;
00949
00950
00951
00952
00953
00954
00955
00956 int pointer_lookup(void *vp, std::string &name, collection_entry *&ep);
00957
00958
00959 collection *cop;
00960
00961
00962 int pointer_map_fout(out_file_format *out);
00963
00964
00965
00966
00967
00968
00969
00970
00971 int npointers;
00972
00973 #endif
00974
00975 };
00976
00977
00978
00979
00980
00981
00982
00983 template <class object> class io_vtlate : public io_base {
00984
00985 public:
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995 virtual const char *type() { return "io_tlate"; }
00996
00997
00998 virtual int input(cinput *cin, in_file_format *ins, object *op)
00999 { return 0; }
01000
01001
01002
01003 virtual int output(coutput *cout, out_file_format *outs, object *op)
01004 { return 0; }
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 virtual bool has_static_data() { return false; }
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034 virtual int stat_input(cinput *cin, in_file_format *ins, object *op)
01035 { return 0; }
01036
01037
01038
01039
01040 virtual int stat_output(coutput *cout, out_file_format *outs,
01041 object *op)
01042 { return 0; }
01043
01044 };
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059 template <class object> class io_tlate : public io_base {
01060
01061 public:
01062
01063
01064 io_tlate() : io_base() {};
01065
01066
01067
01068
01069
01070 io_tlate(const char *t) : io_base(t) {};
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080 virtual const char *type() { return "io_tlate"; }
01081
01082
01083 virtual int input(cinput *cin, in_file_format *ins, object *op)
01084 { return 0; }
01085
01086
01087
01088 virtual int output(coutput *cout, out_file_format *outs, object *op)
01089 { return 0; }
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101 virtual bool has_static_data() { return false; }
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119 virtual int stat_input(cinput *cin, in_file_format *ins, object *op)
01120 { return 0; }
01121
01122
01123
01124
01125 virtual int stat_output(coutput *cout, out_file_format *outs,
01126 object *op)
01127 { return 0; }
01128
01129
01130 #ifndef DOXYGEN_INTERNAL
01131
01132 protected:
01133
01134 virtual int object_in_void(cinput *cin, in_file_format *ins, void *op,
01135 std::string &name) {
01136 return object_in(cin,ins,(object *)op,name);
01137 }
01138
01139 virtual int object_in_void(cinput *cin, in_file_format *ins, void *op,
01140 int sz, std::string &name) {
01141 return object_in(cin,ins,(object *)op,sz,name);
01142 }
01143
01144 virtual int object_in_void(cinput *cin, in_file_format *ins, void *op,
01145 int sz, int sz2, std::string &name) {
01146 return object_in(cin,ins,(object **)op,sz,sz2,name);
01147 }
01148
01149 virtual int object_in_mem_void(cinput *cin, in_file_format *ins,
01150 void *&vp, std::string &name) {
01151 object *op;
01152 int ret=object_in_mem(cin,ins,op,name);
01153 vp=(void *)op;
01154 return ret;
01155 }
01156
01157 virtual int object_in_mem_void(cinput *cin, in_file_format *ins, void *&vp,
01158 int &sz,std::string &name) {
01159 object *op;
01160 int ret=object_in_mem(cin,ins,op,sz,name);
01161 vp=(void *)op;
01162 return ret;
01163 }
01164
01165 virtual int object_in_mem_void(cinput *cin, in_file_format *ins, void *&vp,
01166 int &sz, int &sz2, std::string &name) {
01167 object **op;
01168 int ret=object_in_mem(cin,ins,op,sz,sz2,name);
01169 vp=(void *)op;
01170 return ret;
01171 }
01172
01173 virtual int object_out_void(coutput *cout, out_file_format *outs,
01174 void *op, int sz=0, int sz2=0,
01175 std::string name="") {
01176 if (sz2==0) {
01177 return object_out(cout,outs,(object *)op,sz,name);
01178 }
01179 return object_out(cout,outs,(object **)op,sz,sz2,name);
01180 }
01181
01182 virtual int stat_in_noobj(cinput *cin, in_file_format *ins) {
01183 int ret;
01184 object *op=new object;
01185 ret=stat_input(cin,ins,op);
01186 return ret;
01187 };
01188
01189 virtual int stat_out_noobj(coutput *cout, out_file_format *outs) {
01190 int ret;
01191 object *op=new object;
01192 ret=stat_output(cout,outs,op);
01193 return ret;
01194 };
01195
01196 int in_wrapper(cinput *cin, in_file_format *ins, void *&vp) {
01197 object *op;
01198 if (vp==NULL) {
01199 op=new object;
01200 } else {
01201 op=(object *)vp;
01202 }
01203 input(cin,ins,op);
01204 if (vp==NULL) vp=(void *)op;
01205 return 0;
01206 }
01207
01208 int in_wrapper(cinput *cin, in_file_format *ins, void *&vp, int &sz) {
01209 object *op;
01210 ins->int_in(sz);
01211 if (vp==NULL) {
01212 op=new object[sz];
01213 } else {
01214 op=(object *)vp;
01215 }
01216 for(int i=0;i<sz;i++) {
01217 input(cin,ins,&(op[i]));
01218 }
01219 if (vp==NULL) vp=(void *)op;
01220 return 0;
01221 }
01222
01223 int in_wrapper(cinput *cin, in_file_format *ins, void *&vp, int &sz,
01224 int &sz2) {
01225 object **op;
01226 ins->int_in(sz);
01227 ins->int_in(sz2);
01228 if (vp==NULL) {
01229 op=new object *[sz];
01230 } else {
01231 op=(object **)vp;
01232 }
01233 for(int i=0;i<sz;i++) {
01234 if (vp==NULL) op[i]=new object[sz2];
01235 for(int j=0;j<sz2;j++) {
01236 input(cin,ins,&(op[i][j]));
01237 }
01238 }
01239 if (vp==NULL) vp=(void *)op;
01240 return 0;
01241 }
01242
01243 int out_wrapper(coutput *cout, out_file_format *outs, void *vp, int sz,
01244 int sz2) {
01245 int i, j;
01246 std::string stype;
01247 object *op=(object *)vp;
01248
01249 if (sz==0 && sz2==0) {
01250 output(cout,outs,op);
01251 } else if (sz2==0) {
01252 outs->int_out(sz);
01253 for(i=0;i<sz;i++) {
01254 output(cout,outs,&(op[i]));
01255 }
01256 } else {
01257 object **aop=(object **)vp;
01258 outs->int_out(sz);
01259 outs->int_out(sz2);
01260 for(i=0;i<sz;i++) {
01261 for(j=0;j<sz2;j++) {
01262 output(cout,outs,&(aop[i][j]));
01263 }
01264 }
01265 }
01266 return 0;
01267 }
01268
01269
01270 virtual int remove(void *vp) {
01271 object *op=(object *)vp;
01272 delete op;
01273 return 0;
01274 }
01275
01276
01277 virtual int remove_arr(void *vp) {
01278 object *op=(object *)vp;
01279 delete[] op;
01280 return 0;
01281 }
01282
01283
01284 virtual int remove_2darr(void *vp, int sz) {
01285 object **op=(object **)vp;
01286 for(int i=0;i<sz;i++) {
01287 delete[] op[i];
01288 }
01289 delete[] op;
01290 return 0;
01291 }
01292
01293
01294 virtual int stat_in_wrapper(cinput *cin, in_file_format *ins, void *vp) {
01295 object *op=(object *)vp;
01296 stat_input(cin,ins,op);
01297 return 0;
01298 }
01299
01300
01301 virtual int stat_out_wrapper(coutput *cout, out_file_format *outs,
01302 void *vp) {
01303 object *op=(object *)vp;
01304 outs->start_object(type());
01305 stat_output(cout,outs,op);
01306 outs->end_object();
01307 return 0;
01308 }
01309
01310 #endif
01311
01312 public:
01313
01314
01315
01316
01317
01318
01319 virtual int object_in(cinput *cin, in_file_format *ins, object *op,
01320 std::string &name) {
01321 int i, j;
01322
01323 std::string typ;
01324 ins->start_object(typ,name);
01325 input(cin,ins,op);
01326 ins->end_object();
01327 return 0;
01328 }
01329
01330
01331 virtual int object_in(cinput *cin, in_file_format *ins, object *op,
01332 int sz, std::string &name) {
01333 int i;
01334
01335 std::string typ;
01336 ins->start_object(typ,name);
01337 ins->int_in(sz);
01338 for(i=0;i<sz;i++) {
01339 input(cin,ins,&op[i]);
01340 }
01341 ins->end_object();
01342 return 0;
01343 }
01344
01345
01346 virtual int object_in(cinput *cin, in_file_format *ins, object **op,
01347 int sz, int sz2, std::string &name) {
01348 int i, j;
01349
01350 std::string typ;
01351 ins->start_object(typ,name);
01352 ins->int_in(sz);
01353 ins->int_in(sz2);
01354
01355 for(i=0;i<sz;i++) {
01356 object *opx=op[i];
01357 for(j=0;j<sz2;j++) {
01358 input(cin,ins,&opx[j]);
01359 }
01360 }
01361 ins->end_object();
01362 return 0;
01363 }
01364
01365
01366
01367
01368 template<size_t N>
01369 int object_in(cinput *co, in_file_format *ins,
01370 object op[][N], int sz, std::string &name) {
01371 int i, j;
01372
01373 std::string typ;
01374 ins->start_object(typ,name);
01375 ins->int_in(sz);
01376 ins->int_in(((int)N));
01377
01378 for(i=0;i<sz;i++) {
01379 for(j=0;j<N;j++) {
01380 input(co,ins,&op[i][j]);
01381 }
01382 }
01383 ins->end_object();
01384
01385 return 0;
01386 }
01387
01388
01389 virtual int object_in_mem(cinput *cin, in_file_format *ins,
01390 object *&op, std::string &name) {
01391 int i, j;
01392 op=new object;
01393 std::string typ;
01394 ins->start_object(typ,name);
01395 input(cin,ins,op);
01396 ins->end_object();
01397 return 0;
01398 }
01399
01400
01401 virtual int object_in_mem(cinput *cin, in_file_format *ins, object *&op,
01402 int &sz, std::string &name) {
01403 int i, j;
01404
01405 std::string typ;
01406 ins->start_object(typ,name);
01407 ins->int_in(sz);
01408 op=new object[sz];
01409 for(i=0;i<sz;i++) {
01410 input(cin,ins,&op[i]);
01411 }
01412 ins->end_object();
01413 return 0;
01414 }
01415
01416
01417 virtual int object_in_mem(cinput *cin, in_file_format *ins,
01418 object **&op, int &sz, int &sz2,
01419 std::string &name) {
01420 int i, j;
01421
01422 std::string typ;
01423 ins->start_object(typ,name);
01424 ins->int_in(sz);
01425 ins->int_in(sz2);
01426
01427 op=new object *[sz];
01428 for(i=0;i<sz;i++) {
01429 op[i]=new object[sz2];
01430 for(j=0;j<sz2;j++) {
01431 input(cin,ins,&op[i][j]);
01432 }
01433 }
01434 ins->end_object();
01435
01436 return 0;
01437 }
01438
01439
01440
01441
01442
01443
01444 template<size_t N>
01445 int object_in_mem(cinput *co, in_file_format *ins,
01446 object op[][N], int &sz, std::string &name) {
01447 int i, j;
01448
01449 std::string typ;
01450 ins->start_object(typ,name);
01451 ins->int_in(sz);
01452 ins->int_in(((int)N));
01453
01454
01455
01456 for(i=0;i<sz;i++) {
01457
01458
01459 for(j=0;j<N;j++) {
01460 input(co,ins,&op[i][j]);
01461 }
01462 }
01463 ins->end_object();
01464
01465 return 0;
01466 }
01467
01468
01469
01470
01471
01472
01473
01474
01475 virtual int object_out(coutput *cout, out_file_format *outs, object *op,
01476 int sz=0, std::string name="") {
01477 if (sz==0) {
01478 outs->start_object(type(),name);
01479 output(cout,outs,op);
01480 } else {
01481 outs->start_object(((std::string)(type()))+"[]",name);
01482 outs->int_out(sz);
01483 for(int i=0;i<sz;i++) {
01484 output(cout,outs,&op[i]);
01485 }
01486 }
01487 outs->end_object();
01488 return 0;
01489 }
01490
01491
01492
01493 virtual int object_out(coutput *cout, out_file_format *outs, object **op,
01494 int sz, int sz2, std::string name="") {
01495 int i, j;
01496
01497 outs->start_object(((std::string)(type()))+"[][]",name);
01498 outs->int_out(sz);
01499 outs->int_out(sz2);
01500 for(i=0;i<sz;i++) {
01501 for(j=0;j<sz2;j++) {
01502 output(cout,outs,&(op[i][j]));
01503 }
01504 }
01505 outs->end_object();
01506 return 0;
01507 }
01508
01509
01510
01511 template<size_t N>
01512 int object_out(coutput *cout, out_file_format *outs,
01513 object op[][N], int sz, std::string name="") {
01514 int i, j;
01515
01516 outs->start_object(((std::string)(type()))+"[][]",name);
01517 outs->int_out(sz);
01518 outs->int_out(N);
01519 for(i=0;i<sz;i++) {
01520 for(j=0;j<N;j++) {
01521 output(cout,outs,&op[i][j]);
01522 }
01523 }
01524 outs->end_object();
01525 return 0;
01526 }
01527
01528
01529
01530
01531
01532
01533 virtual int mem_alloc(object *&op) {
01534 op=new object;
01535 return 0;
01536 }
01537
01538
01539 virtual int mem_alloc_arr(object *&op, int sz) {
01540 op=new object[sz];
01541 return 0;
01542 }
01543
01544
01545 virtual int mem_alloc_2darr(object **&op, int sz, int sz2) {
01546 op=new object *[sz];
01547 for(int i=0;i<sz;i++) {
01548 op[i]=new object[sz2];
01549 }
01550 return 0;
01551 }
01552
01553
01554
01555
01556
01557
01558
01559 int add(collection &coll, std::string name, object *op, int sz=0,
01560 bool overwrt=true, bool owner=false) {
01561 return coll.add(name,this,op,sz,0,overwrt,owner);
01562 }
01563
01564
01565 int add_2darray(collection &coll, std::string name, object **op, int sz,
01566 int sz2, bool overwrt=true, bool owner=false) {
01567 return coll.add(name,this,op,sz,sz2,overwrt,owner);
01568 }
01569
01570
01571 int get(collection &coll, std::string tname, object *&op) {
01572 void *vp;
01573 int ret=coll.get(tname,vp);
01574 if (ret==0) {
01575 op=(object *)vp;
01576 } else {
01577 op=NULL;
01578 return ret;
01579 }
01580 return 0;
01581 }
01582
01583
01584 int get(collection &co, std::string tname, object *&op, int &sz) {
01585 void *vp;
01586 int ret=co.get(tname,vp,sz);
01587 if (ret==0) {
01588 op=(object *)vp;
01589 } else {
01590 op=NULL;
01591 return ret;
01592 }
01593 return 0;
01594 }
01595
01596
01597 int get(collection &co, std::string tname, object **&op, int &sz,
01598 int &sz2) {
01599 void *vp;
01600 int ret=co.get(tname,vp,sz,sz2);
01601 if (ret==0) {
01602 op=(object **)vp;
01603 } else {
01604 op=NULL;
01605 return ret;
01606 }
01607 return 0;
01608 }
01609
01610
01611
01612
01613
01614
01615
01616 virtual int mem_free(object *op) { return remove((void *)op); }
01617
01618
01619 virtual int mem_free_arr(object *op) { return remove_arr((void *)op); }
01620
01621
01622 virtual int mem_free_2darr(object **op, int sz)
01623 { return remove_2darr((void *)op,sz); }
01624
01625
01626
01627 };
01628
01629
01630 template<> int io_tlate<bool>::input
01631 (cinput *co, in_file_format *ins, bool *dp);
01632 template<> int io_tlate<bool>::output
01633 (coutput *co, out_file_format *outs, bool *dp);
01634 template<> const char *io_tlate<bool>::type();
01635
01636
01637
01638
01639
01640
01641 #ifdef DOXYGENP
01642 class bool_io_type : public io_tlate<object>
01643 #else
01644 class bool_io_type : public io_tlate<bool>
01645 #endif
01646 {
01647 public:
01648
01649
01650 bool_io_type(const char *t) : io_tlate<bool>(t) {};
01651
01652 bool_io_type() : io_tlate<bool>() {};
01653
01654
01655 int addb(collection &co, std::string name, bool x, bool overwrt=true);
01656
01657 bool getb(collection &co, std::string tname);
01658
01659 int get_def(collection &co, std::string tname, bool &op, bool def=false);
01660 };
01661
01662 template<> int io_tlate<char>::input
01663 (cinput *co, in_file_format *ins, char *dp);
01664 template<> int io_tlate<char>::output
01665 (coutput *co, out_file_format *outs, char *dp);
01666 template<> const char *io_tlate<char>::type();
01667
01668
01669
01670
01671
01672
01673 #ifdef DOXYGENP
01674 class char_io_type : public io_tlate<object>
01675 #else
01676 class char_io_type : public io_tlate<char>
01677 #endif
01678 {
01679 public:
01680
01681 char_io_type(const char *t) : io_tlate<char>(t) {};
01682
01683 char_io_type() : io_tlate<char>() {};
01684
01685
01686 int addc(collection &co, std::string name, char x, bool overwrt=true);
01687
01688
01689
01690
01691
01692
01693 char getcc(collection &co, std::string tname);
01694
01695 int get_def(collection &co, std::string tname, char &op, char def='x');
01696 };
01697
01698 template<> int io_tlate<double>::input
01699 (cinput *co, in_file_format *ins, double *dp);
01700 template<> int io_tlate<double>::output
01701 (coutput *co, out_file_format *outs, double *dp);
01702 template<> const char *io_tlate<double>::type();
01703
01704
01705
01706
01707
01708
01709 #ifdef DOXYGENP
01710 class double_io_type : public io_tlate<object>
01711 #else
01712 class double_io_type : public io_tlate<double>
01713 #endif
01714 {
01715 public:
01716
01717 double_io_type(const char *t) : io_tlate<double>(t) {};
01718
01719 double_io_type() : io_tlate<double>() {};
01720
01721
01722 int addd(collection &co, std::string name, double x, bool overwrt=true);
01723
01724 double getd(collection &co, std::string tname);
01725
01726 int get_def(collection &co, std::string tname, double &op,
01727 double def=0.0);
01728 };
01729
01730 template<> int io_tlate<int>::input
01731 (cinput *co, in_file_format *ins, int *dp);
01732 template<> int io_tlate<int>::output
01733 (coutput *co, out_file_format *outs, int *dp);
01734 template<> const char *io_tlate<int>::type();
01735
01736
01737
01738
01739
01740
01741 #ifdef DOXYGENP
01742 class int_io_type : public io_tlate<object>
01743 #else
01744 class int_io_type : public io_tlate<int>
01745 #endif
01746 {
01747 public:
01748
01749 int_io_type(const char *t) : io_tlate<int>(t) {};
01750
01751 int_io_type() : io_tlate<int>() {};
01752
01753
01754 int addi(collection &co, std::string name, int x, bool overwrt=true);
01755
01756 int geti(collection &co, std::string tname);
01757
01758 int get_def(collection &co, std::string tname, int &op,
01759 int def=0);
01760 };
01761
01762 template<> int io_tlate<unsigned long int>::input
01763 (cinput *co, in_file_format *ins, unsigned long int *dp);
01764 template<> int io_tlate<unsigned long int>::output
01765 (coutput *co, out_file_format *outs, unsigned long int *dp);
01766 template<> const char *io_tlate<unsigned long int>::type();
01767
01768
01769
01770
01771
01772
01773 #ifdef DOXYGENP
01774 class long_io_type : public io_tlate<object>
01775 #else
01776 class long_io_type : public io_tlate<unsigned long int>
01777 #endif
01778 {
01779 public:
01780
01781 long_io_type(const char *t) : io_tlate<unsigned long int>(t) {};
01782
01783 long_io_type() : io_tlate<unsigned long int>() {};
01784
01785
01786 int addl(collection &co, std::string name, unsigned long int x,
01787 bool overwrt=true);
01788
01789 int getl(collection &co, std::string tname);
01790
01791 int get_def(collection &co, std::string tname, unsigned long int &op,
01792 unsigned long int def=0);
01793 };
01794
01795 template<> int io_tlate<std::string>::input
01796 (cinput *co, in_file_format *ins, std::string *dp);
01797 template<> int io_tlate<std::string>::output
01798 (coutput *co, out_file_format *outs, std::string *dp);
01799 template<> const char *io_tlate<std::string>::type();
01800
01801
01802
01803
01804
01805
01806 #ifdef DOXYGENP
01807 class string_io_type : public io_tlate<object>
01808 #else
01809 class string_io_type : public io_tlate<std::string>
01810 #endif
01811 {
01812 public:
01813
01814 string_io_type(const char *t) : io_tlate<std::string>(t) {};
01815
01816 string_io_type() : io_tlate<std::string>() {};
01817
01818
01819 int adds(collection &co, std::string name, std::string s,
01820 bool overwrt=true);
01821
01822 std::string gets(collection &co, std::string tname);
01823
01824 int get_def(collection &co, std::string tname, std::string &op,
01825 std::string def="");
01826 };
01827
01828
01829
01830
01831
01832
01833 #ifdef DOXYGENP
01834 class word_io_type : public io_tlate<object>
01835 #else
01836 class word_io_type : public io_tlate<std::string>
01837 #endif
01838 {
01839 public:
01840
01841 word_io_type(const char *t) : io_tlate<std::string>(t) {};
01842
01843 word_io_type() : io_tlate<std::string>() {};
01844
01845
01846 int input(cinput *co, in_file_format *ins, std::string *dp);
01847
01848 int output(coutput *co, out_file_format *outs, std::string *dp);
01849
01850 int addw(collection &co, std::string name, std::string w,
01851 bool overwrt=true);
01852
01853 std::string getw(collection &co, std::string tname);
01854
01855 int get_def(collection &co, std::string tname, std::string &op,
01856 std::string def="");
01857
01858 const char *type() { return "word"; }
01859 };
01860
01861 #ifdef NEVER_DEFINED
01862
01863
01864
01865
01866
01867 template<> int io_tlate<ovector>::input
01868 (cinput *co, in_file_format *ins, ovector *dp);
01869 template<> int io_tlate<ovector>::output
01870 (coutput *co, out_file_format *outs, ovector *dp);
01871 template<> const char *io_tlate<ovector>::type();
01872
01873
01874
01875
01876
01877
01878 template<> int io_tlate<omatrix>::input
01879 (cinput *co, in_file_format *ins, omatrix *dp);
01880 template<> int io_tlate<omatrix>::output
01881 (coutput *co, out_file_format *outs, omatrix *dp);
01882 template<> const char *io_tlate<omatrix>::type();
01883
01884
01885
01886
01887
01888
01889 template<> int io_tlate<ovector_int>::input
01890 (cinput *co, in_file_format *ins, ovector_int *dp);
01891 template<> int io_tlate<ovector_int>::output
01892 (coutput *co, out_file_format *outs, ovector_int *dp);
01893 template<> const char *io_tlate<ovector_int>::type();
01894
01895
01896
01897
01898
01899
01900 template<> int io_tlate<omatrix_int>::input
01901 (cinput *co, in_file_format *ins, omatrix_int *dp);
01902 template<> int io_tlate<omatrix_int>::output
01903 (coutput *co, out_file_format *outs, omatrix_int *dp);
01904 template<> const char *io_tlate<omatrix_int>::type();
01905
01906
01907
01908
01909
01910
01911 template<> int io_tlate<ovector_cx>::input
01912 (cinput *co, in_file_format *ins, ovector_cx *dp);
01913 template<> int io_tlate<ovector_cx>::output
01914 (coutput *co, out_file_format *outs, ovector_cx *dp);
01915 template<> const char *io_tlate<ovector_cx>::type();
01916
01917
01918
01919
01920
01921
01922 template<> int io_tlate<omatrix_cx>::input
01923 (cinput *co, in_file_format *ins, omatrix_cx *dp);
01924 template<> int io_tlate<omatrix_cx>::output
01925 (coutput *co, out_file_format *outs, omatrix_cx *dp);
01926 template<> const char *io_tlate<omatrix_cx>::type();
01927
01928 typedef io_tlate<ovector> ovector_io_type;
01929 typedef io_tlate<omatrix> omatrix_io_type;
01930 typedef io_tlate<ovector_int> ovector_int_io_type;
01931 typedef io_tlate<omatrix_int> omatrix_int_io_type;
01932 typedef io_tlate<ovector_cx> ovector_cx_io_type;
01933 typedef io_tlate<omatrix_cx> omatrix_cx_io_type;
01934
01935 #endif
01936
01937 #ifndef DOXYGENP
01938 }
01939 #endif
01940
01941 #endif