00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef _PARMPARSE_H_
00053 #define _PARMPARSE_H_
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #include <iostream>
00069 #include <iomanip>
00070 #include <cstdlib>
00071 #include <string>
00072 #include <vector>
00073
00074 #include "SPACE.H"
00075 #include "MayDay.H"
00076 #include "Misc.H"
00077 #include "Vector.H"
00078 using std::cout;
00079 using std::cerr;
00080 using std::endl;
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 #ifndef DOXYGEN
00098 class PP_UseCount
00099 {
00100 public:
00101
00103
00104 PP_UseCount ();
00105
00107
00108 PP_UseCount (const PP_UseCount& rhs);
00109
00114 PP_UseCount& operator= (const PP_UseCount& rhs);
00115
00117
00118 ~PP_UseCount ();
00119
00121
00122 bool unique () const;
00123
00125
00126 int linkCount () const;
00127
00128 private:
00129
00130
00131
00132 unsigned int* cnt;
00133
00134
00135
00136
00137 void decrement ();
00138 };
00139
00140
00141
00142
00143
00144 inline
00145 PP_UseCount::PP_UseCount ()
00146 :
00147 cnt(new unsigned int(1))
00148 {}
00149
00150 inline
00151 PP_UseCount::PP_UseCount (const PP_UseCount& rhs)
00152 :
00153 cnt(rhs.cnt)
00154 {
00155 ++*cnt;
00156 }
00157
00158 inline
00159 bool
00160 PP_UseCount::unique () const
00161 {
00162 return *cnt == 1;
00163 }
00164
00165 inline
00166 void
00167 PP_UseCount::decrement ()
00168 {
00169 if (unique())
00170 {
00171 delete cnt;
00172 cnt = 0;
00173 }
00174 else
00175 --*cnt;
00176 }
00177
00178 inline
00179 PP_UseCount&
00180 PP_UseCount::operator= (const PP_UseCount& rhs)
00181 {
00182 ++*rhs.cnt;
00183 decrement();
00184 cnt = rhs.cnt;
00185 return *this;
00186 }
00187
00188 inline
00189 PP_UseCount::~PP_UseCount ()
00190 {
00191 decrement();
00192 }
00193
00194 inline
00195 int
00196 PP_UseCount::linkCount () const
00197 {
00198 return *cnt;
00199 }
00200
00202
00219 template <class T>
00220 class PP_CpPtr
00221 {
00222 public:
00223
00225
00226 PP_CpPtr ();
00227
00229
00230 PP_CpPtr (T* rhs);
00231
00233
00234 ~PP_CpPtr ();
00235
00244 PP_CpPtr (const PP_CpPtr<T>& rhs);
00245
00249 PP_CpPtr<T>& operator= (T* rhs);
00250
00259 PP_CpPtr<T>& operator= (const PP_CpPtr<T>& rhs);
00260
00266 T& operator* () const;
00267
00269
00270 bool isNull () const;
00271
00273
00274 T* release ();
00275
00277
00278 bool operator== (const PP_CpPtr<T>& rhs) const;
00279
00281
00282 bool operator!= (const PP_CpPtr<T>& rhs) const;
00283
00284 protected:
00285 T* ptr;
00286 };
00287
00289
00301 template<class T>
00302 class PP_CpClassPtr :
00303 public PP_CpPtr<T>
00304 {
00305 public:
00306
00308
00309 PP_CpClassPtr ();
00310
00312
00313 PP_CpClassPtr (T* rhs);
00314
00323 PP_CpClassPtr (const PP_CpClassPtr<T>& rhs);
00324
00328 PP_CpClassPtr<T>& operator= (T* rhs);
00329
00338 PP_CpClassPtr<T>& operator= (const PP_CpClassPtr<T>& rhs);
00339
00341
00342 T* operator-> () const;
00343 };
00344
00346
00359 template<class T>
00360 class PP_LnPtr
00361 {
00362 public:
00363
00365
00366 PP_LnPtr ();
00367
00369
00370 PP_LnPtr (T* rhs);
00371
00377 PP_LnPtr<T>& operator= (const PP_LnPtr<T>& rhs);
00378
00383 PP_LnPtr<T>& operator= (T* rhs)
00384 {
00385
00386
00387
00388 if (unique())
00389 delete ptr;
00390 ptr = rhs;
00391 ucnt = PP_UseCount();
00392 return *this;
00393 }
00394
00398 ~PP_LnPtr ();
00399
00401
00402 bool unique () const;
00403
00405
00406 int linkCount () const;
00407
00413 T& operator* () const;
00414
00416
00417 bool isNull () const;
00418
00420
00421 bool operator== (const PP_LnPtr<T>& rhs) const;
00422
00424
00425 bool operator!= (const PP_LnPtr<T>& rhs) const;
00426
00427 protected:
00428 T* ptr;
00429
00430 private:
00431 PP_UseCount ucnt;
00432 };
00433
00435
00446 template<class T>
00447 class PP_LnClassPtr
00448 : public PP_LnPtr<T>
00449 {
00450 public:
00451
00453
00454 PP_LnClassPtr ();
00455
00457
00458 PP_LnClassPtr (T* rhs);
00459
00465 PP_LnClassPtr<T>& operator= (const PP_LnClassPtr<T>& rhs);
00466
00471 PP_LnClassPtr<T>& operator= (T* rhs);
00472
00474
00475 T* operator->() const;
00476 };
00477
00478
00479
00480
00481
00482 template <class T>
00483 inline
00484 PP_CpPtr<T>::PP_CpPtr ()
00485 :
00486 ptr(0)
00487 {}
00488
00489 template <class T>
00490 inline
00491 PP_CpPtr<T>::PP_CpPtr(T* rhs)
00492 :
00493 ptr(rhs)
00494 {}
00495
00496 template <class T>
00497 inline
00498 PP_CpPtr<T>::~PP_CpPtr()
00499 {
00500 delete ptr;
00501 }
00502
00503 template <class T>
00504 inline
00505 bool
00506 PP_CpPtr<T>::isNull () const
00507 {
00508 return ptr == 0;
00509 }
00510
00511 template <class T>
00512 inline
00513 PP_CpPtr<T>::PP_CpPtr (const PP_CpPtr<T>& rhs)
00514 {
00515 ptr = rhs.isNull() ? 0 : new T(*rhs.ptr);
00516 }
00517
00518 template <class T>
00519 inline
00520 PP_CpPtr<T>&
00521 PP_CpPtr<T>::operator= (const PP_CpPtr<T>& rhs)
00522 {
00523 if (!(ptr == rhs.ptr))
00524 {
00525 delete ptr;
00526 ptr = rhs.isNull() ? 0 : new T(*rhs.ptr);
00527 }
00528 return *this;
00529 }
00530
00531 template <class T>
00532 inline
00533 PP_CpPtr<T>&
00534 PP_CpPtr<T>::operator= (T* rhs)
00535 {
00536 delete ptr;
00537 ptr = rhs;
00538 return *this;
00539 }
00540
00541 template <class T>
00542 inline
00543 T&
00544 PP_CpPtr<T>::operator* () const
00545 {
00546 CH_assert(ptr != 0);
00547 return *ptr;
00548 }
00549
00550 template <class T>
00551 inline
00552 T*
00553 PP_CpPtr<T>::release ()
00554 {
00555 T* old = ptr;
00556 ptr = 0;
00557 return old;
00558 }
00559
00560 template <class T>
00561 inline
00562 bool
00563 PP_CpPtr<T>::operator== (const PP_CpPtr<T>& rhs) const
00564 {
00565 return ptr == rhs.ptr;
00566 }
00567
00568 template <class T>
00569 inline
00570 bool
00571 PP_CpPtr<T>::operator!= (const PP_CpPtr<T>& rhs) const
00572 {
00573 return ptr != rhs.ptr;
00574 }
00575
00576 template <class T>
00577 inline
00578 PP_CpClassPtr<T>::PP_CpClassPtr ()
00579 :
00580 PP_CpPtr<T>()
00581 {}
00582
00583 template <class T>
00584 inline
00585 PP_CpClassPtr<T>::PP_CpClassPtr (T* rhs)
00586 :
00587 PP_CpPtr<T>(rhs)
00588 {}
00589
00590 template <class T>
00591 inline
00592 PP_CpClassPtr<T>::PP_CpClassPtr (const PP_CpClassPtr<T>& rhs)
00593 :
00594 PP_CpPtr<T>(rhs)
00595 {}
00596
00597 template <class T>
00598 inline
00599 PP_CpClassPtr<T>&
00600 PP_CpClassPtr<T>::operator= (T* rhs)
00601 {
00602 PP_CpPtr<T>::operator= (rhs);
00603 return *this;
00604 }
00605
00606 template <class T>
00607 inline
00608 PP_CpClassPtr<T>&
00609 PP_CpClassPtr<T>::operator= (const PP_CpClassPtr<T>& rhs)
00610 {
00611 PP_CpPtr<T>::operator= (rhs);
00612 return *this;
00613 }
00614
00615 template <class T>
00616 inline
00617 T*
00618 PP_CpClassPtr<T>::operator-> () const
00619 {
00620 return this->ptr;
00621 }
00622
00623 template <class T>
00624 inline
00625 PP_LnPtr<T>::PP_LnPtr ()
00626 :
00627 ptr(0)
00628 {}
00629
00630 template <class T>
00631 inline
00632 PP_LnPtr<T>::PP_LnPtr(T* rhs)
00633 :
00634 ptr(rhs)
00635 {}
00636
00637 template <class T>
00638 inline
00639 bool
00640 PP_LnPtr<T>::unique () const
00641 {
00642 return ucnt.unique();
00643 }
00644
00645 template <class T>
00646 inline
00647 PP_LnPtr<T>::~PP_LnPtr ()
00648 {
00649 if (ucnt.unique())
00650 delete ptr;
00651 }
00652
00653 template <class T>
00654 inline
00655 PP_LnPtr<T>&
00656 PP_LnPtr<T>::operator= (const PP_LnPtr<T>& rhs)
00657 {
00658 if (ptr != rhs.ptr)
00659 {
00660 if (unique())
00661 delete ptr;
00662 ptr = rhs.ptr;
00663 ucnt = rhs.ucnt;
00664 }
00665 return *this;
00666 }
00667
00668 template <class T>
00669 inline
00670 int
00671 PP_LnPtr<T>::linkCount () const
00672 {
00673 return ucnt.linkCount();
00674 }
00675
00676 template <class T>
00677 inline
00678 T&
00679 PP_LnPtr<T>::operator* () const
00680 {
00681 CH_assert(ptr != 0);
00682 return *ptr;
00683 }
00684
00685 template <class T>
00686 inline
00687 bool
00688 PP_LnPtr<T>::isNull () const
00689 {
00690 return ptr == 0;
00691 }
00692
00693 template <class T>
00694 inline
00695 bool
00696 PP_LnPtr<T>::operator== (const PP_LnPtr<T>& rhs) const
00697 {
00698 return ptr == rhs.ptr;
00699 }
00700
00701 template <class T>
00702 inline
00703 bool
00704 PP_LnPtr<T>::operator!= (const PP_LnPtr<T>& rhs) const
00705 {
00706 return ptr != rhs.ptr;
00707 }
00708
00709 template <class T>
00710 inline
00711 PP_LnClassPtr<T>::PP_LnClassPtr ()
00712 {}
00713
00714 template <class T>
00715 inline
00716 PP_LnClassPtr<T>::PP_LnClassPtr (T* rhs)
00717 :
00718 PP_LnPtr<T>(rhs)
00719 {}
00720
00721 template <class T>
00722 inline
00723 PP_LnClassPtr<T>&
00724 PP_LnClassPtr<T>::operator= (const PP_LnClassPtr<T>& rhs)
00725 {
00726 PP_LnPtr<T>::operator=(rhs);
00727 return *this;
00728 }
00729
00730 template <class T>
00731 inline
00732 PP_LnClassPtr<T>&
00733 PP_LnClassPtr<T>::operator= (T* rhs)
00734 {
00735 PP_LnPtr<T>::operator=(rhs);
00736 return *this;
00737 }
00738
00739 template <class T>
00740 inline
00741 T*
00742 PP_LnClassPtr<T>::operator->() const
00743 {
00744 return this->ptr;
00745 }
00746
00747
00748
00749
00750
00751 class PP_StringRep
00752 {
00753 friend class PP_String;
00754 char* s;
00755 int bufferlength;
00756 public:
00757 PP_StringRep (int _len = 0);
00758 ~PP_StringRep ();
00759
00760
00761
00762 void resize (int n);
00763 };
00764
00765
00766
00767
00768
00769 inline
00770 PP_StringRep::PP_StringRep (int _len)
00771 {
00772 bufferlength = _len;
00773 s = new char [bufferlength];
00774 }
00775
00776 inline
00777 PP_StringRep::~PP_StringRep ()
00778 {
00779 delete [] s;
00780 s = 0;
00781 }
00782
00784
00807 class PP_String
00808 {
00809 public:
00810
00812
00813 PP_String ();
00814
00818 PP_String (char c);
00819
00828 PP_String (int len);
00829
00833 PP_String (const char* s);
00834
00836
00837 PP_String (const PP_String& rhs);
00838
00840
00841 PP_String& operator= (const PP_String& rhs);
00842
00846 PP_String& operator+= (const PP_String& right);
00847
00852 PP_String& operator+= (const char* right);
00853
00858 PP_String& operator+= (char c);
00859
00863 PP_String& toUpper ();
00864
00868 PP_String& toLower ();
00869
00876 std::istream& getline (std::istream& strm);
00877
00881 int length () const;
00882
00883
00885
00886 bool isNull () const;
00887
00891 char& operator [] (int k);
00892
00896 char operator[] (int k) const;
00897
00901 const char* c_str () const;
00902
00908 double toDouble () const;
00909
00915 int toInteger () const;
00916
00922 long toLong () const;
00923
00925
00926 friend std::ostream& operator<< (std::ostream& os,
00927 const PP_String& str);
00928
00941 friend std::istream& operator>> (std::istream& is,
00942 PP_String& str);
00943
00944 protected:
00945 void copyModify ();
00946
00947 private:
00948 PP_LnClassPtr<PP_StringRep> p;
00949 int len;
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960 friend inline bool operator< (const PP_String& left,
00961 const PP_String& right);
00962
00963
00964
00965 friend inline bool operator<= (const PP_String& left,
00966 const PP_String& right);
00967
00968
00969
00970 friend inline bool operator!= (const PP_String& left,
00971 const PP_String& right);
00972
00973
00974
00975 friend inline bool operator== (const PP_String& left,
00976 const PP_String& right);
00977
00978
00979
00980 friend inline bool operator>= (const PP_String& left,
00981 const PP_String& right);
00982
00983
00984
00985 friend inline bool operator> (const PP_String& left,
00986 const PP_String& right);
00987
00988
00989
00990 friend inline bool operator< (const PP_String& left,
00991 const char* right);
00992
00993
00994
00995 friend inline bool operator<= (const PP_String& left,
00996 const char* right);
00997
00998
00999
01000 friend inline bool operator!= (const PP_String& left,
01001 const char* right);
01002
01003
01004
01005 friend inline bool operator== (const PP_String& left,
01006 const char* right);
01007
01008
01009
01010 friend inline bool operator>= (const PP_String& left,
01011 const char* right);
01012
01013
01014
01015 friend inline bool operator> (const PP_String& left,
01016 const char* right);
01017
01018
01019
01020 friend inline bool operator< (const char* left,
01021 const PP_String& right);
01022
01023
01024
01025 friend inline bool operator<= (const char* left,
01026 const PP_String& right);
01027
01028
01029
01030 friend inline bool operator!= (const char* left,
01031 const PP_String& right);
01032
01033
01034
01035 friend inline bool operator== (const char* left,
01036 const PP_String& right);
01037
01038
01039
01040 friend inline bool operator>= (const char* left,
01041 const PP_String& right);
01042
01043
01044
01045 friend inline bool operator> (const char* left,
01046 const PP_String& right);
01047 };
01048
01049
01050
01051
01052
01053 inline
01054 bool
01055 PP_String::isNull () const
01056 {
01057 return len == 0;
01058 }
01059
01060 inline
01061 int
01062 PP_String::length () const
01063 {
01064 return len;
01065 }
01066
01067 inline
01068 double
01069 PP_String::toDouble () const
01070 {
01071 return len == 0 ? 0 : std::atof(p->s);
01072 }
01073
01074 inline
01075 int
01076 PP_String::toInteger () const
01077 {
01078 return len == 0 ? 0 : atoi(p->s);
01079 }
01080
01081 inline
01082 long
01083 PP_String::toLong () const
01084 {
01085 return len == 0 ? 0 : atol(p->s);
01086 }
01087
01088 inline
01089 const char*
01090 PP_String::c_str () const
01091 {
01092 return p->s;
01093 }
01094
01095 inline
01096 char
01097 PP_String::operator[] (int index) const
01098 {
01099 CH_assert(index >=0 && index < len);
01100 return p->s[index];
01101 }
01102
01103 inline
01104 PP_String
01105 operator+ (const PP_String& left,
01106 const PP_String& right)
01107 {
01108 PP_String result(left);
01109 return result += right;
01110 }
01111
01112 inline
01113 bool
01114 operator< (const PP_String& left,
01115 const PP_String& right)
01116 {
01117 return ::strcmp(left.c_str(), right.c_str()) < 0;
01118 }
01119
01120 inline
01121 bool
01122 operator<= (const PP_String& left,
01123 const PP_String& right)
01124 {
01125 return ::strcmp(left.c_str(), right.c_str()) <= 0;
01126 }
01127
01128 inline
01129 bool
01130 operator!= (const PP_String& left,
01131 const PP_String& right)
01132 {
01133 return ::strcmp(left.c_str(), right.c_str()) != 0;
01134 }
01135
01136 inline
01137 bool
01138 operator== (const PP_String& left,
01139 const PP_String& right)
01140 {
01141 return ::strcmp(left.c_str(), right.c_str()) == 0;
01142 }
01143
01144 inline
01145 bool
01146 operator>= (const PP_String& left,
01147 const PP_String& right)
01148 {
01149 return ::strcmp(left.c_str(), right.c_str()) >= 0;
01150 }
01151
01152 inline
01153 bool
01154 operator> (const PP_String& left,
01155 const PP_String& right)
01156 {
01157 return ::strcmp(left.c_str(), right.c_str()) > 0;
01158 }
01159
01160 inline
01161 bool
01162 operator< (const PP_String& left,
01163 const char* right)
01164 {
01165 return ::strcmp(left.c_str(), right) < 0;
01166 }
01167
01168 inline
01169 bool
01170 operator<= (const PP_String& left,
01171 const char* right)
01172 {
01173 return ::strcmp(left.c_str(), right) <= 0;
01174 }
01175
01176 inline
01177 bool
01178 operator!= (const PP_String& left,
01179 const char* right)
01180 {
01181 return ::strcmp(left.c_str(), right) != 0;
01182 }
01183
01184 inline
01185 bool
01186 operator== (const PP_String& left,
01187 const char* right)
01188 {
01189 return ::strcmp(left.c_str(), right) == 0;
01190 }
01191
01192 inline
01193 bool
01194 operator>= (const PP_String& left,
01195 const char* right)
01196 {
01197 return ::strcmp(left.c_str(), right) >= 0;
01198 }
01199
01200 inline
01201 bool
01202 operator> (const PP_String& left,
01203 const char* right)
01204 {
01205 return ::strcmp(left.c_str(), right) > 0;
01206 }
01207
01208 inline
01209 bool
01210 operator< (const char* left,
01211 const PP_String& right)
01212 {
01213 return ::strcmp(left, right.c_str()) < 0;
01214 }
01215
01216 inline
01217 bool
01218 operator<= (const char* left,
01219 const PP_String& right)
01220 {
01221 return ::strcmp(left, right.c_str()) <= 0;
01222 }
01223
01224 inline
01225 bool
01226 operator!= (const char* left,
01227 const PP_String& right)
01228 {
01229 return ::strcmp(left, right.c_str()) != 0;
01230 }
01231
01232 inline
01233 bool
01234 operator== (const char* left,
01235 const PP_String& right)
01236 {
01237 return ::strcmp(left, right.c_str()) == 0;
01238 }
01239
01240 inline
01241 bool
01242 operator>= (const char* left,
01243 const PP_String& right)
01244 {
01245 return ::strcmp(left, right.c_str()) >= 0;
01246 }
01247
01248 inline
01249 bool
01250 operator> (const char* left,
01251 const PP_String& right)
01252 {
01253 return ::strcmp(left, right.c_str()) > 0;
01254 }
01255
01256
01257
01258 template <class T> class PP_ListLink;
01259 template <class T> class PP_ListIterator;
01260 template <class T> class PP_List;
01261
01262 template <class T>
01263 class PP_ListLink
01264 {
01265 private:
01266 friend class PP_List<T>;
01267 friend class PP_ListIterator<T>;
01268
01269 PP_ListLink (const T& _val,
01270 PP_ListLink<T>* _pre,
01271 PP_ListLink<T>* _suc)
01272 :
01273 val(_val),
01274 pre(_pre),
01275 suc(_suc)
01276 {}
01277
01278 private:
01279 T val;
01280 PP_ListLink<T>* pre;
01281 PP_ListLink<T>* suc;
01282 };
01283
01285
01295 template <class T>
01296 class PP_ListIterator
01297 {
01298 public:
01299
01301
01302 PP_ListIterator (const PP_List<T>& aList);
01303
01305
01306 PP_ListIterator (const PP_ListIterator<T>& rhs);
01307
01311 void rewind ();
01312
01316 const T& operator() () const;
01317
01321 const T& operator* () const;
01322
01329 operator void* ();
01330
01334 bool operator! () const;
01335
01339 const T& value () const;
01340
01346 PP_ListIterator<T>& operator++ ();
01347
01353 PP_ListIterator<T>& operator-- ();
01354
01361 PP_ListIterator<T> operator-- (int);
01362
01368 PP_ListIterator<T> operator++ (int);
01369
01373 bool operator== (const PP_ListIterator<T>&) const;
01374
01376
01377 bool operator!= (const PP_ListIterator<T>&) const;
01378
01379 protected:
01380
01381
01382
01383 PP_ListIterator (const PP_List<T>& _list,
01384 PP_ListLink<T>* _p);
01385
01386
01387
01388 const PP_List<T>& list;
01389
01390
01391
01392 PP_ListLink<T>* p;
01393
01394 private:
01395 friend class PP_List<T>;
01396
01397
01398
01399 PP_ListIterator ();
01400 PP_ListIterator<T>& operator= (const PP_ListIterator<T>&);
01401 };
01402
01404
01436 template <class T>
01437 class PP_List
01438 {
01439 public:
01440
01442
01443 PP_List ();
01444
01446
01447 PP_List (const PP_List<T>& rhs);
01448
01450
01451 PP_List<T>& operator= (const PP_List<T>& rhs);
01452
01454
01455 ~PP_List();
01456
01458
01459 void prepend (const T& value);
01460
01462
01463 void append (const T& value);
01464
01466
01467 void add (const T& value);
01468
01470
01471 void join (const PP_List<T>& src);
01472
01479 void catenate (PP_List<T>& src);
01480
01482
01483 void clear ();
01484
01486
01487 T& firstElement () const;
01488
01490
01491 T& lastElement () const;
01492
01497 bool includes (const T& value) const;
01498
01504 bool operator== (const PP_List<T>& rhs) const;
01505
01507
01508 bool operator!= (const PP_List<T>& rhs) const;
01509
01511
01512 bool isEmpty () const;
01513
01515
01516 bool isNotEmpty () const;
01517
01519
01520 int length () const;
01521
01523
01524 void removeFirst ();
01525
01527
01528 void removeLast ();
01529
01531
01532 const T& operator[] (const PP_ListIterator<T>& li) const;
01533
01535
01536 T& operator[] (const PP_ListIterator<T>& li);
01537
01539
01540 void remove (const T& value);
01541
01545 void remove (const PP_List<T>& lst);
01546
01548
01549 void remove (PP_ListIterator<T>& lit);
01550
01552
01553 void replace (PP_ListIterator<T>& li,
01554 const T& val);
01555
01559 void addAfter (PP_ListIterator<T>& lit,
01560 const T& val);
01561
01565 void addBefore (PP_ListIterator<T>& lit,
01566 const T& val);
01567
01569
01570 PP_ListIterator<T> first () const;
01571
01573
01574 PP_ListIterator<T> last () const;
01575
01576 protected:
01577
01578
01579
01580 void remove (PP_ListLink<T> *ln);
01581
01582
01583
01584 PP_ListLink<T>* addBefore (PP_ListLink<T>* ln,
01585 const T& val);
01586
01587
01588
01589 PP_ListLink<T>* addAfter (PP_ListLink<T>* ln,
01590 const T& val);
01591
01592
01593
01594 PP_ListLink<T>* head;
01595
01596
01597
01598 PP_ListLink<T>* tail;
01599
01600
01601
01602 friend class PP_ListIterator<T>;
01603 };
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613 template <class T>
01614 inline
01615 PP_ListIterator<T>::PP_ListIterator (const PP_List<T>& _list,
01616 PP_ListLink<T>* _p)
01617 :
01618 list(_list),
01619 p(_p)
01620 {}
01621
01622 template <class T>
01623 inline
01624 PP_ListIterator<T>::PP_ListIterator (const PP_List<T>& aList)
01625 :
01626 list(aList)
01627 {
01628 p = list.head;
01629 }
01630
01631 template <class T>
01632 inline
01633 PP_ListIterator<T>::PP_ListIterator (const PP_ListIterator<T>& li)
01634 :
01635 list(li.list),
01636 p(li.p)
01637 {}
01638
01639 template <class T>
01640 inline
01641 void
01642 PP_ListIterator<T>::rewind ()
01643 {
01644 p = list.head;
01645 }
01646
01647 template <class T>
01648 inline
01649 const T&
01650 PP_ListIterator<T>::operator() () const
01651 {
01652 CH_assert(p != 0);
01653 return p->val;
01654 }
01655
01656 template <class T>
01657 inline
01658 const T&
01659 PP_ListIterator<T>::operator* () const
01660 {
01661 CH_assert(p != 0);
01662 return p->val;
01663 }
01664
01665 template <class T>
01666 inline
01667 PP_ListIterator<T>::operator void* ()
01668 {
01669 return p != 0 ? this : 0;
01670 }
01671
01672 template <class T>
01673 inline
01674 bool
01675 PP_ListIterator<T>::operator! () const
01676 {
01677 return p == 0 ? true : false;
01678 }
01679
01680 template <class T>
01681 inline
01682 const T&
01683 PP_ListIterator<T>::value () const
01684 {
01685 CH_assert(p != 0);
01686 return p->val;
01687 }
01688
01689 template <class T>
01690 inline
01691 PP_ListIterator<T>&
01692 PP_ListIterator<T>::operator++ ()
01693 {
01694 if (p)
01695 p = p->suc;
01696 return *this;
01697 }
01698
01699 template <class T>
01700 inline
01701 PP_ListIterator<T>&
01702 PP_ListIterator<T>::operator-- ()
01703 {
01704 if (p)
01705 p = p->pre;
01706 return *this;
01707 }
01708
01709 template <class T>
01710 inline
01711 PP_ListIterator<T>
01712 PP_ListIterator<T>::operator++ (int)
01713 {
01714 const PP_ListIterator<T> li = *this;
01715 ++(*this);
01716 return li;
01717 }
01718
01719 template <class T>
01720 inline
01721 PP_ListIterator<T>
01722 PP_ListIterator<T>::operator-- (int)
01723 {
01724 const PP_ListIterator<T> li = *this;
01725 --(*this);
01726 return li;
01727 }
01728
01729 template <class T>
01730 inline
01731 bool
01732 PP_ListIterator<T>::operator== (const PP_ListIterator<T>& _li) const
01733 {
01734 return (&list == &_li.list && p == _li.p) ? true : false;
01735 }
01736
01737 template <class T>
01738 inline
01739 bool
01740 PP_ListIterator<T>::operator!= (const PP_ListIterator<T>& _li) const
01741 {
01742 return ! PP_ListIterator<T>::operator==(_li);
01743 }
01744
01745
01746
01747
01748
01749 template <class T>
01750 inline
01751 PP_List<T>::PP_List ()
01752 :
01753 head(0),
01754 tail(0)
01755 {}
01756
01757 template <class T>
01758 inline
01759 PP_List<T>::~PP_List ()
01760 {
01761 clear();
01762 }
01763
01764 template <class T>
01765 inline
01766 void
01767 PP_List<T>::prepend (const T& value)
01768 {
01769 addBefore(head, value);
01770 }
01771
01772 template <class T>
01773 inline
01774 void
01775 PP_List<T>::append (const T& value)
01776 {
01777 addAfter(tail, value);
01778 }
01779
01780 template <class T>
01781 inline
01782 T&
01783 PP_List<T>::firstElement () const
01784 {
01785 CH_assert(head != 0);
01786 return head->val;
01787 }
01788
01789 template <class T>
01790 inline
01791 T&
01792 PP_List<T>::lastElement () const
01793 {
01794 CH_assert(tail != 0);
01795 return tail->val;
01796 }
01797
01798 template <class T>
01799 inline
01800 bool
01801 PP_List<T>::isEmpty () const
01802 {
01803 return head == 0 && tail == 0;
01804 }
01805
01806 template <class T>
01807 inline
01808 bool
01809 PP_List<T>::isNotEmpty () const
01810 {
01811 return !isEmpty();
01812 }
01813
01814 template <class T>
01815 inline
01816 void
01817 PP_List<T>::removeFirst ()
01818 {
01819 remove(head);
01820 }
01821
01822 template <class T>
01823 inline
01824 void
01825 PP_List<T>::removeLast ()
01826 {
01827 remove(tail);
01828 }
01829
01830 template <class T>
01831 inline
01832 const T&
01833 PP_List<T>::operator[] (const PP_ListIterator<T>& li) const
01834 {
01835 CH_assert(li.p != 0);
01836 return li.p->val;
01837 }
01838
01839 template <class T>
01840 inline
01841 T&
01842 PP_List<T>::operator[] (const PP_ListIterator<T>& li)
01843 {
01844 CH_assert(li.p != 0);
01845 return li.p->val;
01846 }
01847
01848 template <class T>
01849 inline
01850 void
01851 PP_List<T>::replace (PP_ListIterator<T>& li,
01852 const T& _val)
01853 {
01854 CH_assert(li.p != 0);
01855 li.p->val = _val;
01856 }
01857
01858 template <class T>
01859 inline
01860 void
01861 PP_List<T>::addAfter (PP_ListIterator<T>& lit,
01862 const T& val)
01863 {
01864 addAfter(lit.p, val);
01865 }
01866
01867 template <class T>
01868 inline
01869 void
01870 PP_List<T>::addBefore (PP_ListIterator<T>& lit,
01871 const T& val)
01872 {
01873 addBefore(lit.p, val);
01874 }
01875
01876 template <class T>
01877 inline
01878 PP_ListIterator<T>
01879 PP_List<T>::first () const
01880 {
01881 return PP_ListIterator<T>(*this,head);
01882 }
01883
01884 template <class T>
01885 inline
01886 PP_ListIterator<T>
01887 PP_List<T>::last () const
01888 {
01889 return PP_ListIterator<T>(*this,tail);
01890 }
01891
01892
01893
01894
01895
01896 template <class T>
01897 inline
01898 PP_List<T>::PP_List (const PP_List<T>& source)
01899 :
01900 head(0),
01901 tail(0)
01902 {
01903 if (source.isEmpty())
01904 tail = head = 0;
01905 else
01906 for (PP_ListIterator<T> li(source); li; ++li)
01907 append(li());
01908 }
01909
01910
01911
01912
01913
01914 template <class T>
01915 inline void
01916 PP_List<T>::add (const T& value)
01917 {
01918 append(value);
01919 }
01920
01921 template <class T>
01922 inline
01923 int
01924 PP_List<T>::length () const
01925 {
01926 int len = 0;
01927 for (PP_ListIterator<T> li(*this); li; ++li)
01928 len++;
01929 return len;
01930 }
01931
01932 template <class T>
01933 inline
01934 PP_List<T>&
01935 PP_List<T>::operator= (const PP_List<T>& source)
01936 {
01937 if (!(this == &source))
01938 {
01939 clear();
01940 for (PP_ListIterator<T> li(source); li; ++li)
01941 append(li());
01942 }
01943 return *this;
01944 }
01945
01946 template <class T>
01947 inline PP_ListLink<T> *
01948 PP_List<T>::addBefore (PP_ListLink<T>* ln,
01949 const T& val)
01950 {
01951 CH_assert(ln != 0 || head == 0);
01952
01953 PP_ListLink<T>* newlink;
01954
01955 if (ln == head)
01956 {
01957 head = newlink = new PP_ListLink<T>(val, 0, head);
01958
01959 if (tail == 0)
01960 tail = head;
01961 else
01962 head->suc->pre = newlink;
01963 }
01964 else
01965 {
01966 newlink = new PP_ListLink<T>(val, ln->pre, ln);
01967
01968 ln->pre->suc = newlink;
01969 ln->pre = newlink;
01970 }
01971
01972 return newlink;
01973 }
01974
01975 template <class T>
01976 inline
01977 PP_ListLink<T>*
01978 PP_List<T>::addAfter (PP_ListLink<T>* ln,
01979 const T& val)
01980 {
01981 CH_assert(ln != 0 || tail == 0);
01982
01983 PP_ListLink<T>* newlink;
01984
01985
01986
01987
01988
01989
01990
01991 if (ln == tail)
01992 {
01993 tail = newlink = new PP_ListLink<T>(val,tail,0);
01994
01995 if (head == 0)
01996 head = tail;
01997 else
01998 tail->pre->suc = newlink;
01999 }
02000 else
02001 {
02002 newlink = new PP_ListLink<T>(val, ln, ln->suc);
02003
02004 ln->suc->pre = newlink;
02005 ln->suc = newlink;
02006 }
02007
02008 return newlink;
02009 }
02010
02011 template <class T>
02012 inline void
02013 PP_List<T>::join (const PP_List<T>& list2)
02014 {
02015 for (PP_ListIterator<T> li2(list2); li2; ++li2)
02016 append(li2());
02017 }
02018
02019 template <class T>
02020 inline void
02021 PP_List<T>::catenate (PP_List<T>& list2)
02022 {
02023 if (list2.isEmpty())
02024
02025
02026
02027 ;
02028 else if (isEmpty())
02029 {
02030 head = list2.head;
02031 tail = list2.tail;
02032 list2.head = 0;
02033 list2.tail = 0;
02034 }
02035 else
02036 {
02037 tail->suc = list2.head;
02038 list2.head->pre = tail;
02039 tail = list2.tail;
02040 list2.head = 0;
02041 list2.tail = 0;
02042 }
02043 }
02044
02045 template <class T>
02046 inline void
02047 PP_List<T>::clear ()
02048 {
02049 PP_ListLink<T>* next = 0;
02050
02051 for (PP_ListLink<T>* p = head; p != 0; p = next)
02052 {
02053 next = p->suc;
02054 p->suc = 0;
02055 delete p;
02056 }
02057 tail = head = 0;
02058 }
02059
02060 template <class T>
02061 inline bool
02062 PP_List<T>::includes (const T& v) const
02063 {
02064 bool rc = false;
02065 for (PP_ListIterator<T> li(*this); li && !rc; ++li)
02066 if (v == li())
02067 rc = true;
02068 return rc;
02069 }
02070
02071 template<class T>
02072 inline bool
02073 PP_List<T>::operator== (const PP_List<T>& rhs) const
02074 {
02075 if (length() == rhs.length())
02076 {
02077 for (PP_ListIterator<T> li(*this), ri(rhs); li; ++li, ++ri)
02078 if (li() != ri())
02079 return false;
02080 return true;
02081 }
02082
02083 return false;
02084 }
02085
02086 template<class T>
02087 inline bool
02088 PP_List<T>::operator!= (const PP_List<T>& rhs) const
02089 {
02090 return !operator==(rhs);
02091 }
02092
02093 template <class T>
02094 inline void
02095 PP_List<T>::remove (PP_ListIterator<T>& li)
02096 {
02097 PP_ListLink<T> *np = li.p->suc;
02098 remove(li.p);
02099 li.p = np;
02100 }
02101
02102 template <class T>
02103 inline void
02104 PP_List<T>::remove (const T& _v)
02105 {
02106 for (PP_ListIterator<T> litr(*this); litr; ++litr)
02107 if (litr() == _v)
02108 remove(litr);
02109 }
02110
02111 template <class T>
02112 inline void
02113 PP_List<T>::remove (const PP_List<T>& _lv)
02114 {
02115 for (PP_ListIterator<T> litr(_lv); litr; ++litr)
02116 remove(litr());
02117 }
02118
02119 template <class T>
02120 inline void
02121 PP_List<T>::remove (PP_ListLink<T>* ln)
02122 {
02123 CH_assert(head !=0 && tail != 0);
02124
02125 if (head == ln && tail == ln)
02126 head = tail = 0;
02127 else if (head == ln)
02128 {
02129 CH_assert(ln->pre == 0);
02130 head = ln->suc;
02131 head->pre = 0;
02132 }
02133 else if (tail == ln)
02134 {
02135 CH_assert(ln->suc == 0);
02136 tail = ln->pre;
02137 tail->suc = 0;
02138 }
02139 else
02140 {
02141 CH_assert(ln->suc != 0 && ln->pre != 0);
02142 ln->suc->pre = ln->pre;
02143 ln->pre->suc = ln->suc;
02144 }
02145 delete ln;
02146 ln = 0;
02147 }
02148
02149 template <class T> class PP_Array;
02150
02152
02190 template <class T>
02191 class PP_Array
02192 {
02193 public:
02194
02196
02197 PP_Array ();
02198
02202 PP_Array (long len);
02203
02207 PP_Array (long len,
02208 const T& initialvalue);
02209
02213 PP_Array (const T* vec,
02214 long len);
02215
02217
02218 PP_Array (const PP_Array<T>& rhs);
02219
02223 PP_Array<T>& operator= (const PP_Array<T>& rhs);
02224
02226
02227 ~PP_Array ();
02228
02232 void clear ();
02233
02235
02236 bool ready () const;
02237
02241 void reserve (long _truesize);
02242
02249 void shrinkWrap ();
02250
02259 void resize (long newlen);
02260
02269 void resize (long newlen,
02270 const T& initialvalue);
02271
02273
02274 long length () const;
02275
02279 long trueSize () const;
02280
02285 T& operator[] (long K);
02286
02288
02289 const T& operator[] (long K) const;
02290
02292
02293 T& get (long i);
02294
02296
02297 const T& get (long i) const;
02298
02303 T* dataPtr ();
02304
02306
02307 const T* dataPtr () const;
02308
02310
02311 void set (long i,
02312 const T& elem);
02313
02315
02316 void swap (long i,
02317 long j);
02318
02320
02321 bool operator== (const PP_Array<T>& rhs) const;
02322
02324
02325 bool operator!= (const PP_Array<T>& rhs) const;
02326
02327 protected:
02328
02329
02330
02331 long truesize;
02332
02333
02334
02335 long nelem;
02336
02337
02338
02339 T* vp;
02340
02341 private:
02342
02343
02344
02345 PP_Array<T>& operator= (int);
02346 };
02347
02348
02349
02350
02351
02352 template <class T>
02353 inline
02354 PP_Array<T>::PP_Array ()
02355 {
02356 nelem = 0;
02357 vp = new T[1];
02358 truesize = 1;
02359 }
02360
02361 template <class T>
02362 inline
02363 PP_Array<T>::PP_Array (long len)
02364 {
02365 CH_assert(len >= 0);
02366 nelem = len;
02367 vp = new T[len];
02368 truesize = nelem;
02369 }
02370
02371 template <class T>
02372 inline
02373 void
02374 PP_Array<T>::clear ()
02375 {
02376 delete [] vp;
02377 vp = 0;
02378 nelem = 0;
02379 truesize = 0;
02380 }
02381
02382 template <class T>
02383 inline
02384 PP_Array<T>::~PP_Array ()
02385 {
02386 clear();
02387 }
02388
02389 template <class T>
02390 inline
02391 bool
02392 PP_Array<T>::ready () const
02393 {
02394 return vp != 0 && nelem != 0;
02395 }
02396
02397 template <class T>
02398 inline
02399 long
02400 PP_Array<T>::length () const
02401 {
02402 return nelem;
02403 }
02404
02405 template <class T>
02406 inline
02407 long
02408 PP_Array<T>::trueSize () const
02409 {
02410 return truesize;
02411 }
02412
02413 template <class T>
02414 inline
02415 T&
02416 PP_Array<T>::operator[] (long i)
02417 {
02418 CH_assert(vp != 0);
02419 CH_assert(i >= 0 && i < nelem);
02420 return vp[i];
02421 }
02422
02423 template <class T>
02424 inline
02425 const T&
02426 PP_Array<T>::operator[] (long i) const
02427 {
02428 CH_assert(vp != 0);
02429 CH_assert(i >= 0 && i < nelem);
02430 return vp[i];
02431 }
02432
02433 template <class T>
02434 inline
02435 T&
02436 PP_Array<T>::get (long i)
02437 {
02438 CH_assert(vp != 0);
02439 CH_assert(i >= 0 && i < nelem);
02440 return vp[i];
02441 }
02442
02443 template <class T>
02444 inline
02445 const T&
02446 PP_Array<T>::get (long i) const
02447 {
02448 CH_assert(vp != 0);
02449 CH_assert(i >= 0 && i < nelem);
02450 return vp[i];
02451 }
02452
02453 template <class T>
02454 inline
02455 void
02456 PP_Array<T>::set (long i,
02457 const T& elem)
02458 {
02459 CH_assert(vp != 0);
02460 CH_assert(i >= 0 && i < nelem);
02461 vp[i] = elem;
02462 }
02463
02464 template <class T>
02465 inline
02466 T*
02467 PP_Array<T>::dataPtr ()
02468 {
02469 return vp;
02470 }
02471
02472 template <class T>
02473 inline
02474 const T*
02475 PP_Array<T>::dataPtr () const
02476 {
02477 return vp;
02478 }
02479
02480 template <class T>
02481 inline
02482 void
02483 PP_Array<T>::swap (long i,
02484 long j)
02485 {
02486 CH_assert(i >= 0 && i < nelem);
02487 CH_assert(j >= 0 && j < nelem);
02488 T tmp = vp[i];
02489 vp[i] = vp[j];
02490 vp[j] = tmp;
02491 }
02492
02493 template <class T>
02494 inline
02495 bool
02496 PP_Array<T>::operator!= (const PP_Array<T>& rhs) const
02497 {
02498 return !(operator==(rhs));
02499 }
02500
02501
02502
02503
02504
02505 template <class T>
02506 PP_Array<T>::PP_Array (long len,
02507 const T& initialValue)
02508 {
02509 CH_assert(len >= 0);
02510 nelem = len;
02511 vp = new T[len];
02512 truesize = nelem;
02513 for(long i = 0; i < nelem; ++i)
02514 vp[i] = initialValue;
02515 }
02516
02517 template <class T>
02518 PP_Array<T>::PP_Array (const T* vec,
02519 long len)
02520 {
02521 CH_assert(len >= 0);
02522 nelem = len;
02523 vp = new T[len];
02524 truesize = nelem;
02525 for(long i = 0; i < nelem; ++i)
02526 vp[i] = vec[i];
02527 }
02528
02529 template <class T>
02530 PP_Array<T>::PP_Array (const PP_Array<T>& a)
02531 {
02532 nelem = a.nelem;
02533 vp = new T[nelem];
02534 truesize = nelem;
02535 for (long i = 0; i < nelem; i++)
02536 vp[i] = a.vp[i];
02537 }
02538
02539 template <class T>
02540 PP_Array<T>&
02541 PP_Array<T>::operator= (const PP_Array<T>& sa)
02542 {
02543 if (this != &sa)
02544 {
02545 clear();
02546 vp = new T[sa.nelem];
02547 nelem = sa.nelem;
02548 truesize = nelem;
02549 for(long i = 0; i < nelem; i++)
02550 vp[i] = sa.vp[i];
02551 }
02552 return *this;
02553 }
02554
02555 template <class T>
02556 inline
02557 void
02558 PP_Array<T>::resize (long newlen)
02559 {
02560 if (newlen == nelem)
02561 return;
02562 if (newlen <= truesize)
02563 {
02564 nelem = newlen;
02565 return;
02566 }
02567 T* newvp = new T[newlen];
02568 long len = Min(newlen,nelem);
02569 for (long i = 0; i < len; i++)
02570 newvp[i] = vp[i];
02571 delete [] vp;
02572 vp = newvp;
02573 nelem = newlen;
02574 truesize = newlen;
02575 }
02576
02577 template <class T>
02578 inline
02579 void PP_Array<T>::resize (long newlen,
02580 const T& initialValue)
02581 {
02582 if (newlen == nelem)
02583 return;
02584 if (newlen <= truesize)
02585 {
02586 for(long i = nelem; i < newlen; ++i)
02587 vp[i] = initialValue;
02588 nelem = newlen;
02589 return;
02590 }
02591 T* newvp = new T[newlen];
02592 long len = Min(newlen,nelem);
02593 long i;
02594 for (i = 0; i < len; i++)
02595 newvp[i] = vp[i];
02596 for(i = len; i < newlen; ++i)
02597 newvp[i] = initialValue;
02598 delete [] vp;
02599 vp = newvp;
02600 nelem = newlen;
02601 truesize = newlen;
02602 }
02603
02604 template <class T>
02605 void
02606 PP_Array<T>::reserve (long _truesize)
02607 {
02608 if (_truesize > truesize)
02609 {
02610 T* newvp = new T[_truesize];
02611 for (long i = 0; i < nelem; i++)
02612 newvp[i] = vp[i];
02613 delete [] vp;
02614 vp = newvp;
02615 truesize = _truesize;
02616 }
02617 }
02618
02619 template <class T>
02620 void
02621 PP_Array<T>::shrinkWrap ()
02622 {
02623 if (nelem != truesize)
02624 {
02625 T* newvp = new T[nelem];
02626 for (long i = 0; i < nelem; i++)
02627 newvp[i] = vp[i];
02628 delete [] vp;
02629 vp = newvp;
02630 truesize = nelem;
02631 }
02632 }
02633
02634 template <class T>
02635 bool
02636 PP_Array<T>::operator== (const PP_Array<T>& rhs) const
02637 {
02638 if (length() != rhs.length())
02639 return false;
02640
02641 for (long i = 0; i < length(); ++i)
02642 if (!((*this)[i] == rhs[i]))
02643 return false;
02644
02645 return true;
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
02774
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798 class PP_entry;
02799
02800 #endif //for the doxygen thing
02801
02803
02874 class ParmParse
02875 {
02876 friend class PP_entry;
02877 public:
02878
02880
02888 ParmParse (int argc,
02889 char** argv,
02890 const char* prefix = 0,
02891 const char* parfile = 0);
02892
02894
02896 void define (int argc,
02897 char** argv,
02898 const char* prefix = 0,
02899 const char* parfile = 0);
02900
02906 ParmParse (const char* prefix = 0);
02907
02911 ~ParmParse();
02912
02914
02917 bool contains (const char* name);
02918
02920
02923 bool contains (const std::string& name);
02924
02926
02930 int countval (const char* name,
02931 int n = -1);
02932
02934
02937 int countname (const char* name);
02938
02940
02943 int countname (const std::string& name);
02944
02946
02949 void dumpTable (std::ostream& os);
02950
02952
02960 void get (const char* name,
02961 int& ref,
02962 int ival=0);
02963
02965
02974 int query (const char* name,
02975 int& ref,
02976 int ival=0);
02977
02979
02987 void get (const char* name,
02988 unsigned long& ref,
02989 int ival=0);
02990
02992
03001 int query (const char* name,
03002 unsigned long& ref,
03003 int ival=0);
03004
03006
03014 void get (const char* name,
03015 float& ref,
03016 int ival=0);
03017
03019
03028 int query (const char* name,
03029 float& ref,
03030 int ival=0);
03031
03033
03041 void get (const char* name,
03042 double& ref,
03043 int ival=0);
03044
03046
03055 int query (const char* name,
03056 double& ref,
03057 int ival=0);
03058
03060
03068 void get (const char* name,
03069 std::string& ref,
03070 int ival=0);
03071
03073
03082 int query (const char* name,
03083 std::string& ref,
03084 int ival=0);
03085
03087
03097 void get (const char* name,
03098 bool& ref,
03099 int ival=0);
03100
03102
03113 int query (const char* name,
03114 bool& ref,
03115 int ival=0);
03116
03117
03119
03131 void getarr (const char* name,
03132 Vector<int>& ref,
03133 int start_ix,
03134 int num_val);
03135
03137
03149 void getarr (const char* name,
03150 std::vector<int>& ref,
03151 int start_ix,
03152 int num_val);
03153
03155
03168 int queryarr (const char* name,
03169 Vector<int>& ref,
03170 int start_ix,
03171 int num_val);
03172
03174
03187 int queryarr (const char* name,
03188 std::vector<int>& ref,
03189 int start_ix,
03190 int num_val);
03191
03193
03205 void getarr (const char* name,
03206 Vector<unsigned long>& ref,
03207 int start_ix,
03208 int num_val);
03209
03211
03223 void getarr (const char* name,
03224 std::vector<unsigned long>& ref,
03225 int start_ix,
03226 int num_val);
03227
03229
03242 int queryarr (const char* name,
03243 Vector<unsigned long>& ref,
03244 int start_ix,
03245 int num_val);
03246
03248
03261 int queryarr (const char* name,
03262 std::vector<unsigned long>& ref,
03263 int start_ix,
03264 int num_val);
03265
03267
03279 void getarr (const char* name,
03280 Vector<float>& ref,
03281 int start_ix,
03282 int num_val);
03283
03285
03297 void getarr (const char* name,
03298 std::vector<float>& ref,
03299 int start_ix,
03300 int num_val);
03301
03303
03316 int queryarr (const char* name,
03317 Vector<float>& ref,
03318 int start_ix,
03319 int num_val);
03320
03322
03335 int queryarr (const char* name,
03336 std::vector<float>& ref,
03337 int start_ix,
03338 int num_val);
03339
03341
03353 void getarr (const char* name,
03354 Vector<double>& ref,
03355 int start_ix,
03356 int num_val);
03357
03359
03371 void getarr (const char* name,
03372 std::vector<double>& ref,
03373 int start_ix,
03374 int num_val);
03375
03377
03390 int queryarr (const char* name,
03391 Vector<double>& ref,
03392 int start_ix,
03393 int num_val);
03394
03396
03409 int queryarr (const char* name,
03410 std::vector<double>& ref,
03411 int start_ix,
03412 int num_val);
03413
03415
03427 void getarr (const char* name,
03428 Vector<std::string>& ref,
03429 int start_ix,
03430 int num_val);
03431
03433
03445 void getarr (const char* name,
03446 std::vector<std::string>& ref,
03447 int start_ix,
03448 int num_val);
03449
03451
03464 int queryarr (const char* name,
03465 Vector<std::string>& ref,
03466 int start_ix,
03467 int num_val);
03468
03470
03483 int queryarr (const char* name,
03484 std::vector<std::string>& ref,
03485 int start_ix,
03486 int num_val);
03487
03489
03501 void getarr (const char* name,
03502 Vector<bool>& ref,
03503 int start_ix,
03504 int num_val);
03505
03507
03519 void getarr (const char* name,
03520 std::vector<bool>& ref,
03521 int start_ix,
03522 int num_val);
03523
03525
03538 int queryarr (const char* name,
03539 Vector<bool>& ref,
03540 int start_ix,
03541 int num_val);
03542
03544
03557 int queryarr (const char* name,
03558 std::vector<bool>& ref,
03559 int start_ix,
03560 int num_val);
03561
03562 #ifndef DOXYGEN
03563
03564
03565
03566 enum PPType
03567 {
03568 ppDefn,
03569 ppOption,
03570 ppInt,
03571 ppUnsignedLong,
03572 ppFloat,
03573 ppDouble,
03574 ppString,
03575 ppBool,
03576 ppEQ_sign,
03577 ppEOF
03578 };
03579
03580
03581 protected:
03582
03583
03584
03585 static PP_List<PP_entry*> table;
03586
03587
03588
03589 static int xargc;
03590 static char** xargv;
03591
03592
03593
03594 static int num_obj;
03595
03596
03597
03598 void bldTable (const char* str,
03599 int lenstr,
03600 PP_List<PP_entry*>& tab);
03601
03602
03603
03604 void addDefn (PP_String& def,
03605 PP_List<PP_String>& val,
03606 PP_List<PP_entry*>& tab);
03607
03608
03609
03610 void read_file (const char* fname,
03611 PP_List<PP_entry*>& tab);
03612
03613
03614
03615 PPType getToken (const char*,
03616 int&,
03617 int,
03618 char*);
03619
03620
03621
03622 void rmTable ();
03623
03624
03625
03626 PP_String thePrefix;
03627
03628
03629
03630 void ppinit (const char* parfile);
03631
03632
03633
03634 const PP_entry* ppindex (int n,
03635 const char* name) const;
03636
03637
03638
03639
03640
03641
03642
03643
03644 void getval (const char* name,
03645 const PPType type,
03646 void* ptr,
03647 int ival,
03648 int k=-1);
03649
03650
03651
03652 void getarr (const char* name,
03653 const PPType type,
03654 void* ptr,
03655 int start_ix,
03656 int num_val,
03657 int k=-1);
03658 int queryval (const char* name,
03659 const PPType type,
03660 void* ptr,
03661 int ival,
03662 int k=-1);
03663 int queryarr (const char* name,
03664 const PPType type,
03665 void* ptr,
03666 int start_ix,
03667 int num_val,
03668 int k=-1);
03669
03670 bool isInteger (const PP_String& str, int& val);
03671 bool isUnsigned(const PP_String& str, unsigned long& val);
03672 int isDouble (const PP_String& str, double& val);
03673 bool isBool (const PP_String& str, bool& val);
03674
03675 #endif
03676
03677 };
03678
03679 #ifndef DOXYGEN
03680 class PP_entry
03681 {
03682 private:
03683 friend class ParmParse;
03684 PP_entry()
03685 {}
03686
03687 PP_entry (PP_String& name,
03688 ParmParse::PPType typ,
03689 PP_List<PP_String>& vals);
03690
03691 ~PP_entry()
03692 {}
03693
03694 PP_String defname;
03695 ParmParse::PPType deftype;
03696 PP_Array<PP_String> val;
03697
03698 void dump (std::ostream& os) const;
03699 };
03700 #endif //doxygen
03701
03702
03703
03704
03705
03706 inline
03707 int
03708 ParmParse::countval (const char* name,
03709 int n)
03710 {
03711
03712
03713
03714 const PP_entry* def = ppindex(n,name);
03715 return def == 0 ? 0 : def->val.length();
03716 }
03717
03718 inline
03719 void
03720 ParmParse::get (const char* name,
03721 int& ptr,
03722 int ival)
03723 {
03724 getval(name,ppInt,&ptr,ival,-1);
03725 }
03726
03727 inline
03728 int
03729 ParmParse::query (const char* name,
03730 int& ptr,
03731 int ival)
03732 {
03733 return queryval(name,ppInt,&ptr,ival,-1);
03734 }
03735
03736 inline
03737 void
03738 ParmParse::get (const char* name,
03739 unsigned long& ptr,
03740 int ival)
03741 {
03742 getval(name,ppUnsignedLong,&ptr,ival,-1);
03743 }
03744
03745 inline
03746 int
03747 ParmParse::query (const char* name,
03748 unsigned long& ptr,
03749 int ival)
03750 {
03751 return queryval(name,ppUnsignedLong,&ptr,ival,-1);
03752 }
03753
03754 inline
03755 void
03756 ParmParse::get (const char* name,
03757 float& ptr,
03758 int ival)
03759 {
03760 getval(name,ppFloat,&ptr,ival,-1);
03761 }
03762
03763 inline
03764 int
03765 ParmParse::query (const char* name,
03766 float& ptr,
03767 int ival)
03768 {
03769 return queryval(name,ppFloat,&ptr,ival,-1);
03770 }
03771
03772 inline
03773 void
03774 ParmParse::get (const char* name,
03775 double& ptr,
03776 int ival)
03777 {
03778 getval(name,ppDouble,&ptr,ival,-1);
03779 }
03780
03781 inline
03782 int
03783 ParmParse::query (const char* name,
03784 double& ptr,
03785 int ival)
03786 {
03787 return queryval(name,ppDouble,&ptr,ival,-1);
03788 }
03789
03790 inline
03791 void
03792 ParmParse::get (const char* name,
03793 std::string& ptr,
03794 int ival)
03795 {
03796 PP_String pp_string;
03797 getval(name,ppString,&pp_string,ival,-1);
03798 ptr = pp_string.c_str();
03799 }
03800
03801 inline
03802 int
03803 ParmParse::query (const char* name,
03804 std::string& ptr,
03805 int ival)
03806 {
03807 PP_String pp_string;
03808 int status = queryval(name,ppString,&pp_string,ival,-1);
03809 if (status != 0)
03810 ptr = pp_string.c_str();
03811 return status;
03812 }
03813
03814 inline
03815 void
03816 ParmParse::get(const char* name,
03817 bool& ptr,
03818 int ival)
03819 {
03820 getval(name,ppBool,&ptr,ival,-1);
03821 }
03822
03823 inline
03824 int
03825 ParmParse::query (const char* name,
03826 bool& ptr,
03827 int ival)
03828 {
03829 return queryval(name,ppBool,&ptr,ival,-1);
03830 }
03831
03832 inline
03833 void
03834 ParmParse::getarr (const char* name,
03835 std::vector<int>& ptr,
03836 int start_ix,
03837 int num_val)
03838 {
03839 if (ptr.size() < num_val)
03840 ptr.resize(num_val);
03841 int* c_array = new int[num_val];
03842 getarr(name,ppInt,c_array,start_ix,num_val,-1);
03843 for (int i = 0; i < num_val; ++i)
03844 {
03845 ptr[i] = c_array[i];
03846 }
03847 delete[] c_array;
03848 }
03849
03850 inline
03851 void
03852 ParmParse::getarr (const char* name,
03853 Vector<int>& ptr,
03854 int start_ix,
03855 int num_val)
03856 {
03857 if (ptr.size() < num_val)
03858 ptr.resize(num_val);
03859 int* c_array = new int[num_val];
03860 getarr(name,ppInt,c_array,start_ix,num_val,-1);
03861 for (int i = 0; i < num_val; ++i)
03862 {
03863 ptr[i] = c_array[i];
03864 }
03865 delete[] c_array;
03866 }
03867
03868 inline
03869 int
03870 ParmParse::queryarr (const char* name,
03871 std::vector<int>& ptr,
03872 int start_ix,
03873 int num_val)
03874 {
03875 if (ptr.size() < num_val)
03876 ptr.resize(num_val);
03877 int* c_array = new int[num_val];
03878 int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03879 if (status != 0 )
03880 {
03881 for (int i = 0; i < num_val; ++i)
03882 {
03883 ptr[i] = c_array[i];
03884 }
03885 }
03886 return status;
03887 }
03888
03889 inline
03890 int
03891 ParmParse::queryarr (const char* name,
03892 Vector<int>& ptr,
03893 int start_ix,
03894 int num_val)
03895 {
03896 if (ptr.size() < num_val)
03897 ptr.resize(num_val);
03898 int* c_array = new int[num_val];
03899 int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03900 if (status != 0 )
03901 {
03902 for (int i = 0; i < num_val; ++i)
03903 {
03904 ptr[i] = c_array[i];
03905 }
03906 }
03907 return status;
03908 }
03909
03910 inline
03911 void
03912 ParmParse::getarr (const char* name,
03913 std::vector<float>& ptr,
03914 int start_ix,
03915 int num_val)
03916 {
03917 if (ptr.size() < num_val)
03918 ptr.resize(num_val);
03919 float* c_array = new float[num_val];
03920 getarr(name,ppFloat,c_array,start_ix,num_val,-1);
03921 for (int i = 0; i < num_val; ++i)
03922 {
03923 ptr[i] = c_array[i];
03924 }
03925 delete[] c_array;
03926 }
03927
03928 inline
03929 void
03930 ParmParse::getarr (const char* name,
03931 Vector<float>& ptr,
03932 int start_ix,
03933 int num_val)
03934 {
03935 if (ptr.size() < num_val)
03936 ptr.resize(num_val);
03937 float* c_array = new float[num_val];
03938 getarr(name,ppFloat,c_array,start_ix,num_val,-1);
03939 for (int i = 0; i < num_val; ++i)
03940 {
03941 ptr[i] = c_array[i];
03942 }
03943 delete[] c_array;
03944 }
03945
03946 inline
03947 int
03948 ParmParse::queryarr (const char* name,
03949 std::vector<float>& ptr,
03950 int start_ix,
03951 int num_val)
03952 {
03953 if (ptr.size() < num_val)
03954 ptr.resize(num_val);
03955 float* c_array = new float[num_val];
03956 int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03957 if (status != 0)
03958 {
03959 for (int i = 0; i < num_val; ++i)
03960 {
03961 ptr[i] = c_array[i];
03962 }
03963 }
03964 delete[] c_array;
03965 return status;
03966 }
03967
03968 inline
03969 int
03970 ParmParse::queryarr (const char* name,
03971 Vector<float>& ptr,
03972 int start_ix,
03973 int num_val)
03974 {
03975 if (ptr.size() < num_val)
03976 ptr.resize(num_val);
03977 float* c_array = new float[num_val];
03978 int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03979 if (status != 0)
03980 {
03981 for (int i = 0; i < num_val; ++i)
03982 {
03983 ptr[i] = c_array[i];
03984 }
03985 }
03986 delete[] c_array;
03987 return status;
03988 }
03989
03990 inline
03991 void
03992 ParmParse::getarr (const char* name,
03993 std::vector<double>& ptr,
03994 int start_ix,
03995 int num_val)
03996 {
03997 if (ptr.size() < num_val)
03998 ptr.resize(num_val);
03999 double* c_array = new double[num_val];
04000 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04001 if (status == 0)
04002 {
04003 cerr << "ParmParse::getarr(): "
04004 << name
04005 << " not found in table" << endl;
04006 dumpTable(cerr);
04007 MayDay::Abort();
04008 }
04009 for (int i = 0; i < num_val; ++i)
04010 {
04011 ptr[i] = c_array[i];
04012 }
04013 delete[] c_array;
04014 }
04015
04016 inline
04017 void
04018 ParmParse::getarr (const char* name,
04019 Vector<double>& ptr,
04020 int start_ix,
04021 int num_val)
04022 {
04023 if (ptr.size() < num_val)
04024 ptr.resize(num_val);
04025 double* c_array = new double[num_val];
04026 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04027 if (status == 0)
04028 {
04029 cerr << "ParmParse::getarr(): "
04030 << name
04031 << " not found in table" << endl;
04032 dumpTable(cerr);
04033 MayDay::Abort();
04034 }
04035 for (int i = 0; i < num_val; ++i)
04036 {
04037 ptr[i] = c_array[i];
04038 }
04039 delete[] c_array;
04040 }
04041
04042 inline
04043 int
04044 ParmParse::queryarr (const char* name,
04045 std::vector<double>& ptr,
04046 int start_ix,
04047 int num_val)
04048 {
04049 if (ptr.size() < num_val)
04050 ptr.resize(num_val);
04051 double* c_array = new double[num_val];
04052 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04053 if (status != 0)
04054 {
04055 for (int i = 0; i < num_val; ++i)
04056 {
04057 ptr[i] = c_array[i];
04058 }
04059 }
04060 delete[] c_array;
04061 return status;
04062 }
04063
04064 inline
04065 int
04066 ParmParse::queryarr (const char* name,
04067 Vector<double>& ptr,
04068 int start_ix,
04069 int num_val)
04070 {
04071 if (ptr.size() < num_val)
04072 ptr.resize(num_val);
04073 double* c_array = new double[num_val];
04074 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04075 if (status != 0)
04076 {
04077 for (int i = 0; i < num_val; ++i)
04078 {
04079 ptr[i] = c_array[i];
04080 }
04081 }
04082 delete[] c_array;
04083 return status;
04084 }
04085
04086 inline
04087 void
04088 ParmParse::getarr (const char* name,
04089 std::vector<std::string>& ptr,
04090 int start_ix,
04091 int num_val)
04092 {
04093 if (ptr.size() < num_val)
04094 ptr.resize(num_val);
04095 PP_String* c_array = new PP_String[num_val];
04096 getarr(name,ppString,c_array,start_ix,num_val,-1);
04097 for (int i = 0; i < num_val; ++i)
04098 {
04099 ptr[i] = c_array[i].c_str();
04100 }
04101 delete[] c_array;
04102 }
04103
04104 inline
04105 void
04106 ParmParse::getarr (const char* name,
04107 Vector<std::string>& ptr,
04108 int start_ix,
04109 int num_val)
04110 {
04111 if (ptr.size() < num_val)
04112 ptr.resize(num_val);
04113 PP_String* c_array = new PP_String[num_val];
04114 getarr(name,ppString,c_array,start_ix,num_val,-1);
04115 for (int i = 0; i < num_val; ++i)
04116 {
04117 ptr[i] = c_array[i].c_str();
04118 }
04119 delete[] c_array;
04120 }
04121
04122 inline
04123 int
04124 ParmParse::queryarr (const char* name,
04125 std::vector<std::string>& ptr,
04126 int start_ix,
04127 int num_val)
04128 {
04129 if (ptr.size() < num_val)
04130 ptr.resize(num_val);
04131 PP_String* c_array = new PP_String[num_val];
04132 int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
04133 if (status != 0)
04134 {
04135 for (int i = 0; i < num_val; ++i)
04136 {
04137 ptr[i] = c_array[i].c_str();
04138 }
04139 }
04140 delete[] c_array;
04141 return status;
04142 }
04143
04144 inline
04145 int
04146 ParmParse::queryarr (const char* name,
04147 Vector<std::string>& ptr,
04148 int start_ix,
04149 int num_val)
04150 {
04151 if (ptr.size() < num_val)
04152 ptr.resize(num_val);
04153 PP_String* c_array = new PP_String[num_val];
04154 int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
04155 if (status != 0)
04156 {
04157 for (int i = 0; i < num_val; ++i)
04158 {
04159 ptr[i] = c_array[i].c_str();
04160 }
04161 }
04162 delete[] c_array;
04163 return status;
04164 }
04165
04166 inline
04167 bool
04168 ParmParse::isInteger (const PP_String& str,
04169 int& val)
04170 {
04171
04172
04173
04174 char* endp = 0;
04175 val = (int) strtol(str.c_str(), &endp, 10);
04176 return *endp == 0;
04177 }
04178
04179 inline
04180 bool
04181 ParmParse::isUnsigned (const PP_String& str,
04182 unsigned long & val)
04183 {
04184 char* endp = 0;
04185 val = strtoul(str.c_str(), &endp, 10);
04186 return *endp == 0;
04187 }
04188
04189 inline
04190 int
04191 ParmParse::isDouble (const PP_String& str,
04192 double& val)
04193 {
04194 char* endp = 0;
04195 val = std::strtod(str.c_str(), &endp);
04196 return *endp == 0;
04197 }
04198
04199 inline
04200 bool
04201 ParmParse::isBool (const PP_String& str,
04202 bool& val)
04203 {
04204 PP_String str_lc( str );
04205 str_lc.toLower();
04206 if( str_lc == "true" || str_lc == "1" ){
04207 return val = true ;
04208 }else if( str_lc == "false" || str_lc == "0" ){
04209 val = false ;
04210 return true ;
04211 }else{
04212 return false ;
04213 }
04214 }
04215
04216 inline
04217 int
04218 ParmParse::countname (const std::string& name)
04219 {
04220 return countname(name.c_str());
04221 }
04222
04223 #endif