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 <cassert>
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 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 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 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 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 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 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 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 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 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 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 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 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 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 assert(head !=0 && tail != 0);
02124
02125 if (head == ln && tail == ln)
02126 head = tail = 0;
02127 else if (head == ln)
02128 {
02129 assert(ln->pre == 0);
02130 head = ln->suc;
02131 head->pre = 0;
02132 }
02133 else if (tail == ln)
02134 {
02135 assert(ln->suc == 0);
02136 tail = ln->pre;
02137 tail->suc = 0;
02138 }
02139 else
02140 {
02141 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 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 assert(vp != 0);
02419 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 assert(vp != 0);
02429 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 assert(vp != 0);
02439 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 assert(vp != 0);
02449 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 assert(vp != 0);
02460 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 assert(i >= 0 && i < nelem);
02487 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 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 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
02898 ParmParse (const char* prefix = 0);
02899
02903 ~ParmParse();
02904
02906
02909 bool contains (const char* name);
02910
02912
02915 bool contains (const std::string& name);
02916
02918
02922 int countval (const char* name,
02923 int n = -1);
02924
02926
02929 int countname (const char* name);
02930
02932
02935 int countname (const std::string& name);
02936
02938
02941 void dumpTable (std::ostream& os);
02942
02944
02952 void get (const char* name,
02953 int& ref,
02954 int ival=0);
02955
02957
02966 int query (const char* name,
02967 int& ref,
02968 int ival=0);
02969
02971
02979 void get (const char* name,
02980 float& ref,
02981 int ival=0);
02982
02984
02993 int query (const char* name,
02994 float& ref,
02995 int ival=0);
02996
02998
03006 void get (const char* name,
03007 double& ref,
03008 int ival=0);
03009
03011
03020 int query (const char* name,
03021 double& ref,
03022 int ival=0);
03023
03025
03033 void get (const char* name,
03034 std::string& ref,
03035 int ival=0);
03036
03038
03047 int query (const char* name,
03048 std::string& ref,
03049 int ival=0);
03050
03052
03064 void getarr (const char* name,
03065 Vector<int>& ref,
03066 int start_ix,
03067 int num_val);
03068
03070
03082 void getarr (const char* name,
03083 std::vector<int>& ref,
03084 int start_ix,
03085 int num_val);
03086
03088
03101 int queryarr (const char* name,
03102 Vector<int>& ref,
03103 int start_ix,
03104 int num_val);
03105
03107
03120 int queryarr (const char* name,
03121 std::vector<int>& ref,
03122 int start_ix,
03123 int num_val);
03124
03126
03138 void getarr (const char* name,
03139 Vector<float>& ref,
03140 int start_ix,
03141 int num_val);
03142
03144
03156 void getarr (const char* name,
03157 std::vector<float>& ref,
03158 int start_ix,
03159 int num_val);
03160
03162
03175 int queryarr (const char* name,
03176 Vector<float>& ref,
03177 int start_ix,
03178 int num_val);
03179
03181
03194 int queryarr (const char* name,
03195 std::vector<float>& ref,
03196 int start_ix,
03197 int num_val);
03198
03200
03212 void getarr (const char* name,
03213 Vector<double>& ref,
03214 int start_ix,
03215 int num_val);
03216
03218
03230 void getarr (const char* name,
03231 std::vector<double>& ref,
03232 int start_ix,
03233 int num_val);
03234
03236
03249 int queryarr (const char* name,
03250 Vector<double>& ref,
03251 int start_ix,
03252 int num_val);
03253
03255
03268 int queryarr (const char* name,
03269 std::vector<double>& ref,
03270 int start_ix,
03271 int num_val);
03272
03274
03286 void getarr (const char* name,
03287 Vector<std::string>& ref,
03288 int start_ix,
03289 int num_val);
03290
03292
03304 void getarr (const char* name,
03305 std::vector<std::string>& ref,
03306 int start_ix,
03307 int num_val);
03308
03310
03323 int queryarr (const char* name,
03324 Vector<std::string>& ref,
03325 int start_ix,
03326 int num_val);
03327
03329
03342 int queryarr (const char* name,
03343 std::vector<std::string>& ref,
03344 int start_ix,
03345 int num_val);
03346
03347 #ifndef DOXYGEN
03348
03349
03350
03351 enum PPType
03352 {
03353 ppDefn,
03354 ppOption,
03355 ppInt,
03356 ppFloat,
03357 ppDouble,
03358 ppString,
03359 ppEQ_sign,
03360 ppEOF
03361 };
03362
03363
03364 protected:
03365
03366
03367
03368 static PP_List<PP_entry*> table;
03369
03370
03371
03372 static int xargc;
03373 static char** xargv;
03374
03375
03376
03377 static int num_obj;
03378
03379
03380
03381 void bldTable (const char* str,
03382 int lenstr,
03383 PP_List<PP_entry*>& tab);
03384
03385
03386
03387 void addDefn (PP_String& def,
03388 PP_List<PP_String>& val,
03389 PP_List<PP_entry*>& tab);
03390
03391
03392
03393 void read_file (const char* fname,
03394 PP_List<PP_entry*>& tab);
03395
03396
03397
03398 PPType getToken (const char*,
03399 int&,
03400 int,
03401 char*);
03402
03403
03404
03405 void rmTable ();
03406
03407
03408
03409 PP_String thePrefix;
03410
03411
03412
03413 void ppinit (const char* parfile);
03414
03415
03416
03417 const PP_entry* ppindex (int n,
03418 const char* name) const;
03419
03420
03421
03422
03423
03424
03425
03426
03427 void getval (const char* name,
03428 const PPType type,
03429 void* ptr,
03430 int ival,
03431 int k=-1);
03432
03433
03434
03435 void getarr (const char* name,
03436 const PPType type,
03437 void* ptr,
03438 int start_ix,
03439 int num_val,
03440 int k=-1);
03441 int queryval (const char* name,
03442 const PPType type,
03443 void* ptr,
03444 int ival,
03445 int k=-1);
03446 int queryarr (const char* name,
03447 const PPType type,
03448 void* ptr,
03449 int start_ix,
03450 int num_val,
03451 int k=-1);
03452
03453 bool isInteger (const PP_String& str,
03454 int& val);
03455 int isDouble (const PP_String& str,
03456 double& val);
03457
03458 #endif
03459
03460 };
03461
03462 #ifndef DOXYGEN
03463 class PP_entry
03464 {
03465 private:
03466 friend class ParmParse;
03467 PP_entry()
03468 {}
03469
03470 PP_entry (PP_String& name,
03471 ParmParse::PPType typ,
03472 PP_List<PP_String>& vals);
03473
03474 ~PP_entry()
03475 {}
03476
03477 PP_String defname;
03478 ParmParse::PPType deftype;
03479 PP_Array<PP_String> val;
03480
03481 void dump (std::ostream& os) const;
03482 };
03483 #endif //doxygen
03484
03485
03486
03487
03488
03489 inline
03490 int
03491 ParmParse::countval (const char* name,
03492 int n)
03493 {
03494
03495
03496
03497 const PP_entry* def = ppindex(n,name);
03498 return def == 0 ? 0 : def->val.length();
03499 }
03500
03501 inline
03502 void
03503 ParmParse::get (const char* name,
03504 int& ptr,
03505 int ival)
03506 {
03507 getval(name,ppInt,&ptr,ival,-1);
03508 }
03509
03510 inline
03511 int
03512 ParmParse::query (const char* name,
03513 int& ptr,
03514 int ival)
03515 {
03516 return queryval(name,ppInt,&ptr,ival,-1);
03517 }
03518
03519 inline
03520 void
03521 ParmParse::get (const char* name,
03522 float& ptr,
03523 int ival)
03524 {
03525 getval(name,ppFloat,&ptr,ival,-1);
03526 }
03527
03528 inline
03529 int
03530 ParmParse::query (const char* name,
03531 float& ptr,
03532 int ival)
03533 {
03534 return queryval(name,ppFloat,&ptr,ival,-1);
03535 }
03536
03537 inline
03538 void
03539 ParmParse::get (const char* name,
03540 double& ptr,
03541 int ival)
03542 {
03543 getval(name,ppDouble,&ptr,ival,-1);
03544 }
03545
03546 inline
03547 int
03548 ParmParse::query (const char* name,
03549 double& ptr,
03550 int ival)
03551 {
03552 return queryval(name,ppDouble,&ptr,ival,-1);
03553 }
03554
03555 inline
03556 void
03557 ParmParse::get (const char* name,
03558 std::string& ptr,
03559 int ival)
03560 {
03561 PP_String pp_string;
03562 getval(name,ppString,&pp_string,ival,-1);
03563 ptr = pp_string.c_str();
03564 }
03565
03566 inline
03567 int
03568 ParmParse::query (const char* name,
03569 std::string& ptr,
03570 int ival)
03571 {
03572 PP_String pp_string;
03573 int status = queryval(name,ppString,&pp_string,ival,-1);
03574 if (status != 0)
03575 ptr = pp_string.c_str();
03576 return status;
03577 }
03578
03579 inline
03580 void
03581 ParmParse::getarr (const char* name,
03582 std::vector<int>& ptr,
03583 int start_ix,
03584 int num_val)
03585 {
03586 if (ptr.size() < num_val)
03587 ptr.resize(num_val);
03588 int* c_array = new int[num_val];
03589 getarr(name,ppInt,c_array,start_ix,num_val,-1);
03590 for (int i = 0; i < num_val; ++i)
03591 {
03592 ptr[i] = c_array[i];
03593 }
03594 delete[] c_array;
03595 }
03596
03597 inline
03598 void
03599 ParmParse::getarr (const char* name,
03600 Vector<int>& ptr,
03601 int start_ix,
03602 int num_val)
03603 {
03604 if (ptr.size() < num_val)
03605 ptr.resize(num_val);
03606 int* c_array = new int[num_val];
03607 getarr(name,ppInt,c_array,start_ix,num_val,-1);
03608 for (int i = 0; i < num_val; ++i)
03609 {
03610 ptr[i] = c_array[i];
03611 }
03612 delete[] c_array;
03613 }
03614
03615 inline
03616 int
03617 ParmParse::queryarr (const char* name,
03618 std::vector<int>& ptr,
03619 int start_ix,
03620 int num_val)
03621 {
03622 if (ptr.size() < num_val)
03623 ptr.resize(num_val);
03624 int* c_array = new int[num_val];
03625 int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03626 if (status != 0 )
03627 {
03628 for (int i = 0; i < num_val; ++i)
03629 {
03630 ptr[i] = c_array[i];
03631 }
03632 }
03633 return status;
03634 }
03635
03636 inline
03637 int
03638 ParmParse::queryarr (const char* name,
03639 Vector<int>& ptr,
03640 int start_ix,
03641 int num_val)
03642 {
03643 if (ptr.size() < num_val)
03644 ptr.resize(num_val);
03645 int* c_array = new int[num_val];
03646 int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03647 if (status != 0 )
03648 {
03649 for (int i = 0; i < num_val; ++i)
03650 {
03651 ptr[i] = c_array[i];
03652 }
03653 }
03654 return status;
03655 }
03656
03657 inline
03658 void
03659 ParmParse::getarr (const char* name,
03660 std::vector<float>& ptr,
03661 int start_ix,
03662 int num_val)
03663 {
03664 if (ptr.size() < num_val)
03665 ptr.resize(num_val);
03666 float* c_array = new float[num_val];
03667 getarr(name,ppFloat,c_array,start_ix,num_val,-1);
03668 for (int i = 0; i < num_val; ++i)
03669 {
03670 ptr[i] = c_array[i];
03671 }
03672 delete[] c_array;
03673 }
03674
03675 inline
03676 void
03677 ParmParse::getarr (const char* name,
03678 Vector<float>& ptr,
03679 int start_ix,
03680 int num_val)
03681 {
03682 if (ptr.size() < num_val)
03683 ptr.resize(num_val);
03684 float* c_array = new float[num_val];
03685 getarr(name,ppFloat,c_array,start_ix,num_val,-1);
03686 for (int i = 0; i < num_val; ++i)
03687 {
03688 ptr[i] = c_array[i];
03689 }
03690 delete[] c_array;
03691 }
03692
03693 inline
03694 int
03695 ParmParse::queryarr (const char* name,
03696 std::vector<float>& ptr,
03697 int start_ix,
03698 int num_val)
03699 {
03700 if (ptr.size() < num_val)
03701 ptr.resize(num_val);
03702 float* c_array = new float[num_val];
03703 int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03704 if (status != 0)
03705 {
03706 for (int i = 0; i < num_val; ++i)
03707 {
03708 ptr[i] = c_array[i];
03709 }
03710 }
03711 delete[] c_array;
03712 return status;
03713 }
03714
03715 inline
03716 int
03717 ParmParse::queryarr (const char* name,
03718 Vector<float>& ptr,
03719 int start_ix,
03720 int num_val)
03721 {
03722 if (ptr.size() < num_val)
03723 ptr.resize(num_val);
03724 float* c_array = new float[num_val];
03725 int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03726 if (status != 0)
03727 {
03728 for (int i = 0; i < num_val; ++i)
03729 {
03730 ptr[i] = c_array[i];
03731 }
03732 }
03733 delete[] c_array;
03734 return status;
03735 }
03736
03737 inline
03738 void
03739 ParmParse::getarr (const char* name,
03740 std::vector<double>& ptr,
03741 int start_ix,
03742 int num_val)
03743 {
03744 if (ptr.size() < num_val)
03745 ptr.resize(num_val);
03746 double* c_array = new double[num_val];
03747 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03748 if (status == 0)
03749 {
03750 cerr << "ParmParse::getarr(): "
03751 << name
03752 << " not found in table" << endl;
03753 dumpTable(cerr);
03754 MayDay::Abort();
03755 }
03756 for (int i = 0; i < num_val; ++i)
03757 {
03758 ptr[i] = c_array[i];
03759 }
03760 delete[] c_array;
03761 }
03762
03763 inline
03764 void
03765 ParmParse::getarr (const char* name,
03766 Vector<double>& ptr,
03767 int start_ix,
03768 int num_val)
03769 {
03770 if (ptr.size() < num_val)
03771 ptr.resize(num_val);
03772 double* c_array = new double[num_val];
03773 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03774 if (status == 0)
03775 {
03776 cerr << "ParmParse::getarr(): "
03777 << name
03778 << " not found in table" << endl;
03779 dumpTable(cerr);
03780 MayDay::Abort();
03781 }
03782 for (int i = 0; i < num_val; ++i)
03783 {
03784 ptr[i] = c_array[i];
03785 }
03786 delete[] c_array;
03787 }
03788
03789 inline
03790 int
03791 ParmParse::queryarr (const char* name,
03792 std::vector<double>& ptr,
03793 int start_ix,
03794 int num_val)
03795 {
03796 if (ptr.size() < num_val)
03797 ptr.resize(num_val);
03798 double* c_array = new double[num_val];
03799 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03800 if (status != 0)
03801 {
03802 for (int i = 0; i < num_val; ++i)
03803 {
03804 ptr[i] = c_array[i];
03805 }
03806 }
03807 delete[] c_array;
03808 return status;
03809 }
03810
03811 inline
03812 int
03813 ParmParse::queryarr (const char* name,
03814 Vector<double>& ptr,
03815 int start_ix,
03816 int num_val)
03817 {
03818 if (ptr.size() < num_val)
03819 ptr.resize(num_val);
03820 double* c_array = new double[num_val];
03821 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03822 if (status != 0)
03823 {
03824 for (int i = 0; i < num_val; ++i)
03825 {
03826 ptr[i] = c_array[i];
03827 }
03828 }
03829 delete[] c_array;
03830 return status;
03831 }
03832
03833 inline
03834 void
03835 ParmParse::getarr (const char* name,
03836 std::vector<std::string>& ptr,
03837 int start_ix,
03838 int num_val)
03839 {
03840 if (ptr.size() < num_val)
03841 ptr.resize(num_val);
03842 PP_String* c_array = new PP_String[num_val];
03843 getarr(name,ppString,c_array,start_ix,num_val,-1);
03844 for (int i = 0; i < num_val; ++i)
03845 {
03846 ptr[i] = c_array[i].c_str();
03847 }
03848 delete[] c_array;
03849 }
03850
03851 inline
03852 void
03853 ParmParse::getarr (const char* name,
03854 Vector<std::string>& ptr,
03855 int start_ix,
03856 int num_val)
03857 {
03858 if (ptr.size() < num_val)
03859 ptr.resize(num_val);
03860 PP_String* c_array = new PP_String[num_val];
03861 getarr(name,ppString,c_array,start_ix,num_val,-1);
03862 for (int i = 0; i < num_val; ++i)
03863 {
03864 ptr[i] = c_array[i].c_str();
03865 }
03866 delete[] c_array;
03867 }
03868
03869 inline
03870 int
03871 ParmParse::queryarr (const char* name,
03872 std::vector<std::string>& ptr,
03873 int start_ix,
03874 int num_val)
03875 {
03876 if (ptr.size() < num_val)
03877 ptr.resize(num_val);
03878 PP_String* c_array = new PP_String[num_val];
03879 int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
03880 if (status != 0)
03881 {
03882 for (int i = 0; i < num_val; ++i)
03883 {
03884 ptr[i] = c_array[i].c_str();
03885 }
03886 }
03887 delete[] c_array;
03888 return status;
03889 }
03890
03891 inline
03892 int
03893 ParmParse::queryarr (const char* name,
03894 Vector<std::string>& ptr,
03895 int start_ix,
03896 int num_val)
03897 {
03898 if (ptr.size() < num_val)
03899 ptr.resize(num_val);
03900 PP_String* c_array = new PP_String[num_val];
03901 int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
03902 if (status != 0)
03903 {
03904 for (int i = 0; i < num_val; ++i)
03905 {
03906 ptr[i] = c_array[i].c_str();
03907 }
03908 }
03909 delete[] c_array;
03910 return status;
03911 }
03912
03913 inline
03914 bool
03915 ParmParse::isInteger (const PP_String& str,
03916 int& val)
03917 {
03918
03919
03920
03921 char* endp = 0;
03922 val = (int) strtol(str.c_str(), &endp, 10);
03923 return *endp == 0;
03924 }
03925
03926 inline
03927 int
03928 ParmParse::isDouble (const PP_String& str,
03929 double& val)
03930 {
03931 char* endp = 0;
03932 val = std::strtod(str.c_str(), &endp);
03933 return *endp == 0;
03934 }
03935
03936 inline
03937 int
03938 ParmParse::countname (const std::string& name)
03939 {
03940 return countname(name.c_str());
03941 }
03942
03943 #endif