00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _PARMPARSE_H_
00012 #define _PARMPARSE_H_
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <iostream>
00028 #include <iomanip>
00029 #include <cstdlib>
00030 #include <cstring>
00031 #include <vector>
00032 #include <string>
00033 #include <sstream>
00034
00035 #include "CH_assert.H"
00036 #include "MayDay.H"
00037 #include "Misc.H"
00038 #include "Vector.H"
00039 #include "BaseNamespaceHeader.H"
00040 using std::cout;
00041 using std::cerr;
00042 using std::endl;
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #ifndef DOXYGEN
00060 class PP_UseCount
00061 {
00062 public:
00063
00064
00065
00066 PP_UseCount ();
00067
00068
00069
00070 PP_UseCount (const PP_UseCount& rhs);
00071
00072
00073
00074
00075
00076 PP_UseCount& operator= (const PP_UseCount& rhs);
00077
00078
00079
00080 ~PP_UseCount ();
00081
00082
00083
00084 bool unique () const;
00085
00086
00087
00088 int linkCount () const;
00089
00090 private:
00091
00092
00093
00094 unsigned int* cnt;
00095
00096
00097
00098
00099 void decrement ();
00100 };
00101
00102
00103
00104
00105
00106 inline
00107 PP_UseCount::PP_UseCount ()
00108 :
00109 cnt(new unsigned int(1))
00110 {
00111 }
00112
00113 inline
00114 PP_UseCount::PP_UseCount (const PP_UseCount& rhs)
00115 :
00116 cnt(rhs.cnt)
00117 {
00118 ++*cnt;
00119 }
00120
00121 inline
00122 bool
00123 PP_UseCount::unique () const
00124 {
00125 return *cnt == 1;
00126 }
00127
00128 inline
00129 void
00130 PP_UseCount::decrement ()
00131 {
00132 if (unique())
00133 {
00134 delete cnt;
00135 cnt = 0;
00136 }
00137 else
00138 --*cnt;
00139 }
00140
00141 inline
00142 PP_UseCount&
00143 PP_UseCount::operator= (const PP_UseCount& rhs)
00144 {
00145 ++*rhs.cnt;
00146 decrement();
00147 cnt = rhs.cnt;
00148 return *this;
00149 }
00150
00151 inline
00152 PP_UseCount::~PP_UseCount ()
00153 {
00154 decrement();
00155 }
00156
00157 inline
00158 int
00159 PP_UseCount::linkCount () const
00160 {
00161 return *cnt;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 template <class T>
00183 class PP_CpPtr
00184 {
00185 public:
00186
00187
00188
00189 PP_CpPtr ();
00190
00191
00192
00193 PP_CpPtr (T* rhs);
00194
00195
00196
00197 ~PP_CpPtr ();
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 PP_CpPtr (const PP_CpPtr<T>& rhs);
00208
00209
00210
00211
00212 PP_CpPtr<T>& operator= (T* rhs);
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 PP_CpPtr<T>& operator= (const PP_CpPtr<T>& rhs);
00223
00224
00225
00226
00227
00228
00229 T& operator* () const;
00230
00231
00232
00233 bool isNull () const;
00234
00235
00236
00237 T* release ();
00238
00239
00240
00241 bool operator== (const PP_CpPtr<T>& rhs) const;
00242
00243
00244
00245 bool operator!= (const PP_CpPtr<T>& rhs) const;
00246
00247 protected:
00248 T* ptr;
00249 };
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 template<class T>
00265 class PP_CpClassPtr :
00266 public PP_CpPtr<T>
00267 {
00268 public:
00269
00270
00271
00272 PP_CpClassPtr ();
00273
00274
00275
00276 PP_CpClassPtr (T* rhs);
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 PP_CpClassPtr (const PP_CpClassPtr<T>& rhs);
00287
00288
00289
00290
00291 PP_CpClassPtr<T>& operator= (T* rhs);
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 PP_CpClassPtr<T>& operator= (const PP_CpClassPtr<T>& rhs);
00302
00303
00304
00305 T* operator-> () const;
00306 };
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 template<class T>
00323 class PP_LnPtr
00324 {
00325 public:
00326
00327
00328
00329 PP_LnPtr ();
00330
00331
00332
00333 PP_LnPtr (T* rhs);
00334
00335
00336
00337
00338
00339
00340 PP_LnPtr<T>& operator= (const PP_LnPtr<T>& rhs);
00341
00342
00343
00344
00345
00346 PP_LnPtr<T>& operator= (T* rhs)
00347 {
00348
00349
00350
00351 if (unique())
00352 delete ptr;
00353 ptr = rhs;
00354 ucnt = PP_UseCount();
00355 return *this;
00356 }
00357
00358
00359
00360
00361 ~PP_LnPtr ();
00362
00363
00364
00365 bool unique () const;
00366
00367
00368
00369 int linkCount () const;
00370
00371
00372
00373
00374
00375
00376 T& operator* () const;
00377
00378
00379
00380 bool isNull () const;
00381
00382
00383
00384 bool operator== (const PP_LnPtr<T>& rhs) const;
00385
00386
00387
00388 bool operator!= (const PP_LnPtr<T>& rhs) const;
00389
00390 protected:
00391 T* ptr;
00392
00393 private:
00394 PP_UseCount ucnt;
00395 };
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 template<class T>
00410 class PP_LnClassPtr
00411 : public PP_LnPtr<T>
00412 {
00413 public:
00414
00415
00416
00417 PP_LnClassPtr ();
00418
00419
00420
00421 PP_LnClassPtr (T* rhs);
00422
00423
00424
00425
00426
00427
00428 PP_LnClassPtr<T>& operator= (const PP_LnClassPtr<T>& rhs);
00429
00430
00431
00432
00433
00434 PP_LnClassPtr<T>& operator= (T* rhs);
00435
00436
00437
00438 T* operator->() const;
00439 };
00440
00441
00442
00443
00444
00445 template <class T>
00446 inline
00447 PP_CpPtr<T>::PP_CpPtr ()
00448 :
00449 ptr(0)
00450 {
00451 }
00452
00453 template <class T>
00454 inline
00455 PP_CpPtr<T>::PP_CpPtr(T* rhs)
00456 :
00457 ptr(rhs)
00458 {
00459 }
00460
00461 template <class T>
00462 inline
00463 PP_CpPtr<T>::~PP_CpPtr()
00464 {
00465 delete ptr;
00466 }
00467
00468 template <class T>
00469 inline
00470 bool
00471 PP_CpPtr<T>::isNull () const
00472 {
00473 return ptr == 0;
00474 }
00475
00476 template <class T>
00477 inline
00478 PP_CpPtr<T>::PP_CpPtr (const PP_CpPtr<T>& rhs)
00479 {
00480 ptr = rhs.isNull() ? 0 : new T(*rhs.ptr);
00481 }
00482
00483 template <class T>
00484 inline
00485 PP_CpPtr<T>&
00486 PP_CpPtr<T>::operator= (const PP_CpPtr<T>& rhs)
00487 {
00488 if (!(ptr == rhs.ptr))
00489 {
00490 delete ptr;
00491 ptr = rhs.isNull() ? 0 : new T(*rhs.ptr);
00492 }
00493 return *this;
00494 }
00495
00496 template <class T>
00497 inline
00498 PP_CpPtr<T>&
00499 PP_CpPtr<T>::operator= (T* rhs)
00500 {
00501 delete ptr;
00502 ptr = rhs;
00503 return *this;
00504 }
00505
00506 template <class T>
00507 inline
00508 T&
00509 PP_CpPtr<T>::operator* () const
00510 {
00511 CH_assert(ptr != 0);
00512 return *ptr;
00513 }
00514
00515 template <class T>
00516 inline
00517 T*
00518 PP_CpPtr<T>::release ()
00519 {
00520 T* old = ptr;
00521 ptr = 0;
00522 return old;
00523 }
00524
00525 template <class T>
00526 inline
00527 bool
00528 PP_CpPtr<T>::operator== (const PP_CpPtr<T>& rhs) const
00529 {
00530 return ptr == rhs.ptr;
00531 }
00532
00533 template <class T>
00534 inline
00535 bool
00536 PP_CpPtr<T>::operator!= (const PP_CpPtr<T>& rhs) const
00537 {
00538 return ptr != rhs.ptr;
00539 }
00540
00541 template <class T>
00542 inline
00543 PP_CpClassPtr<T>::PP_CpClassPtr ()
00544 :
00545 PP_CpPtr<T>()
00546 {
00547 }
00548
00549 template <class T>
00550 inline
00551 PP_CpClassPtr<T>::PP_CpClassPtr (T* rhs)
00552 :
00553 PP_CpPtr<T>(rhs)
00554 {
00555 }
00556
00557 template <class T>
00558 inline
00559 PP_CpClassPtr<T>::PP_CpClassPtr (const PP_CpClassPtr<T>& rhs)
00560 :
00561 PP_CpPtr<T>(rhs)
00562 {
00563 }
00564
00565 template <class T>
00566 inline
00567 PP_CpClassPtr<T>&
00568 PP_CpClassPtr<T>::operator= (T* rhs)
00569 {
00570 PP_CpPtr<T>::operator= (rhs);
00571 return *this;
00572 }
00573
00574 template <class T>
00575 inline
00576 PP_CpClassPtr<T>&
00577 PP_CpClassPtr<T>::operator= (const PP_CpClassPtr<T>& rhs)
00578 {
00579 PP_CpPtr<T>::operator= (rhs);
00580 return *this;
00581 }
00582
00583 template <class T>
00584 inline
00585 T*
00586 PP_CpClassPtr<T>::operator-> () const
00587 {
00588 return this->ptr;
00589 }
00590
00591 template <class T>
00592 inline
00593 PP_LnPtr<T>::PP_LnPtr ()
00594 :
00595 ptr(0)
00596 {
00597 }
00598
00599 template <class T>
00600 inline
00601 PP_LnPtr<T>::PP_LnPtr(T* rhs)
00602 :
00603 ptr(rhs)
00604 {
00605 }
00606
00607 template <class T>
00608 inline
00609 bool
00610 PP_LnPtr<T>::unique () const
00611 {
00612 return ucnt.unique();
00613 }
00614
00615 template <class T>
00616 inline
00617 PP_LnPtr<T>::~PP_LnPtr ()
00618 {
00619 if (ucnt.unique())
00620 delete ptr;
00621 }
00622
00623 template <class T>
00624 inline
00625 PP_LnPtr<T>&
00626 PP_LnPtr<T>::operator= (const PP_LnPtr<T>& rhs)
00627 {
00628 if (ptr != rhs.ptr)
00629 {
00630 if (unique())
00631 delete ptr;
00632 ptr = rhs.ptr;
00633 ucnt = rhs.ucnt;
00634 }
00635 return *this;
00636 }
00637
00638 template <class T>
00639 inline
00640 int
00641 PP_LnPtr<T>::linkCount () const
00642 {
00643 return ucnt.linkCount();
00644 }
00645
00646 template <class T>
00647 inline
00648 T&
00649 PP_LnPtr<T>::operator* () const
00650 {
00651 CH_assert(ptr != 0);
00652 return *ptr;
00653 }
00654
00655 template <class T>
00656 inline
00657 bool
00658 PP_LnPtr<T>::isNull () const
00659 {
00660 return ptr == 0;
00661 }
00662
00663 template <class T>
00664 inline
00665 bool
00666 PP_LnPtr<T>::operator== (const PP_LnPtr<T>& rhs) const
00667 {
00668 return ptr == rhs.ptr;
00669 }
00670
00671 template <class T>
00672 inline
00673 bool
00674 PP_LnPtr<T>::operator!= (const PP_LnPtr<T>& rhs) const
00675 {
00676 return ptr != rhs.ptr;
00677 }
00678
00679 template <class T>
00680 inline
00681 PP_LnClassPtr<T>::PP_LnClassPtr ()
00682 {
00683 }
00684
00685 template <class T>
00686 inline
00687 PP_LnClassPtr<T>::PP_LnClassPtr (T* rhs)
00688 :
00689 PP_LnPtr<T>(rhs)
00690 {
00691 }
00692
00693 template <class T>
00694 inline
00695 PP_LnClassPtr<T>&
00696 PP_LnClassPtr<T>::operator= (const PP_LnClassPtr<T>& rhs)
00697 {
00698 PP_LnPtr<T>::operator=(rhs);
00699 return *this;
00700 }
00701
00702 template <class T>
00703 inline
00704 PP_LnClassPtr<T>&
00705 PP_LnClassPtr<T>::operator= (T* rhs)
00706 {
00707 PP_LnPtr<T>::operator=(rhs);
00708 return *this;
00709 }
00710
00711 template <class T>
00712 inline
00713 T*
00714 PP_LnClassPtr<T>::operator->() const
00715 {
00716 return this->ptr;
00717 }
00718
00719
00720
00721
00722
00723 class PP_StringRep
00724 {
00725 friend class PP_String;
00726 char* s;
00727 int bufferlength;
00728 public:
00729 PP_StringRep (int _len = 0);
00730 ~PP_StringRep ();
00731
00732
00733
00734 void resize (int n);
00735 };
00736
00737
00738
00739
00740
00741 inline
00742 PP_StringRep::PP_StringRep (int _len)
00743 {
00744 bufferlength = _len;
00745 s = new char [bufferlength];
00746 }
00747
00748 inline
00749 PP_StringRep::~PP_StringRep ()
00750 {
00751 delete [] s;
00752 s = 0;
00753 }
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779 class PP_String
00780 {
00781 public:
00782
00783
00784
00785 PP_String ();
00786
00787
00788
00789
00790 PP_String (char c);
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 PP_String (int len);
00801
00802
00803
00804
00805 PP_String (const char* s);
00806
00807
00808
00809 PP_String (const PP_String& rhs);
00810
00811
00812
00813 PP_String& operator= (const PP_String& rhs);
00814
00815
00816
00817
00818 PP_String& operator+= (const PP_String& right);
00819
00820
00821
00822
00823
00824 PP_String& operator+= (const char* right);
00825
00826
00827
00828
00829
00830 PP_String& operator+= (char c);
00831
00832
00833
00834
00835 PP_String& toUpper ();
00836
00837
00838
00839
00840 PP_String& toLower ();
00841
00842
00843
00844
00845
00846
00847
00848 std::istream& getline (std::istream& strm);
00849
00850
00851
00852
00853 int length () const;
00854
00855
00856
00857
00858 bool isNull () const;
00859
00860
00861
00862
00863 char& operator [] (int k);
00864
00865
00866
00867
00868 char operator[] (int k) const;
00869
00870
00871
00872
00873 const char* c_str () const;
00874
00875
00876
00877
00878
00879
00880 double toDouble () const;
00881
00882
00883
00884
00885
00886
00887 int toInteger () const;
00888
00889
00890
00891
00892
00893
00894 long toLong () const;
00895
00896
00897
00898 friend std::ostream& operator<< (std::ostream& os,
00899 const PP_String& str);
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913 friend std::istream& operator>> (std::istream& is,
00914 PP_String& str);
00915
00916 protected:
00917 void copyModify ();
00918
00919 private:
00920 PP_LnClassPtr<PP_StringRep> p;
00921 int len;
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932 friend inline bool operator< (const PP_String& left,
00933 const PP_String& right);
00934
00935
00936
00937 friend inline bool operator<= (const PP_String& left,
00938 const PP_String& right);
00939
00940
00941
00942 friend inline bool operator!= (const PP_String& left,
00943 const PP_String& right);
00944
00945
00946
00947 friend inline bool operator== (const PP_String& left,
00948 const PP_String& right);
00949
00950
00951
00952 friend inline bool operator>= (const PP_String& left,
00953 const PP_String& right);
00954
00955
00956
00957 friend inline bool operator> (const PP_String& left,
00958 const PP_String& right);
00959
00960
00961
00962 friend inline bool operator< (const PP_String& left,
00963 const char* right);
00964
00965
00966
00967 friend inline bool operator<= (const PP_String& left,
00968 const char* right);
00969
00970
00971
00972 friend inline bool operator!= (const PP_String& left,
00973 const char* right);
00974
00975
00976
00977 friend inline bool operator== (const PP_String& left,
00978 const char* right);
00979
00980
00981
00982 friend inline bool operator>= (const PP_String& left,
00983 const char* right);
00984
00985
00986
00987 friend inline bool operator> (const PP_String& left,
00988 const char* right);
00989
00990
00991
00992 friend inline bool operator< (const char* left,
00993 const PP_String& right);
00994
00995
00996
00997 friend inline bool operator<= (const char* left,
00998 const PP_String& right);
00999
01000
01001
01002 friend inline bool operator!= (const char* left,
01003 const PP_String& right);
01004
01005
01006
01007 friend inline bool operator== (const char* left,
01008 const PP_String& right);
01009
01010
01011
01012 friend inline bool operator>= (const char* left,
01013 const PP_String& right);
01014
01015
01016
01017 friend inline bool operator> (const char* left,
01018 const PP_String& right);
01019 };
01020
01021
01022
01023
01024
01025 inline
01026 bool
01027 PP_String::isNull () const
01028 {
01029 return len == 0;
01030 }
01031
01032 inline
01033 int
01034 PP_String::length () const
01035 {
01036 return len;
01037 }
01038
01039 inline
01040 double
01041 PP_String::toDouble () const
01042 {
01043 return len == 0 ? 0 : std::atof(p->s);
01044 }
01045
01046 inline
01047 int
01048 PP_String::toInteger () const
01049 {
01050 return len == 0 ? 0 : atoi(p->s);
01051 }
01052
01053 inline
01054 long
01055 PP_String::toLong () const
01056 {
01057 return len == 0 ? 0 : atol(p->s);
01058 }
01059
01060 inline
01061 const char*
01062 PP_String::c_str () const
01063 {
01064 return p->s;
01065 }
01066
01067 inline
01068 char
01069 PP_String::operator[] (int index) const
01070 {
01071 CH_assert(index >=0 && index < len);
01072 return p->s[index];
01073 }
01074
01075 inline
01076 PP_String
01077 operator+ (const PP_String& left,
01078 const PP_String& right)
01079 {
01080 PP_String result(left);
01081 return result += right;
01082 }
01083
01084 inline
01085 bool
01086 operator< (const PP_String& left,
01087 const PP_String& right)
01088 {
01089 return ::strcmp(left.c_str(), right.c_str()) < 0;
01090 }
01091
01092 inline
01093 bool
01094 operator<= (const PP_String& left,
01095 const PP_String& right)
01096 {
01097 return ::strcmp(left.c_str(), right.c_str()) <= 0;
01098 }
01099
01100 inline
01101 bool
01102 operator!= (const PP_String& left,
01103 const PP_String& right)
01104 {
01105 return ::strcmp(left.c_str(), right.c_str()) != 0;
01106 }
01107
01108 inline
01109 bool
01110 operator== (const PP_String& left,
01111 const PP_String& right)
01112 {
01113 return ::strcmp(left.c_str(), right.c_str()) == 0;
01114 }
01115
01116 inline
01117 bool
01118 operator>= (const PP_String& left,
01119 const PP_String& right)
01120 {
01121 return ::strcmp(left.c_str(), right.c_str()) >= 0;
01122 }
01123
01124 inline
01125 bool
01126 operator> (const PP_String& left,
01127 const PP_String& right)
01128 {
01129 return ::strcmp(left.c_str(), right.c_str()) > 0;
01130 }
01131
01132 inline
01133 bool
01134 operator< (const PP_String& left,
01135 const char* right)
01136 {
01137 return ::strcmp(left.c_str(), right) < 0;
01138 }
01139
01140 inline
01141 bool
01142 operator<= (const PP_String& left,
01143 const char* right)
01144 {
01145 return ::strcmp(left.c_str(), right) <= 0;
01146 }
01147
01148 inline
01149 bool
01150 operator!= (const PP_String& left,
01151 const char* right)
01152 {
01153 return ::strcmp(left.c_str(), right) != 0;
01154 }
01155
01156 inline
01157 bool
01158 operator== (const PP_String& left,
01159 const char* right)
01160 {
01161 return ::strcmp(left.c_str(), right) == 0;
01162 }
01163
01164 inline
01165 bool
01166 operator>= (const PP_String& left,
01167 const char* right)
01168 {
01169 return ::strcmp(left.c_str(), right) >= 0;
01170 }
01171
01172 inline
01173 bool
01174 operator> (const PP_String& left,
01175 const char* right)
01176 {
01177 return ::strcmp(left.c_str(), right) > 0;
01178 }
01179
01180 inline
01181 bool
01182 operator< (const char* left,
01183 const PP_String& right)
01184 {
01185 return ::strcmp(left, right.c_str()) < 0;
01186 }
01187
01188 inline
01189 bool
01190 operator<= (const char* left,
01191 const PP_String& right)
01192 {
01193 return ::strcmp(left, right.c_str()) <= 0;
01194 }
01195
01196 inline
01197 bool
01198 operator!= (const char* left,
01199 const PP_String& right)
01200 {
01201 return ::strcmp(left, right.c_str()) != 0;
01202 }
01203
01204 inline
01205 bool
01206 operator== (const char* left,
01207 const PP_String& right)
01208 {
01209 return ::strcmp(left, right.c_str()) == 0;
01210 }
01211
01212 inline
01213 bool
01214 operator>= (const char* left,
01215 const PP_String& right)
01216 {
01217 return ::strcmp(left, right.c_str()) >= 0;
01218 }
01219
01220 inline
01221 bool
01222 operator> (const char* left,
01223 const PP_String& right)
01224 {
01225 return ::strcmp(left, right.c_str()) > 0;
01226 }
01227
01228
01229
01230 template <class T> class PP_ListLink;
01231 template <class T> class PP_ListIterator;
01232 template <class T> class PP_List;
01233
01234 template <class T>
01235 class PP_ListLink
01236 {
01237 private:
01238 friend class PP_List<T>;
01239 friend class PP_ListIterator<T>;
01240
01241 PP_ListLink (const T& _val,
01242 PP_ListLink<T>* _pre,
01243 PP_ListLink<T>* _suc)
01244 :
01245 val(_val),
01246 pre(_pre),
01247 suc(_suc)
01248 {}
01249
01250 private:
01251 T val;
01252 PP_ListLink<T>* pre;
01253 PP_ListLink<T>* suc;
01254 };
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267 template <class T>
01268 class PP_ListIterator
01269 {
01270 public:
01271
01272
01273
01274 PP_ListIterator (const PP_List<T>& aList);
01275
01276
01277
01278 PP_ListIterator (const PP_ListIterator<T>& rhs);
01279
01280
01281
01282
01283 void rewind ();
01284
01285
01286
01287
01288 const T& operator() () const;
01289
01290
01291
01292
01293 const T& operator* () const;
01294
01295
01296
01297
01298
01299
01300
01301 operator void* ();
01302
01303
01304
01305
01306 bool operator! () const;
01307
01308
01309
01310
01311 const T& value () const;
01312
01313
01314
01315
01316
01317
01318 PP_ListIterator<T>& operator++ ();
01319
01320
01321
01322
01323
01324
01325 PP_ListIterator<T>& operator-- ();
01326
01327
01328
01329
01330
01331
01332
01333 PP_ListIterator<T> operator-- (int);
01334
01335
01336
01337
01338
01339
01340 PP_ListIterator<T> operator++ (int);
01341
01342
01343
01344
01345 bool operator== (const PP_ListIterator<T>&) const;
01346
01347
01348
01349 bool operator!= (const PP_ListIterator<T>&) const;
01350
01351 protected:
01352
01353
01354
01355 PP_ListIterator (const PP_List<T>& _list,
01356 PP_ListLink<T>* _p);
01357
01358
01359
01360 const PP_List<T>& list;
01361
01362
01363
01364 PP_ListLink<T>* p;
01365
01366 private:
01367 friend class PP_List<T>;
01368
01369
01370
01371 PP_ListIterator ();
01372 PP_ListIterator<T>& operator= (const PP_ListIterator<T>&);
01373 };
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408 template <class T>
01409 class PP_List
01410 {
01411 public:
01412
01413
01414
01415 PP_List ();
01416
01417
01418
01419 PP_List (const PP_List<T>& rhs);
01420
01421
01422
01423 PP_List<T>& operator= (const PP_List<T>& rhs);
01424
01425
01426
01427 ~PP_List();
01428
01429
01430
01431 void prepend (const T& value);
01432
01433
01434
01435 void append (const T& value);
01436
01437
01438
01439 void add (const T& value);
01440
01441
01442
01443 void join (const PP_List<T>& src);
01444
01445
01446
01447
01448
01449
01450
01451 void catenate (PP_List<T>& src);
01452
01453
01454
01455 void clear ();
01456
01457
01458
01459 T& firstElement () const;
01460
01461
01462
01463 T& lastElement () const;
01464
01465
01466
01467
01468
01469 bool includes (const T& value) const;
01470
01471
01472
01473
01474
01475
01476 bool operator== (const PP_List<T>& rhs) const;
01477
01478
01479
01480 bool operator!= (const PP_List<T>& rhs) const;
01481
01482
01483
01484 bool isEmpty () const;
01485
01486
01487
01488 bool isNotEmpty () const;
01489
01490
01491
01492 int length () const;
01493
01494
01495
01496 void removeFirst ();
01497
01498
01499
01500 void removeLast ();
01501
01502
01503
01504 const T& operator[] (const PP_ListIterator<T>& li) const;
01505
01506
01507
01508 T& operator[] (const PP_ListIterator<T>& li);
01509
01510
01511
01512 void remove (const T& value);
01513
01514
01515
01516
01517 void remove (const PP_List<T>& lst);
01518
01519
01520
01521 void remove (PP_ListIterator<T>& lit);
01522
01523
01524
01525 void replace (PP_ListIterator<T>& li,
01526 const T& val);
01527
01528
01529
01530
01531 void addAfter (PP_ListIterator<T>& lit,
01532 const T& val);
01533
01534
01535
01536
01537 void addBefore (PP_ListIterator<T>& lit,
01538 const T& val);
01539
01540
01541
01542 PP_ListIterator<T> first () const;
01543
01544
01545
01546 PP_ListIterator<T> last () const;
01547
01548 protected:
01549
01550
01551
01552 void remove (PP_ListLink<T> *ln);
01553
01554
01555
01556 PP_ListLink<T>* addBefore (PP_ListLink<T>* ln,
01557 const T& val);
01558
01559
01560
01561 PP_ListLink<T>* addAfter (PP_ListLink<T>* ln,
01562 const T& val);
01563
01564
01565
01566 PP_ListLink<T>* head;
01567
01568
01569
01570 PP_ListLink<T>* tail;
01571
01572
01573
01574 friend class PP_ListIterator<T>;
01575 };
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585 template <class T>
01586 inline
01587 PP_ListIterator<T>::PP_ListIterator (const PP_List<T>& _list,
01588 PP_ListLink<T>* _p)
01589 :
01590 list(_list),
01591 p(_p)
01592 {
01593 }
01594
01595 template <class T>
01596 inline
01597 PP_ListIterator<T>::PP_ListIterator (const PP_List<T>& aList)
01598 :
01599 list(aList)
01600 {
01601 p = list.head;
01602 }
01603
01604 template <class T>
01605 inline
01606 PP_ListIterator<T>::PP_ListIterator (const PP_ListIterator<T>& li)
01607 :
01608 list(li.list),
01609 p(li.p)
01610 {
01611 }
01612
01613 template <class T>
01614 inline
01615 void
01616 PP_ListIterator<T>::rewind ()
01617 {
01618 p = list.head;
01619 }
01620
01621 template <class T>
01622 inline
01623 const T&
01624 PP_ListIterator<T>::operator() () const
01625 {
01626 CH_assert(p != 0);
01627 return p->val;
01628 }
01629
01630 template <class T>
01631 inline
01632 const T&
01633 PP_ListIterator<T>::operator* () const
01634 {
01635 CH_assert(p != 0);
01636 return p->val;
01637 }
01638
01639 template <class T>
01640 inline
01641 PP_ListIterator<T>::operator void* ()
01642 {
01643 return p != 0 ? this : 0;
01644 }
01645
01646 template <class T>
01647 inline
01648 bool
01649 PP_ListIterator<T>::operator! () const
01650 {
01651 return p == 0 ? true : false;
01652 }
01653
01654 template <class T>
01655 inline
01656 const T&
01657 PP_ListIterator<T>::value () const
01658 {
01659 CH_assert(p != 0);
01660 return p->val;
01661 }
01662
01663 template <class T>
01664 inline
01665 PP_ListIterator<T>&
01666 PP_ListIterator<T>::operator++ ()
01667 {
01668 if (p)
01669 p = p->suc;
01670 return *this;
01671 }
01672
01673 template <class T>
01674 inline
01675 PP_ListIterator<T>&
01676 PP_ListIterator<T>::operator-- ()
01677 {
01678 if (p)
01679 p = p->pre;
01680 return *this;
01681 }
01682
01683 template <class T>
01684 inline
01685 PP_ListIterator<T>
01686 PP_ListIterator<T>::operator++ (int)
01687 {
01688 const PP_ListIterator<T> li = *this;
01689 ++(*this);
01690 return li;
01691 }
01692
01693 template <class T>
01694 inline
01695 PP_ListIterator<T>
01696 PP_ListIterator<T>::operator-- (int)
01697 {
01698 const PP_ListIterator<T> li = *this;
01699 --(*this);
01700 return li;
01701 }
01702
01703 template <class T>
01704 inline
01705 bool
01706 PP_ListIterator<T>::operator== (const PP_ListIterator<T>& _li) const
01707 {
01708 return (&list == &_li.list && p == _li.p) ? true : false;
01709 }
01710
01711 template <class T>
01712 inline
01713 bool
01714 PP_ListIterator<T>::operator!= (const PP_ListIterator<T>& _li) const
01715 {
01716 return ! PP_ListIterator<T>::operator==(_li);
01717 }
01718
01719
01720
01721
01722
01723 template <class T>
01724 inline
01725 PP_List<T>::PP_List ()
01726 :
01727 head(0),
01728 tail(0)
01729 {
01730 }
01731
01732 template <class T>
01733 inline
01734 PP_List<T>::~PP_List ()
01735 {
01736 clear();
01737 }
01738
01739 template <class T>
01740 inline
01741 void
01742 PP_List<T>::prepend (const T& value)
01743 {
01744 addBefore(head, value);
01745 }
01746
01747 template <class T>
01748 inline
01749 void
01750 PP_List<T>::append (const T& value)
01751 {
01752 addAfter(tail, value);
01753 }
01754
01755 template <class T>
01756 inline
01757 T&
01758 PP_List<T>::firstElement () const
01759 {
01760 CH_assert(head != 0);
01761 return head->val;
01762 }
01763
01764 template <class T>
01765 inline
01766 T&
01767 PP_List<T>::lastElement () const
01768 {
01769 CH_assert(tail != 0);
01770 return tail->val;
01771 }
01772
01773 template <class T>
01774 inline
01775 bool
01776 PP_List<T>::isEmpty () const
01777 {
01778 return head == 0 && tail == 0;
01779 }
01780
01781 template <class T>
01782 inline
01783 bool
01784 PP_List<T>::isNotEmpty () const
01785 {
01786 return !isEmpty();
01787 }
01788
01789 template <class T>
01790 inline
01791 void
01792 PP_List<T>::removeFirst ()
01793 {
01794 remove(head);
01795 }
01796
01797 template <class T>
01798 inline
01799 void
01800 PP_List<T>::removeLast ()
01801 {
01802 remove(tail);
01803 }
01804
01805 template <class T>
01806 inline
01807 const T&
01808 PP_List<T>::operator[] (const PP_ListIterator<T>& li) const
01809 {
01810 CH_assert(li.p != 0);
01811 return li.p->val;
01812 }
01813
01814 template <class T>
01815 inline
01816 T&
01817 PP_List<T>::operator[] (const PP_ListIterator<T>& li)
01818 {
01819 CH_assert(li.p != 0);
01820 return li.p->val;
01821 }
01822
01823 template <class T>
01824 inline
01825 void
01826 PP_List<T>::replace (PP_ListIterator<T>& li,
01827 const T& _val)
01828 {
01829 CH_assert(li.p != 0);
01830 li.p->val = _val;
01831 }
01832
01833 template <class T>
01834 inline
01835 void
01836 PP_List<T>::addAfter (PP_ListIterator<T>& lit,
01837 const T& val)
01838 {
01839 addAfter(lit.p, val);
01840 }
01841
01842 template <class T>
01843 inline
01844 void
01845 PP_List<T>::addBefore (PP_ListIterator<T>& lit,
01846 const T& val)
01847 {
01848 addBefore(lit.p, val);
01849 }
01850
01851 template <class T>
01852 inline
01853 PP_ListIterator<T>
01854 PP_List<T>::first () const
01855 {
01856 return PP_ListIterator<T>(*this,head);
01857 }
01858
01859 template <class T>
01860 inline
01861 PP_ListIterator<T>
01862 PP_List<T>::last () const
01863 {
01864 return PP_ListIterator<T>(*this,tail);
01865 }
01866
01867
01868
01869
01870
01871 template <class T>
01872 inline
01873 PP_List<T>::PP_List (const PP_List<T>& source)
01874 :
01875 head(0),
01876 tail(0)
01877 {
01878 if (source.isEmpty())
01879 tail = head = 0;
01880 else
01881 for (PP_ListIterator<T> li(source); li; ++li)
01882 append(li());
01883 }
01884
01885
01886
01887
01888
01889 template <class T>
01890 inline void
01891 PP_List<T>::add (const T& value)
01892 {
01893 append(value);
01894 }
01895
01896 template <class T>
01897 inline
01898 int
01899 PP_List<T>::length () const
01900 {
01901 int len = 0;
01902 for (PP_ListIterator<T> li(*this); li; ++li)
01903 len++;
01904 return len;
01905 }
01906
01907 template <class T>
01908 inline
01909 PP_List<T>&
01910 PP_List<T>::operator= (const PP_List<T>& source)
01911 {
01912 if (!(this == &source))
01913 {
01914 clear();
01915 for (PP_ListIterator<T> li(source); li; ++li)
01916 append(li());
01917 }
01918 return *this;
01919 }
01920
01921 template <class T>
01922 inline PP_ListLink<T> *
01923 PP_List<T>::addBefore (PP_ListLink<T>* ln,
01924 const T& val)
01925 {
01926 CH_assert(ln != 0 || head == 0);
01927
01928 PP_ListLink<T>* newlink;
01929
01930 if (ln == head)
01931 {
01932 head = newlink = new PP_ListLink<T>(val, 0, head);
01933
01934 if (tail == 0)
01935 tail = head;
01936 else
01937 head->suc->pre = newlink;
01938 }
01939 else
01940 {
01941 newlink = new PP_ListLink<T>(val, ln->pre, ln);
01942
01943 ln->pre->suc = newlink;
01944 ln->pre = newlink;
01945 }
01946
01947 return newlink;
01948 }
01949
01950 template <class T>
01951 inline
01952 PP_ListLink<T>*
01953 PP_List<T>::addAfter (PP_ListLink<T>* ln,
01954 const T& val)
01955 {
01956 CH_assert(ln != 0 || tail == 0);
01957
01958 PP_ListLink<T>* newlink;
01959
01960
01961
01962
01963
01964
01965
01966 if (ln == tail)
01967 {
01968 tail = newlink = new PP_ListLink<T>(val,tail,0);
01969
01970 if (head == 0)
01971 head = tail;
01972 else
01973 tail->pre->suc = newlink;
01974 }
01975 else
01976 {
01977 newlink = new PP_ListLink<T>(val, ln, ln->suc);
01978
01979 ln->suc->pre = newlink;
01980 ln->suc = newlink;
01981 }
01982
01983 return newlink;
01984 }
01985
01986 template <class T>
01987 inline void
01988 PP_List<T>::join (const PP_List<T>& list2)
01989 {
01990 for (PP_ListIterator<T> li2(list2); li2; ++li2)
01991 append(li2());
01992 }
01993
01994 template <class T>
01995 inline void
01996 PP_List<T>::catenate (PP_List<T>& list2)
01997 {
01998 if (list2.isEmpty())
01999
02000
02001
02002 ;
02003 else if (isEmpty())
02004 {
02005 head = list2.head;
02006 tail = list2.tail;
02007 list2.head = 0;
02008 list2.tail = 0;
02009 }
02010 else
02011 {
02012 tail->suc = list2.head;
02013 list2.head->pre = tail;
02014 tail = list2.tail;
02015 list2.head = 0;
02016 list2.tail = 0;
02017 }
02018 }
02019
02020 template <class T>
02021 inline void
02022 PP_List<T>::clear ()
02023 {
02024 PP_ListLink<T>* next = 0;
02025
02026 for (PP_ListLink<T>* p = head; p != 0; p = next)
02027 {
02028 next = p->suc;
02029 p->suc = 0;
02030 delete p;
02031 }
02032 tail = head = 0;
02033 }
02034
02035 template <class T>
02036 inline bool
02037 PP_List<T>::includes (const T& v) const
02038 {
02039 bool rc = false;
02040 for (PP_ListIterator<T> li(*this); li && !rc; ++li)
02041 if (v == li())
02042 rc = true;
02043 return rc;
02044 }
02045
02046 template<class T>
02047 inline bool
02048 PP_List<T>::operator== (const PP_List<T>& rhs) const
02049 {
02050 if (length() == rhs.length())
02051 {
02052 for (PP_ListIterator<T> li(*this), ri(rhs); li; ++li, ++ri)
02053 if (li() != ri())
02054 return false;
02055 return true;
02056 }
02057
02058 return false;
02059 }
02060
02061 template<class T>
02062 inline bool
02063 PP_List<T>::operator!= (const PP_List<T>& rhs) const
02064 {
02065 return !operator==(rhs);
02066 }
02067
02068 template <class T>
02069 inline void
02070 PP_List<T>::remove (PP_ListIterator<T>& li)
02071 {
02072 PP_ListLink<T> *np = li.p->suc;
02073 remove(li.p);
02074 li.p = np;
02075 }
02076
02077 template <class T>
02078 inline void
02079 PP_List<T>::remove (const T& _v)
02080 {
02081 for (PP_ListIterator<T> litr(*this); litr; ++litr)
02082 if (litr() == _v)
02083 remove(litr);
02084 }
02085
02086 template <class T>
02087 inline void
02088 PP_List<T>::remove (const PP_List<T>& _lv)
02089 {
02090 for (PP_ListIterator<T> litr(_lv); litr; ++litr)
02091 remove(litr());
02092 }
02093
02094 template <class T>
02095 inline void
02096 PP_List<T>::remove (PP_ListLink<T>* ln)
02097 {
02098 CH_assert(head !=0 && tail != 0);
02099
02100 if (head == ln && tail == ln)
02101 head = tail = 0;
02102 else if (head == ln)
02103 {
02104 CH_assert(ln->pre == 0);
02105 head = ln->suc;
02106 head->pre = 0;
02107 }
02108 else if (tail == ln)
02109 {
02110 CH_assert(ln->suc == 0);
02111 tail = ln->pre;
02112 tail->suc = 0;
02113 }
02114 else
02115 {
02116 CH_assert(ln->suc != 0 && ln->pre != 0);
02117 ln->suc->pre = ln->pre;
02118 ln->pre->suc = ln->suc;
02119 }
02120 delete ln;
02121 ln = 0;
02122 }
02123
02124 template <class T> class PP_Array;
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165 template <class T>
02166 class PP_Array
02167 {
02168 public:
02169
02170
02171
02172 PP_Array ();
02173
02174
02175
02176
02177 PP_Array (long len);
02178
02179
02180
02181
02182 PP_Array (long len,
02183 const T& initialvalue);
02184
02185
02186
02187
02188 PP_Array (const T* vec,
02189 long len);
02190
02191
02192
02193 PP_Array (const PP_Array<T>& rhs);
02194
02195
02196
02197
02198 PP_Array<T>& operator= (const PP_Array<T>& rhs);
02199
02200
02201
02202 ~PP_Array ();
02203
02204
02205
02206
02207 void clear ();
02208
02209
02210
02211 bool ready () const;
02212
02213
02214
02215
02216 void reserve (long _truesize);
02217
02218
02219
02220
02221
02222
02223
02224 void shrinkWrap ();
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234 void resize (long newlen);
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244 void resize (long newlen,
02245 const T& initialvalue);
02246
02247
02248
02249 long length () const;
02250
02251
02252
02253
02254 long trueSize () const;
02255
02256
02257
02258
02259
02260 T& operator[] (long K);
02261
02262
02263
02264 const T& operator[] (long K) const;
02265
02266
02267
02268 T& get (long i);
02269
02270
02271
02272 const T& get (long i) const;
02273
02274
02275
02276
02277
02278 T* dataPtr ();
02279
02280
02281
02282 const T* dataPtr () const;
02283
02284
02285
02286 void set (long i,
02287 const T& elem);
02288
02289
02290
02291 void swap (long i,
02292 long j);
02293
02294
02295
02296 bool operator== (const PP_Array<T>& rhs) const;
02297
02298
02299
02300 bool operator!= (const PP_Array<T>& rhs) const;
02301
02302 protected:
02303
02304
02305
02306 long truesize;
02307
02308
02309
02310 long nelem;
02311
02312
02313
02314 T* vp;
02315
02316 private:
02317
02318
02319
02320 PP_Array<T>& operator= (int);
02321 };
02322
02323
02324
02325
02326
02327 template <class T>
02328 inline
02329 PP_Array<T>::PP_Array ()
02330 {
02331 nelem = 0;
02332 vp = new T[1];
02333 truesize = 1;
02334 }
02335
02336 template <class T>
02337 inline
02338 PP_Array<T>::PP_Array (long len)
02339 {
02340 CH_assert(len >= 0);
02341 nelem = len;
02342 vp = new T[len];
02343 truesize = nelem;
02344 }
02345
02346 template <class T>
02347 inline
02348 void
02349 PP_Array<T>::clear ()
02350 {
02351 delete [] vp;
02352 vp = 0;
02353 nelem = 0;
02354 truesize = 0;
02355 }
02356
02357 template <class T>
02358 inline
02359 PP_Array<T>::~PP_Array ()
02360 {
02361 clear();
02362 }
02363
02364 template <class T>
02365 inline
02366 bool
02367 PP_Array<T>::ready () const
02368 {
02369 return vp != 0 && nelem != 0;
02370 }
02371
02372 template <class T>
02373 inline
02374 long
02375 PP_Array<T>::length () const
02376 {
02377 return nelem;
02378 }
02379
02380 template <class T>
02381 inline
02382 long
02383 PP_Array<T>::trueSize () const
02384 {
02385 return truesize;
02386 }
02387
02388 template <class T>
02389 inline
02390 T&
02391 PP_Array<T>::operator[] (long i)
02392 {
02393 CH_assert(vp != 0);
02394 CH_assert(i >= 0 && i < nelem);
02395 return vp[i];
02396 }
02397
02398 template <class T>
02399 inline
02400 const T&
02401 PP_Array<T>::operator[] (long i) const
02402 {
02403 CH_assert(vp != 0);
02404 CH_assert(i >= 0 && i < nelem);
02405 return vp[i];
02406 }
02407
02408 template <class T>
02409 inline
02410 T&
02411 PP_Array<T>::get (long i)
02412 {
02413 CH_assert(vp != 0);
02414 CH_assert(i >= 0 && i < nelem);
02415 return vp[i];
02416 }
02417
02418 template <class T>
02419 inline
02420 const T&
02421 PP_Array<T>::get (long i) const
02422 {
02423 CH_assert(vp != 0);
02424 CH_assert(i >= 0 && i < nelem);
02425 return vp[i];
02426 }
02427
02428 template <class T>
02429 inline
02430 void
02431 PP_Array<T>::set (long i,
02432 const T& elem)
02433 {
02434 CH_assert(vp != 0);
02435 CH_assert(i >= 0 && i < nelem);
02436 vp[i] = elem;
02437 }
02438
02439 template <class T>
02440 inline
02441 T*
02442 PP_Array<T>::dataPtr ()
02443 {
02444 return vp;
02445 }
02446
02447 template <class T>
02448 inline
02449 const T*
02450 PP_Array<T>::dataPtr () const
02451 {
02452 return vp;
02453 }
02454
02455 template <class T>
02456 inline
02457 void
02458 PP_Array<T>::swap (long i,
02459 long j)
02460 {
02461 CH_assert(i >= 0 && i < nelem);
02462 CH_assert(j >= 0 && j < nelem);
02463 T tmp = vp[i];
02464 vp[i] = vp[j];
02465 vp[j] = tmp;
02466 }
02467
02468 template <class T>
02469 inline
02470 bool
02471 PP_Array<T>::operator!= (const PP_Array<T>& rhs) const
02472 {
02473 return !(operator==(rhs));
02474 }
02475
02476
02477
02478
02479
02480 template <class T>
02481 PP_Array<T>::PP_Array (long len,
02482 const T& initialValue)
02483 {
02484 CH_assert(len >= 0);
02485 nelem = len;
02486 vp = new T[len];
02487 truesize = nelem;
02488 for (long i = 0; i < nelem; ++i)
02489 vp[i] = initialValue;
02490 }
02491
02492 template <class T>
02493 PP_Array<T>::PP_Array (const T* vec,
02494 long len)
02495 {
02496 CH_assert(len >= 0);
02497 nelem = len;
02498 vp = new T[len];
02499 truesize = nelem;
02500 for (long i = 0; i < nelem; ++i)
02501 vp[i] = vec[i];
02502 }
02503
02504 template <class T>
02505 PP_Array<T>::PP_Array (const PP_Array<T>& a)
02506 {
02507 nelem = a.nelem;
02508 vp = new T[nelem];
02509 truesize = nelem;
02510 for (long i = 0; i < nelem; i++)
02511 vp[i] = a.vp[i];
02512 }
02513
02514 template <class T>
02515 PP_Array<T>&
02516 PP_Array<T>::operator= (const PP_Array<T>& sa)
02517 {
02518 if (this != &sa)
02519 {
02520 clear();
02521 vp = new T[sa.nelem];
02522 nelem = sa.nelem;
02523 truesize = nelem;
02524 for (long i = 0; i < nelem; i++)
02525 vp[i] = sa.vp[i];
02526 }
02527 return *this;
02528 }
02529
02530 template <class T>
02531 inline
02532 void
02533 PP_Array<T>::resize (long newlen)
02534 {
02535 if (newlen == nelem)
02536 return;
02537 if (newlen <= truesize)
02538 {
02539 nelem = newlen;
02540 return;
02541 }
02542 T* newvp = new T[newlen];
02543 long len = Min(newlen,nelem);
02544 for (long i = 0; i < len; i++)
02545 newvp[i] = vp[i];
02546 delete [] vp;
02547 vp = newvp;
02548 nelem = newlen;
02549 truesize = newlen;
02550 }
02551
02552 template <class T>
02553 inline
02554 void PP_Array<T>::resize (long newlen,
02555 const T& initialValue)
02556 {
02557 if (newlen == nelem)
02558 return;
02559 if (newlen <= truesize)
02560 {
02561 for (long i = nelem; i < newlen; ++i)
02562 vp[i] = initialValue;
02563 nelem = newlen;
02564 return;
02565 }
02566 T* newvp = new T[newlen];
02567 long len = Min(newlen,nelem);
02568 long i;
02569 for (i = 0; i < len; i++)
02570 newvp[i] = vp[i];
02571 for (i = len; i < newlen; ++i)
02572 newvp[i] = initialValue;
02573 delete [] vp;
02574 vp = newvp;
02575 nelem = newlen;
02576 truesize = newlen;
02577 }
02578
02579 template <class T>
02580 void
02581 PP_Array<T>::reserve (long _truesize)
02582 {
02583 if (_truesize > truesize)
02584 {
02585 T* newvp = new T[_truesize];
02586 for (long i = 0; i < nelem; i++)
02587 newvp[i] = vp[i];
02588 delete [] vp;
02589 vp = newvp;
02590 truesize = _truesize;
02591 }
02592 }
02593
02594 template <class T>
02595 void
02596 PP_Array<T>::shrinkWrap ()
02597 {
02598 if (nelem != truesize)
02599 {
02600 T* newvp = new T[nelem];
02601 for (long i = 0; i < nelem; i++)
02602 newvp[i] = vp[i];
02603 delete [] vp;
02604 vp = newvp;
02605 truesize = nelem;
02606 }
02607 }
02608
02609 template <class T>
02610 bool
02611 PP_Array<T>::operator== (const PP_Array<T>& rhs) const
02612 {
02613 if (length() != rhs.length())
02614 return false;
02615
02616 for (long i = 0; i < length(); ++i)
02617 if (!((*this)[i] == rhs[i]))
02618 return false;
02619
02620 return true;
02621 }
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773 class PP_entry;
02774
02775 #endif //for the doxygen thing
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849 class ParmParse
02850 {
02851 friend class PP_entry;
02852 public:
02853
02854
02855
02856
02857
02858
02859
02860
02861
02862
02863 ParmParse (int argc,
02864 char** argv,
02865 const char* prefix = 0,
02866 const char* parfile = 0);
02867
02868
02869
02870
02871 void define (int argc,
02872 char** argv,
02873 const char* prefix = 0,
02874 const char* parfile = 0);
02875
02876
02877
02878
02879
02880
02881
02882
02883 ParmParse (const char* prefix = 0);
02884
02885
02886 ParmParse(const std::string& a_string);
02887
02888
02889
02890
02891
02892 ~ParmParse();
02893
02894
02895
02896
02897
02898 bool contains (const char* name) const;
02899
02900
02901
02902
02903
02904 bool contains (const std::string& name) const;
02905
02906
02907
02908
02909
02910
02911 int countval (const char* name,
02912 int n = -1) const;
02913
02914
02915
02916
02917
02918 int countname (const char* name) const;
02919
02920
02921
02922
02923
02924 int countname (const std::string& name) const;
02925
02926
02927
02928
02929
02930
02931
02932 void addEntries (const std::string& strEntry)
02933 {
02934 int len = (int)strEntry.size() + 1;
02935 bldTable(strEntry.c_str(), len, table);
02936 }
02937
02938
02939
02940
02941
02942
02943
02944
02945
02946
02947
02948
02949 template <typename TYPE>
02950 void setVal (const std::string& varName, TYPE varVal)
02951 {
02952 std::string valStr =
02953 static_cast<std::ostringstream*>( &(std::ostringstream() << varVal) )->str();
02954 std::string inEntry = varName + " = " + valStr;
02955 addEntries(inEntry);
02956 }
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969 void setStr (const std::string& varName, std::string varVal)
02970 {
02971 std::string inEntry = varName + " = " + varVal;
02972 addEntries(inEntry);
02973 }
02974
02975
02976
02977
02978
02979 void dumpTable (std::ostream& os) const;
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989
02990 void get (const char* name,
02991 int& ref,
02992 int ival=0) const;
02993
02994
02995
02996
02997
02998
02999
03000
03001
03002
03003
03004 int query (const char* name,
03005 int& ref,
03006 int ival=0) const;
03007
03008
03009
03010
03011
03012
03013
03014
03015
03016
03017 void get (const char* name,
03018 unsigned long& ref,
03019 int ival=0) const;
03020
03021
03022
03023
03024
03025
03026
03027
03028
03029
03030
03031 int query (const char* name,
03032 unsigned long& ref,
03033 int ival=0) const;
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044 void get (const char* name,
03045 float& ref,
03046 int ival=0) const;
03047
03048
03049
03050
03051
03052
03053
03054
03055
03056
03057
03058 int query (const char* name,
03059 float& ref,
03060 int ival=0) const;
03061
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071 void get (const char* name,
03072 double& ref,
03073 int ival=0) const;
03074
03075
03076
03077
03078
03079
03080
03081
03082
03083
03084
03085 int query (const char* name,
03086 double& ref,
03087 int ival=0) const;
03088
03089
03090
03091
03092
03093
03094
03095
03096
03097
03098 void get (const char* name,
03099 std::string& ref,
03100 int ival=0) const;
03101
03102
03103
03104
03105
03106
03107
03108
03109
03110
03111
03112 int query (const char* name,
03113 std::string& ref,
03114 int ival=0) const;
03115
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127 void get (const char* name,
03128 bool& ref,
03129 int ival=0) const;
03130
03131
03132
03133
03134
03135
03136
03137
03138
03139
03140
03141
03142
03143 int query (const char* name,
03144 bool& ref,
03145 int ival=0) const;
03146
03147
03148
03149
03150
03151
03152
03153
03154
03155
03156
03157
03158
03159
03160 void getarr (const char* name,
03161 Vector<int>& ref,
03162 int start_ix,
03163 int num_val) const;
03164
03165
03166
03167
03168
03169
03170
03171
03172
03173
03174
03175
03176
03177
03178 void getarr (const char* name,
03179 std::vector<int>& ref,
03180 int start_ix,
03181 int num_val) const;
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193
03194
03195
03196
03197 int queryarr (const char* name,
03198 Vector<int>& ref,
03199 int start_ix,
03200 int num_val) const;
03201
03202
03203
03204
03205
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216 int queryarr (const char* name,
03217 std::vector<int>& ref,
03218 int start_ix,
03219 int num_val) const;
03220
03221
03222
03223
03224
03225
03226
03227
03228
03229
03230
03231
03232
03233
03234 void getarr (const char* name,
03235 Vector<unsigned long>& ref,
03236 int start_ix,
03237 int num_val) const;
03238
03239
03240
03241
03242
03243
03244
03245
03246
03247
03248
03249
03250
03251
03252 void getarr (const char* name,
03253 std::vector<unsigned long>& ref,
03254 int start_ix,
03255 int num_val) const;
03256
03257
03258
03259
03260
03261
03262
03263
03264
03265
03266
03267
03268
03269
03270
03271 int queryarr (const char* name,
03272 Vector<unsigned long>& ref,
03273 int start_ix,
03274 int num_val) const;
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285
03286
03287
03288
03289
03290 int queryarr (const char* name,
03291 std::vector<unsigned long>& ref,
03292 int start_ix,
03293 int num_val) const;
03294
03295
03296
03297
03298
03299
03300
03301
03302
03303
03304
03305
03306
03307
03308 void getarr (const char* name,
03309 Vector<float>& ref,
03310 int start_ix,
03311 int num_val) const;
03312
03313
03314
03315
03316
03317
03318
03319
03320
03321
03322
03323
03324
03325
03326 void getarr (const char* name,
03327 std::vector<float>& ref,
03328 int start_ix,
03329 int num_val) const;
03330
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343
03344
03345 int queryarr (const char* name,
03346 Vector<float>& ref,
03347 int start_ix,
03348 int num_val) const;
03349
03350
03351
03352
03353
03354
03355
03356
03357
03358
03359
03360
03361
03362
03363
03364 int queryarr (const char* name,
03365 std::vector<float>& ref,
03366 int start_ix,
03367 int num_val) const;
03368
03369
03370
03371
03372
03373
03374
03375
03376
03377
03378
03379
03380
03381
03382 void getarr (const char* name,
03383 Vector<double>& ref,
03384 int start_ix,
03385 int num_val) const;
03386
03387
03388
03389
03390
03391
03392
03393
03394
03395
03396
03397
03398
03399
03400 void getarr (const char* name,
03401 std::vector<double>& ref,
03402 int start_ix,
03403 int num_val) const;
03404
03405
03406
03407
03408
03409
03410
03411
03412
03413
03414
03415
03416
03417
03418
03419 int queryarr (const char* name,
03420 Vector<double>& ref,
03421 int start_ix,
03422 int num_val) const;
03423
03424
03425
03426
03427
03428
03429
03430
03431
03432
03433
03434
03435
03436
03437
03438 int queryarr (const char* name,
03439 std::vector<double>& ref,
03440 int start_ix,
03441 int num_val) const;
03442
03443
03444
03445
03446
03447
03448
03449
03450
03451
03452
03453
03454
03455
03456 void getarr (const char* name,
03457 Vector<std::string>& ref,
03458 int start_ix,
03459 int num_val) const;
03460
03461
03462
03463
03464
03465
03466
03467
03468
03469
03470
03471
03472
03473
03474 void getarr (const char* name,
03475 std::vector<std::string>& ref,
03476 int start_ix,
03477 int num_val) const;
03478
03479
03480
03481
03482
03483
03484
03485
03486
03487
03488
03489
03490
03491
03492
03493 int queryarr (const char* name,
03494 Vector<std::string>& ref,
03495 int start_ix,
03496 int num_val) const;
03497
03498
03499
03500
03501
03502
03503
03504
03505
03506
03507
03508
03509
03510
03511
03512 int queryarr (const char* name,
03513 std::vector<std::string>& ref,
03514 int start_ix,
03515 int num_val) const;
03516
03517
03518
03519
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529
03530 void getarr (const char* name,
03531 Vector<bool>& ref,
03532 int start_ix,
03533 int num_val) const;
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545
03546
03547
03548 void getarr (const char* name,
03549 std::vector<bool>& ref,
03550 int start_ix,
03551 int num_val) const;
03552
03553
03554
03555
03556
03557
03558
03559
03560
03561
03562
03563
03564
03565
03566
03567 int queryarr (const char* name,
03568 Vector<bool>& ref,
03569 int start_ix,
03570 int num_val) const;
03571
03572
03573
03574
03575
03576
03577
03578
03579
03580
03581
03582
03583
03584
03585
03586 int queryarr (const char* name,
03587 std::vector<bool>& ref,
03588 int start_ix,
03589 int num_val) const;
03590
03591
03592 inline const char* prefix() const
03593 {
03594 return thePrefix.c_str();
03595 }
03596
03597 #ifndef DOXYGEN
03598
03599
03600
03601 enum PPType
03602 {
03603 ppDefn,
03604 ppOption,
03605 ppInt,
03606 ppUnsignedLong,
03607 ppFloat,
03608 ppDouble,
03609 ppString,
03610 ppBool,
03611 ppEQ_sign,
03612 ppEOF
03613 };
03614
03615
03616 protected:
03617
03618
03619
03620 static PP_List<PP_entry*> table;
03621
03622
03623
03624 static int xargc;
03625 static char** xargv;
03626
03627
03628
03629 static int num_obj;
03630
03631
03632
03633 void bldTable (const char* str,
03634 int lenstr,
03635 PP_List<PP_entry*>& tab);
03636
03637
03638
03639 void addDefn (PP_String& def,
03640 PP_List<PP_String>& val,
03641 PP_List<PP_entry*>& tab);
03642
03643
03644
03645 void read_file (const char* fname,
03646 PP_List<PP_entry*>& tab);
03647
03648
03649
03650 PPType getToken (const char*,
03651 int&,
03652 int,
03653 char*);
03654
03655
03656
03657 void rmTable ();
03658
03659
03660
03661 PP_String thePrefix;
03662
03663
03664
03665 void ppinit (const char* parfile);
03666
03667
03668
03669 const PP_entry* ppindex (int n,
03670 const char* name) const;
03671
03672
03673
03674
03675
03676
03677
03678
03679 void getval (const char* name,
03680 const PPType type,
03681 void* ptr,
03682 int ival,
03683 int k=-1) const;
03684 public:
03685
03686
03687
03688 void getarr (const char* name,
03689 const PPType type,
03690 void* ptr,
03691 int start_ix,
03692 int num_val,
03693 int k=-1) const;
03694 int queryval (const char* name,
03695 const PPType type,
03696 void* ptr,
03697 int ival,
03698 int k=-1) const;
03699 int queryarr (const char* name,
03700 const PPType type,
03701 void* ptr,
03702 int start_ix,
03703 int num_val,
03704 int k=-1) const;
03705
03706 private:
03707 bool isInteger (const PP_String& str, int& val) const;
03708 bool isUnsigned(const PP_String& str, unsigned long& val) const;
03709 int isDouble (const PP_String& str, double& val) const;
03710 bool isBool (const PP_String& str, bool& val) const;
03711
03712 #endif
03713
03714 };
03715
03716 #ifndef DOXYGEN
03717 class PP_entry
03718 {
03719 private:
03720 friend class ParmParse;
03721 PP_entry()
03722 {}
03723
03724 PP_entry (PP_String& name,
03725 ParmParse::PPType typ,
03726 PP_List<PP_String>& vals);
03727
03728 ~PP_entry()
03729 {}
03730
03731 PP_String defname;
03732 ParmParse::PPType deftype;
03733 PP_Array<PP_String> val;
03734
03735 void dump (std::ostream& os) const;
03736 };
03737 #endif //doxygen
03738
03739
03740
03741
03742
03743 inline
03744 int
03745 ParmParse::countval (const char* name,
03746 int n) const
03747 {
03748
03749
03750
03751 const PP_entry* def = ppindex(n,name);
03752 return def == 0 ? 0 : def->val.length();
03753 }
03754
03755 inline
03756 void
03757 ParmParse::get (const char* name,
03758 int& ptr,
03759 int ival) const
03760 {
03761 getval(name,ppInt,&ptr,ival,-1);
03762 }
03763
03764 inline
03765 int
03766 ParmParse::query (const char* name,
03767 int& ptr,
03768 int ival) const
03769 {
03770 return queryval(name,ppInt,&ptr,ival,-1);
03771 }
03772
03773 inline
03774 void
03775 ParmParse::get (const char* name,
03776 unsigned long& ptr,
03777 int ival) const
03778 {
03779 getval(name,ppUnsignedLong,&ptr,ival,-1);
03780 }
03781
03782 inline
03783 int
03784 ParmParse::query (const char* name,
03785 unsigned long& ptr,
03786 int ival) const
03787 {
03788 return queryval(name,ppUnsignedLong,&ptr,ival,-1);
03789 }
03790
03791 inline
03792 void
03793 ParmParse::get (const char* name,
03794 float& ptr,
03795 int ival) const
03796 {
03797 getval(name,ppFloat,&ptr,ival,-1);
03798 }
03799
03800 inline
03801 int
03802 ParmParse::query (const char* name,
03803 float& ptr,
03804 int ival) const
03805 {
03806 return queryval(name,ppFloat,&ptr,ival,-1);
03807 }
03808
03809 inline
03810 void
03811 ParmParse::get (const char* name,
03812 double& ptr,
03813 int ival) const
03814 {
03815 getval(name,ppDouble,&ptr,ival,-1);
03816 }
03817
03818 inline
03819 int
03820 ParmParse::query (const char* name,
03821 double& ptr,
03822 int ival) const
03823 {
03824 return queryval(name,ppDouble,&ptr,ival,-1);
03825 }
03826
03827 inline
03828 void
03829 ParmParse::get (const char* name,
03830 std::string& ptr,
03831 int ival) const
03832 {
03833 PP_String pp_string;
03834 getval(name,ppString,&pp_string,ival,-1);
03835 ptr = pp_string.c_str();
03836 }
03837
03838 inline
03839 int
03840 ParmParse::query (const char* name,
03841 std::string& ptr,
03842 int ival) const
03843 {
03844 PP_String pp_string;
03845 int status = queryval(name,ppString,&pp_string,ival,-1);
03846 if (status != 0)
03847 ptr = pp_string.c_str();
03848 return status;
03849 }
03850
03851 inline
03852 void
03853 ParmParse::get(const char* name,
03854 bool& ptr,
03855 int ival) const
03856 {
03857 getval(name,ppBool,&ptr,ival,-1);
03858 }
03859
03860 inline
03861 int
03862 ParmParse::query (const char* name,
03863 bool& ptr,
03864 int ival) const
03865 {
03866 return queryval(name,ppBool,&ptr,ival,-1);
03867 }
03868
03869 inline
03870 void
03871 ParmParse::getarr (const char* name,
03872 std::vector<int>& ptr,
03873 int start_ix,
03874 int num_val) const
03875 {
03876 if (ptr.size() < num_val)
03877 ptr.resize(num_val);
03878 int* c_array = new int[num_val];
03879 getarr(name,ppInt,c_array,start_ix,num_val,-1);
03880 for (int i = 0; i < num_val; ++i)
03881 {
03882 ptr[i] = c_array[i];
03883 }
03884 delete[] c_array;
03885 }
03886
03887 inline
03888 void
03889 ParmParse::getarr (const char* name,
03890 Vector<int>& ptr,
03891 int start_ix,
03892 int num_val) const
03893 {
03894 if (ptr.size() < num_val)
03895 ptr.resize(num_val);
03896 int* c_array = new int[num_val];
03897 getarr(name,ppInt,c_array,start_ix,num_val,-1);
03898 for (int i = 0; i < num_val; ++i)
03899 {
03900 ptr[i] = c_array[i];
03901 }
03902 delete[] c_array;
03903 }
03904
03905 inline
03906 int
03907 ParmParse::queryarr (const char* name,
03908 std::vector<int>& ptr,
03909 int start_ix,
03910 int num_val) const
03911 {
03912 if (ptr.size() < num_val)
03913 ptr.resize(num_val);
03914 int* c_array = new int[num_val];
03915 int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03916 if (status != 0 )
03917 {
03918 for (int i = 0; i < num_val; ++i)
03919 {
03920 ptr[i] = c_array[i];
03921 }
03922 }
03923 delete [] c_array;
03924 return status;
03925 }
03926
03927 inline
03928 int
03929 ParmParse::queryarr (const char* name,
03930 Vector<int>& ptr,
03931 int start_ix,
03932 int num_val) const
03933 {
03934 if (ptr.size() < num_val)
03935 ptr.resize(num_val);
03936 int* c_array = new int[num_val];
03937 int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03938 if (status != 0 )
03939 {
03940 for (int i = 0; i < num_val; ++i)
03941 {
03942 ptr[i] = c_array[i];
03943 }
03944 }
03945 return status;
03946 }
03947
03948 inline
03949 void
03950 ParmParse::getarr (const char* name,
03951 std::vector<float>& ptr,
03952 int start_ix,
03953 int num_val) const
03954 {
03955 if (ptr.size() < num_val)
03956 ptr.resize(num_val);
03957 float* c_array = new float[num_val];
03958 getarr(name,ppFloat,c_array,start_ix,num_val,-1);
03959 for (int i = 0; i < num_val; ++i)
03960 {
03961 ptr[i] = c_array[i];
03962 }
03963 delete[] c_array;
03964 }
03965
03966 inline
03967 void
03968 ParmParse::getarr (const char* name,
03969 Vector<float>& ptr,
03970 int start_ix,
03971 int num_val) const
03972 {
03973 if (ptr.size() < num_val)
03974 ptr.resize(num_val);
03975 float* c_array = new float[num_val];
03976 getarr(name,ppFloat,c_array,start_ix,num_val,-1);
03977 for (int i = 0; i < num_val; ++i)
03978 {
03979 ptr[i] = c_array[i];
03980 }
03981 delete[] c_array;
03982 }
03983
03984 inline
03985 int
03986 ParmParse::queryarr (const char* name,
03987 std::vector<float>& ptr,
03988 int start_ix,
03989 int num_val) const
03990 {
03991 if (ptr.size() < num_val)
03992 ptr.resize(num_val);
03993 float* c_array = new float[num_val];
03994 int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03995 if (status != 0)
03996 {
03997 for (int i = 0; i < num_val; ++i)
03998 {
03999 ptr[i] = c_array[i];
04000 }
04001 }
04002 delete[] c_array;
04003 return status;
04004 }
04005
04006 inline
04007 int
04008 ParmParse::queryarr (const char* name,
04009 Vector<float>& ptr,
04010 int start_ix,
04011 int num_val) const
04012 {
04013 if (ptr.size() < num_val)
04014 ptr.resize(num_val);
04015 float* c_array = new float[num_val];
04016 int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
04017 if (status != 0)
04018 {
04019 for (int i = 0; i < num_val; ++i)
04020 {
04021 ptr[i] = c_array[i];
04022 }
04023 }
04024 delete[] c_array;
04025 return status;
04026 }
04027
04028 inline
04029 void
04030 ParmParse::getarr (const char* name,
04031 std::vector<double>& ptr,
04032 int start_ix,
04033 int num_val) const
04034 {
04035 if (ptr.size() < num_val)
04036 ptr.resize(num_val);
04037 double* c_array = new double[num_val];
04038 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04039 if (status == 0)
04040 {
04041 cerr << "ParmParse::getarr(): "
04042 << name
04043 << " not found in table" << endl;
04044 dumpTable(cerr);
04045 MayDay::Abort();
04046 }
04047 for (int i = 0; i < num_val; ++i)
04048 {
04049 ptr[i] = c_array[i];
04050 }
04051 delete[] c_array;
04052 }
04053
04054 inline
04055 void
04056 ParmParse::getarr (const char* name,
04057 Vector<double>& ptr,
04058 int start_ix,
04059 int num_val) const
04060 {
04061 if (ptr.size() < num_val)
04062 ptr.resize(num_val);
04063 double* c_array = new double[num_val];
04064 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04065 if (status == 0)
04066 {
04067 cerr << "ParmParse::getarr(): "
04068 << name
04069 << " not found in table" << endl;
04070 dumpTable(cerr);
04071 MayDay::Abort();
04072 }
04073 for (int i = 0; i < num_val; ++i)
04074 {
04075 ptr[i] = c_array[i];
04076 }
04077 delete[] c_array;
04078 }
04079
04080 inline
04081 int
04082 ParmParse::queryarr (const char* name,
04083 std::vector<double>& ptr,
04084 int start_ix,
04085 int num_val) const
04086 {
04087 if (ptr.size() < num_val)
04088 ptr.resize(num_val);
04089 double* c_array = new double[num_val];
04090 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04091 if (status != 0)
04092 {
04093 for (int i = 0; i < num_val; ++i)
04094 {
04095 ptr[i] = c_array[i];
04096 }
04097 }
04098 delete[] c_array;
04099 return status;
04100 }
04101
04102 inline
04103 int
04104 ParmParse::queryarr (const char* name,
04105 Vector<double>& ptr,
04106 int start_ix,
04107 int num_val) const
04108 {
04109 if (ptr.size() < num_val)
04110 ptr.resize(num_val);
04111 double* c_array = new double[num_val];
04112 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04113 if (status != 0)
04114 {
04115 for (int i = 0; i < num_val; ++i)
04116 {
04117 ptr[i] = c_array[i];
04118 }
04119 }
04120 delete[] c_array;
04121 return status;
04122 }
04123
04124 inline
04125 void
04126 ParmParse::getarr (const char* name,
04127 std::vector<std::string>& ptr,
04128 int start_ix,
04129 int num_val) const
04130 {
04131 if (ptr.size() < num_val)
04132 ptr.resize(num_val);
04133 PP_String* c_array = new PP_String[num_val];
04134 getarr(name,ppString,c_array,start_ix,num_val,-1);
04135 for (int i = 0; i < num_val; ++i)
04136 {
04137 ptr[i] = c_array[i].c_str();
04138 }
04139 delete[] c_array;
04140 }
04141
04142 inline
04143 void
04144 ParmParse::getarr (const char* name,
04145 Vector<std::string>& ptr,
04146 int start_ix,
04147 int num_val) const
04148 {
04149 if (ptr.size() < num_val)
04150 ptr.resize(num_val);
04151 PP_String* c_array = new PP_String[num_val];
04152 getarr(name,ppString,c_array,start_ix,num_val,-1);
04153 for (int i = 0; i < num_val; ++i)
04154 {
04155 ptr[i] = c_array[i].c_str();
04156 }
04157 delete[] c_array;
04158 }
04159
04160 inline
04161 int
04162 ParmParse::queryarr (const char* name,
04163 std::vector<std::string>& ptr,
04164 int start_ix,
04165 int num_val) const
04166 {
04167 if (ptr.size() < num_val)
04168 ptr.resize(num_val);
04169 PP_String* c_array = new PP_String[num_val];
04170 int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
04171 if (status != 0)
04172 {
04173 for (int i = 0; i < num_val; ++i)
04174 {
04175 ptr[i] = c_array[i].c_str();
04176 }
04177 }
04178 delete[] c_array;
04179 return status;
04180 }
04181
04182 inline
04183 int
04184 ParmParse::queryarr (const char* name,
04185 Vector<std::string>& ptr,
04186 int start_ix,
04187 int num_val) const
04188 {
04189 if (ptr.size() < num_val)
04190 ptr.resize(num_val);
04191 PP_String* c_array = new PP_String[num_val];
04192 int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
04193 if (status != 0)
04194 {
04195 for (int i = 0; i < num_val; ++i)
04196 {
04197 ptr[i] = c_array[i].c_str();
04198 }
04199 }
04200 delete[] c_array;
04201 return status;
04202 }
04203
04204
04205 inline
04206 void
04207 ParmParse::getarr (const char* name,
04208 std::vector<bool>& ptr,
04209 int start_ix,
04210 int num_val) const
04211 {
04212 if (ptr.size() < num_val)
04213 ptr.resize(num_val);
04214 bool* c_array = new bool[num_val];
04215 getarr(name,ppBool,c_array,start_ix,num_val,-1);
04216 for (int i = 0; i < num_val; ++i)
04217 {
04218 ptr[i] = c_array[i];
04219 }
04220 delete[] c_array;
04221 }
04222
04223 inline
04224 int
04225 ParmParse::queryarr (const char* name,
04226 std::vector<bool>& ptr,
04227 int start_ix,
04228 int num_val) const
04229 {
04230 if (ptr.size() < num_val)
04231 ptr.resize(num_val);
04232 bool* c_array = new bool[num_val];
04233 int status = queryarr(name,ppBool,c_array,start_ix,num_val,-1);
04234 if (status != 0 )
04235 {
04236 for (int i = 0; i < num_val; ++i)
04237 {
04238 ptr[i] = c_array[i];
04239 }
04240 }
04241 delete [] c_array;
04242 return status;
04243 }
04244
04245
04246
04247 inline
04248 bool
04249 ParmParse::isInteger (const PP_String& str,
04250 int& val) const
04251 {
04252
04253
04254
04255 char* endp = 0;
04256 val = (int) strtol(str.c_str(), &endp, 10);
04257 return *endp == 0;
04258 }
04259
04260 inline
04261 bool
04262 ParmParse::isUnsigned (const PP_String& str,
04263 unsigned long & val) const
04264 {
04265 char* endp = 0;
04266 val = strtoul(str.c_str(), &endp, 10);
04267 return *endp == 0;
04268 }
04269
04270 inline
04271 int
04272 ParmParse::isDouble (const PP_String& str,
04273 double& val) const
04274 {
04275 char* endp = 0;
04276 val = std::strtod(str.c_str(), &endp);
04277 return *endp == 0;
04278 }
04279
04280 inline
04281 bool
04282 ParmParse::isBool (const PP_String& str,
04283 bool& val) const
04284 {
04285 PP_String str_lc( str );
04286 str_lc.toLower();
04287 if ( str_lc == "true" || str_lc == "1" )
04288 {
04289 return val = true ;
04290 }
04291 else if ( str_lc == "false" || str_lc == "0" )
04292 {
04293 val = false ;
04294 return true ;
04295 }
04296 else
04297 {
04298 return false ;
04299 }
04300 }
04301
04302 inline
04303 int
04304 ParmParse::countname (const std::string& name) const
04305 {
04306 return countname(name.c_str());
04307 }
04308
04309 #include "BaseNamespaceFooter.H"
04310 #endif