00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _PARMPARSE_H_
00012 #define _PARMPARSE_H_
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <iostream>
00028 #include <iomanip>
00029 #include <cstdlib>
00030 #include <cstring>
00031 #include <vector>
00032
00033 #include "CH_assert.H"
00034 #include "MayDay.H"
00035 #include "Misc.H"
00036 #include "Vector.H"
00037 #include "BaseNamespaceHeader.H"
00038 using std::cout;
00039 using std::cerr;
00040 using std::endl;
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef DOXYGEN
00058 class PP_UseCount
00059 {
00060 public:
00061
00063
00064 PP_UseCount ();
00065
00067
00068 PP_UseCount (const PP_UseCount& rhs);
00069
00074 PP_UseCount& operator= (const PP_UseCount& rhs);
00075
00077
00078 ~PP_UseCount ();
00079
00081
00082 bool unique () const;
00083
00085
00086 int linkCount () const;
00087
00088 private:
00089
00090
00091
00092 unsigned int* cnt;
00093
00094
00095
00096
00097 void decrement ();
00098 };
00099
00100
00101
00102
00103
00104 inline
00105 PP_UseCount::PP_UseCount ()
00106 :
00107 cnt(new unsigned int(1))
00108 {}
00109
00110 inline
00111 PP_UseCount::PP_UseCount (const PP_UseCount& rhs)
00112 :
00113 cnt(rhs.cnt)
00114 {
00115 ++*cnt;
00116 }
00117
00118 inline
00119 bool
00120 PP_UseCount::unique () const
00121 {
00122 return *cnt == 1;
00123 }
00124
00125 inline
00126 void
00127 PP_UseCount::decrement ()
00128 {
00129 if (unique())
00130 {
00131 delete cnt;
00132 cnt = 0;
00133 }
00134 else
00135 --*cnt;
00136 }
00137
00138 inline
00139 PP_UseCount&
00140 PP_UseCount::operator= (const PP_UseCount& rhs)
00141 {
00142 ++*rhs.cnt;
00143 decrement();
00144 cnt = rhs.cnt;
00145 return *this;
00146 }
00147
00148 inline
00149 PP_UseCount::~PP_UseCount ()
00150 {
00151 decrement();
00152 }
00153
00154 inline
00155 int
00156 PP_UseCount::linkCount () const
00157 {
00158 return *cnt;
00159 }
00160
00162
00179 template <class T>
00180 class PP_CpPtr
00181 {
00182 public:
00183
00185
00186 PP_CpPtr ();
00187
00189
00190 PP_CpPtr (T* rhs);
00191
00193
00194 ~PP_CpPtr ();
00195
00204 PP_CpPtr (const PP_CpPtr<T>& rhs);
00205
00209 PP_CpPtr<T>& operator= (T* rhs);
00210
00219 PP_CpPtr<T>& operator= (const PP_CpPtr<T>& rhs);
00220
00226 T& operator* () const;
00227
00229
00230 bool isNull () const;
00231
00233
00234 T* release ();
00235
00237
00238 bool operator== (const PP_CpPtr<T>& rhs) const;
00239
00241
00242 bool operator!= (const PP_CpPtr<T>& rhs) const;
00243
00244 protected:
00245 T* ptr;
00246 };
00247
00249
00261 template<class T>
00262 class PP_CpClassPtr :
00263 public PP_CpPtr<T>
00264 {
00265 public:
00266
00268
00269 PP_CpClassPtr ();
00270
00272
00273 PP_CpClassPtr (T* rhs);
00274
00283 PP_CpClassPtr (const PP_CpClassPtr<T>& rhs);
00284
00288 PP_CpClassPtr<T>& operator= (T* rhs);
00289
00298 PP_CpClassPtr<T>& operator= (const PP_CpClassPtr<T>& rhs);
00299
00301
00302 T* operator-> () const;
00303 };
00304
00306
00319 template<class T>
00320 class PP_LnPtr
00321 {
00322 public:
00323
00325
00326 PP_LnPtr ();
00327
00329
00330 PP_LnPtr (T* rhs);
00331
00337 PP_LnPtr<T>& operator= (const PP_LnPtr<T>& rhs);
00338
00343 PP_LnPtr<T>& operator= (T* rhs)
00344 {
00345
00346
00347
00348 if (unique())
00349 delete ptr;
00350 ptr = rhs;
00351 ucnt = PP_UseCount();
00352 return *this;
00353 }
00354
00358 ~PP_LnPtr ();
00359
00361
00362 bool unique () const;
00363
00365
00366 int linkCount () const;
00367
00373 T& operator* () const;
00374
00376
00377 bool isNull () const;
00378
00380
00381 bool operator== (const PP_LnPtr<T>& rhs) const;
00382
00384
00385 bool operator!= (const PP_LnPtr<T>& rhs) const;
00386
00387 protected:
00388 T* ptr;
00389
00390 private:
00391 PP_UseCount ucnt;
00392 };
00393
00395
00406 template<class T>
00407 class PP_LnClassPtr
00408 : public PP_LnPtr<T>
00409 {
00410 public:
00411
00413
00414 PP_LnClassPtr ();
00415
00417
00418 PP_LnClassPtr (T* rhs);
00419
00425 PP_LnClassPtr<T>& operator= (const PP_LnClassPtr<T>& rhs);
00426
00431 PP_LnClassPtr<T>& operator= (T* rhs);
00432
00434
00435 T* operator->() const;
00436 };
00437
00438
00439
00440
00441
00442 template <class T>
00443 inline
00444 PP_CpPtr<T>::PP_CpPtr ()
00445 :
00446 ptr(0)
00447 {}
00448
00449 template <class T>
00450 inline
00451 PP_CpPtr<T>::PP_CpPtr(T* rhs)
00452 :
00453 ptr(rhs)
00454 {}
00455
00456 template <class T>
00457 inline
00458 PP_CpPtr<T>::~PP_CpPtr()
00459 {
00460 delete ptr;
00461 }
00462
00463 template <class T>
00464 inline
00465 bool
00466 PP_CpPtr<T>::isNull () const
00467 {
00468 return ptr == 0;
00469 }
00470
00471 template <class T>
00472 inline
00473 PP_CpPtr<T>::PP_CpPtr (const PP_CpPtr<T>& rhs)
00474 {
00475 ptr = rhs.isNull() ? 0 : new T(*rhs.ptr);
00476 }
00477
00478 template <class T>
00479 inline
00480 PP_CpPtr<T>&
00481 PP_CpPtr<T>::operator= (const PP_CpPtr<T>& rhs)
00482 {
00483 if (!(ptr == rhs.ptr))
00484 {
00485 delete ptr;
00486 ptr = rhs.isNull() ? 0 : new T(*rhs.ptr);
00487 }
00488 return *this;
00489 }
00490
00491 template <class T>
00492 inline
00493 PP_CpPtr<T>&
00494 PP_CpPtr<T>::operator= (T* rhs)
00495 {
00496 delete ptr;
00497 ptr = rhs;
00498 return *this;
00499 }
00500
00501 template <class T>
00502 inline
00503 T&
00504 PP_CpPtr<T>::operator* () const
00505 {
00506 CH_assert(ptr != 0);
00507 return *ptr;
00508 }
00509
00510 template <class T>
00511 inline
00512 T*
00513 PP_CpPtr<T>::release ()
00514 {
00515 T* old = ptr;
00516 ptr = 0;
00517 return old;
00518 }
00519
00520 template <class T>
00521 inline
00522 bool
00523 PP_CpPtr<T>::operator== (const PP_CpPtr<T>& rhs) const
00524 {
00525 return ptr == rhs.ptr;
00526 }
00527
00528 template <class T>
00529 inline
00530 bool
00531 PP_CpPtr<T>::operator!= (const PP_CpPtr<T>& rhs) const
00532 {
00533 return ptr != rhs.ptr;
00534 }
00535
00536 template <class T>
00537 inline
00538 PP_CpClassPtr<T>::PP_CpClassPtr ()
00539 :
00540 PP_CpPtr<T>()
00541 {}
00542
00543 template <class T>
00544 inline
00545 PP_CpClassPtr<T>::PP_CpClassPtr (T* rhs)
00546 :
00547 PP_CpPtr<T>(rhs)
00548 {}
00549
00550 template <class T>
00551 inline
00552 PP_CpClassPtr<T>::PP_CpClassPtr (const PP_CpClassPtr<T>& rhs)
00553 :
00554 PP_CpPtr<T>(rhs)
00555 {}
00556
00557 template <class T>
00558 inline
00559 PP_CpClassPtr<T>&
00560 PP_CpClassPtr<T>::operator= (T* rhs)
00561 {
00562 PP_CpPtr<T>::operator= (rhs);
00563 return *this;
00564 }
00565
00566 template <class T>
00567 inline
00568 PP_CpClassPtr<T>&
00569 PP_CpClassPtr<T>::operator= (const PP_CpClassPtr<T>& rhs)
00570 {
00571 PP_CpPtr<T>::operator= (rhs);
00572 return *this;
00573 }
00574
00575 template <class T>
00576 inline
00577 T*
00578 PP_CpClassPtr<T>::operator-> () const
00579 {
00580 return this->ptr;
00581 }
00582
00583 template <class T>
00584 inline
00585 PP_LnPtr<T>::PP_LnPtr ()
00586 :
00587 ptr(0)
00588 {}
00589
00590 template <class T>
00591 inline
00592 PP_LnPtr<T>::PP_LnPtr(T* rhs)
00593 :
00594 ptr(rhs)
00595 {}
00596
00597 template <class T>
00598 inline
00599 bool
00600 PP_LnPtr<T>::unique () const
00601 {
00602 return ucnt.unique();
00603 }
00604
00605 template <class T>
00606 inline
00607 PP_LnPtr<T>::~PP_LnPtr ()
00608 {
00609 if (ucnt.unique())
00610 delete ptr;
00611 }
00612
00613 template <class T>
00614 inline
00615 PP_LnPtr<T>&
00616 PP_LnPtr<T>::operator= (const PP_LnPtr<T>& rhs)
00617 {
00618 if (ptr != rhs.ptr)
00619 {
00620 if (unique())
00621 delete ptr;
00622 ptr = rhs.ptr;
00623 ucnt = rhs.ucnt;
00624 }
00625 return *this;
00626 }
00627
00628 template <class T>
00629 inline
00630 int
00631 PP_LnPtr<T>::linkCount () const
00632 {
00633 return ucnt.linkCount();
00634 }
00635
00636 template <class T>
00637 inline
00638 T&
00639 PP_LnPtr<T>::operator* () const
00640 {
00641 CH_assert(ptr != 0);
00642 return *ptr;
00643 }
00644
00645 template <class T>
00646 inline
00647 bool
00648 PP_LnPtr<T>::isNull () const
00649 {
00650 return ptr == 0;
00651 }
00652
00653 template <class T>
00654 inline
00655 bool
00656 PP_LnPtr<T>::operator== (const PP_LnPtr<T>& rhs) const
00657 {
00658 return ptr == rhs.ptr;
00659 }
00660
00661 template <class T>
00662 inline
00663 bool
00664 PP_LnPtr<T>::operator!= (const PP_LnPtr<T>& rhs) const
00665 {
00666 return ptr != rhs.ptr;
00667 }
00668
00669 template <class T>
00670 inline
00671 PP_LnClassPtr<T>::PP_LnClassPtr ()
00672 {}
00673
00674 template <class T>
00675 inline
00676 PP_LnClassPtr<T>::PP_LnClassPtr (T* rhs)
00677 :
00678 PP_LnPtr<T>(rhs)
00679 {}
00680
00681 template <class T>
00682 inline
00683 PP_LnClassPtr<T>&
00684 PP_LnClassPtr<T>::operator= (const PP_LnClassPtr<T>& rhs)
00685 {
00686 PP_LnPtr<T>::operator=(rhs);
00687 return *this;
00688 }
00689
00690 template <class T>
00691 inline
00692 PP_LnClassPtr<T>&
00693 PP_LnClassPtr<T>::operator= (T* rhs)
00694 {
00695 PP_LnPtr<T>::operator=(rhs);
00696 return *this;
00697 }
00698
00699 template <class T>
00700 inline
00701 T*
00702 PP_LnClassPtr<T>::operator->() const
00703 {
00704 return this->ptr;
00705 }
00706
00707
00708
00709
00710
00711 class PP_StringRep
00712 {
00713 friend class PP_String;
00714 char* s;
00715 int bufferlength;
00716 public:
00717 PP_StringRep (int _len = 0);
00718 ~PP_StringRep ();
00719
00720
00721
00722 void resize (int n);
00723 };
00724
00725
00726
00727
00728
00729 inline
00730 PP_StringRep::PP_StringRep (int _len)
00731 {
00732 bufferlength = _len;
00733 s = new char [bufferlength];
00734 }
00735
00736 inline
00737 PP_StringRep::~PP_StringRep ()
00738 {
00739 delete [] s;
00740 s = 0;
00741 }
00742
00744
00767 class PP_String
00768 {
00769 public:
00770
00772
00773 PP_String ();
00774
00778 PP_String (char c);
00779
00788 PP_String (int len);
00789
00793 PP_String (const char* s);
00794
00796
00797 PP_String (const PP_String& rhs);
00798
00800
00801 PP_String& operator= (const PP_String& rhs);
00802
00806 PP_String& operator+= (const PP_String& right);
00807
00812 PP_String& operator+= (const char* right);
00813
00818 PP_String& operator+= (char c);
00819
00823 PP_String& toUpper ();
00824
00828 PP_String& toLower ();
00829
00836 std::istream& getline (std::istream& strm);
00837
00841 int length () const;
00842
00843
00845
00846 bool isNull () const;
00847
00851 char& operator [] (int k);
00852
00856 char operator[] (int k) const;
00857
00861 const char* c_str () const;
00862
00868 double toDouble () const;
00869
00875 int toInteger () const;
00876
00882 long toLong () const;
00883
00885
00886 friend std::ostream& operator<< (std::ostream& os,
00887 const PP_String& str);
00888
00901 friend std::istream& operator>> (std::istream& is,
00902 PP_String& str);
00903
00904 protected:
00905 void copyModify ();
00906
00907 private:
00908 PP_LnClassPtr<PP_StringRep> p;
00909 int len;
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920 friend inline bool operator< (const PP_String& left,
00921 const PP_String& right);
00922
00923
00924
00925 friend inline bool operator<= (const PP_String& left,
00926 const PP_String& right);
00927
00928
00929
00930 friend inline bool operator!= (const PP_String& left,
00931 const PP_String& right);
00932
00933
00934
00935 friend inline bool operator== (const PP_String& left,
00936 const PP_String& right);
00937
00938
00939
00940 friend inline bool operator>= (const PP_String& left,
00941 const PP_String& right);
00942
00943
00944
00945 friend inline bool operator> (const PP_String& left,
00946 const PP_String& right);
00947
00948
00949
00950 friend inline bool operator< (const PP_String& left,
00951 const char* right);
00952
00953
00954
00955 friend inline bool operator<= (const PP_String& left,
00956 const char* right);
00957
00958
00959
00960 friend inline bool operator!= (const PP_String& left,
00961 const char* right);
00962
00963
00964
00965 friend inline bool operator== (const PP_String& left,
00966 const char* right);
00967
00968
00969
00970 friend inline bool operator>= (const PP_String& left,
00971 const char* right);
00972
00973
00974
00975 friend inline bool operator> (const PP_String& left,
00976 const char* right);
00977
00978
00979
00980 friend inline bool operator< (const char* left,
00981 const PP_String& right);
00982
00983
00984
00985 friend inline bool operator<= (const char* left,
00986 const PP_String& right);
00987
00988
00989
00990 friend inline bool operator!= (const char* left,
00991 const PP_String& right);
00992
00993
00994
00995 friend inline bool operator== (const char* left,
00996 const PP_String& right);
00997
00998
00999
01000 friend inline bool operator>= (const char* left,
01001 const PP_String& right);
01002
01003
01004
01005 friend inline bool operator> (const char* left,
01006 const PP_String& right);
01007 };
01008
01009
01010
01011
01012
01013 inline
01014 bool
01015 PP_String::isNull () const
01016 {
01017 return len == 0;
01018 }
01019
01020 inline
01021 int
01022 PP_String::length () const
01023 {
01024 return len;
01025 }
01026
01027 inline
01028 double
01029 PP_String::toDouble () const
01030 {
01031 return len == 0 ? 0 : std::atof(p->s);
01032 }
01033
01034 inline
01035 int
01036 PP_String::toInteger () const
01037 {
01038 return len == 0 ? 0 : atoi(p->s);
01039 }
01040
01041 inline
01042 long
01043 PP_String::toLong () const
01044 {
01045 return len == 0 ? 0 : atol(p->s);
01046 }
01047
01048 inline
01049 const char*
01050 PP_String::c_str () const
01051 {
01052 return p->s;
01053 }
01054
01055 inline
01056 char
01057 PP_String::operator[] (int index) const
01058 {
01059 CH_assert(index >=0 && index < len);
01060 return p->s[index];
01061 }
01062
01063 inline
01064 PP_String
01065 operator+ (const PP_String& left,
01066 const PP_String& right)
01067 {
01068 PP_String result(left);
01069 return result += right;
01070 }
01071
01072 inline
01073 bool
01074 operator< (const PP_String& left,
01075 const PP_String& right)
01076 {
01077 return ::strcmp(left.c_str(), right.c_str()) < 0;
01078 }
01079
01080 inline
01081 bool
01082 operator<= (const PP_String& left,
01083 const PP_String& right)
01084 {
01085 return ::strcmp(left.c_str(), right.c_str()) <= 0;
01086 }
01087
01088 inline
01089 bool
01090 operator!= (const PP_String& left,
01091 const PP_String& right)
01092 {
01093 return ::strcmp(left.c_str(), right.c_str()) != 0;
01094 }
01095
01096 inline
01097 bool
01098 operator== (const PP_String& left,
01099 const PP_String& right)
01100 {
01101 return ::strcmp(left.c_str(), right.c_str()) == 0;
01102 }
01103
01104 inline
01105 bool
01106 operator>= (const PP_String& left,
01107 const PP_String& right)
01108 {
01109 return ::strcmp(left.c_str(), right.c_str()) >= 0;
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 char* right)
01124 {
01125 return ::strcmp(left.c_str(), right) < 0;
01126 }
01127
01128 inline
01129 bool
01130 operator<= (const PP_String& left,
01131 const char* right)
01132 {
01133 return ::strcmp(left.c_str(), right) <= 0;
01134 }
01135
01136 inline
01137 bool
01138 operator!= (const PP_String& left,
01139 const char* right)
01140 {
01141 return ::strcmp(left.c_str(), right) != 0;
01142 }
01143
01144 inline
01145 bool
01146 operator== (const PP_String& left,
01147 const char* right)
01148 {
01149 return ::strcmp(left.c_str(), right) == 0;
01150 }
01151
01152 inline
01153 bool
01154 operator>= (const PP_String& left,
01155 const char* right)
01156 {
01157 return ::strcmp(left.c_str(), right) >= 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 char* left,
01171 const PP_String& right)
01172 {
01173 return ::strcmp(left, right.c_str()) < 0;
01174 }
01175
01176 inline
01177 bool
01178 operator<= (const char* left,
01179 const PP_String& right)
01180 {
01181 return ::strcmp(left, right.c_str()) <= 0;
01182 }
01183
01184 inline
01185 bool
01186 operator!= (const char* left,
01187 const PP_String& right)
01188 {
01189 return ::strcmp(left, right.c_str()) != 0;
01190 }
01191
01192 inline
01193 bool
01194 operator== (const char* left,
01195 const PP_String& right)
01196 {
01197 return ::strcmp(left, right.c_str()) == 0;
01198 }
01199
01200 inline
01201 bool
01202 operator>= (const char* left,
01203 const PP_String& right)
01204 {
01205 return ::strcmp(left, right.c_str()) >= 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
01217
01218 template <class T> class PP_ListLink;
01219 template <class T> class PP_ListIterator;
01220 template <class T> class PP_List;
01221
01222 template <class T>
01223 class PP_ListLink
01224 {
01225 private:
01226 friend class PP_List<T>;
01227 friend class PP_ListIterator<T>;
01228
01229 PP_ListLink (const T& _val,
01230 PP_ListLink<T>* _pre,
01231 PP_ListLink<T>* _suc)
01232 :
01233 val(_val),
01234 pre(_pre),
01235 suc(_suc)
01236 {}
01237
01238 private:
01239 T val;
01240 PP_ListLink<T>* pre;
01241 PP_ListLink<T>* suc;
01242 };
01243
01245
01255 template <class T>
01256 class PP_ListIterator
01257 {
01258 public:
01259
01261
01262 PP_ListIterator (const PP_List<T>& aList);
01263
01265
01266 PP_ListIterator (const PP_ListIterator<T>& rhs);
01267
01271 void rewind ();
01272
01276 const T& operator() () const;
01277
01281 const T& operator* () const;
01282
01289 operator void* ();
01290
01294 bool operator! () const;
01295
01299 const T& value () const;
01300
01306 PP_ListIterator<T>& operator++ ();
01307
01313 PP_ListIterator<T>& operator-- ();
01314
01321 PP_ListIterator<T> operator-- (int);
01322
01328 PP_ListIterator<T> operator++ (int);
01329
01333 bool operator== (const PP_ListIterator<T>&) const;
01334
01336
01337 bool operator!= (const PP_ListIterator<T>&) const;
01338
01339 protected:
01340
01341
01342
01343 PP_ListIterator (const PP_List<T>& _list,
01344 PP_ListLink<T>* _p);
01345
01346
01347
01348 const PP_List<T>& list;
01349
01350
01351
01352 PP_ListLink<T>* p;
01353
01354 private:
01355 friend class PP_List<T>;
01356
01357
01358
01359 PP_ListIterator ();
01360 PP_ListIterator<T>& operator= (const PP_ListIterator<T>&);
01361 };
01362
01364
01396 template <class T>
01397 class PP_List
01398 {
01399 public:
01400
01402
01403 PP_List ();
01404
01406
01407 PP_List (const PP_List<T>& rhs);
01408
01410
01411 PP_List<T>& operator= (const PP_List<T>& rhs);
01412
01414
01415 ~PP_List();
01416
01418
01419 void prepend (const T& value);
01420
01422
01423 void append (const T& value);
01424
01426
01427 void add (const T& value);
01428
01430
01431 void join (const PP_List<T>& src);
01432
01439 void catenate (PP_List<T>& src);
01440
01442
01443 void clear ();
01444
01446
01447 T& firstElement () const;
01448
01450
01451 T& lastElement () const;
01452
01457 bool includes (const T& value) const;
01458
01464 bool operator== (const PP_List<T>& rhs) const;
01465
01467
01468 bool operator!= (const PP_List<T>& rhs) const;
01469
01471
01472 bool isEmpty () const;
01473
01475
01476 bool isNotEmpty () const;
01477
01479
01480 int length () const;
01481
01483
01484 void removeFirst ();
01485
01487
01488 void removeLast ();
01489
01491
01492 const T& operator[] (const PP_ListIterator<T>& li) const;
01493
01495
01496 T& operator[] (const PP_ListIterator<T>& li);
01497
01499
01500 void remove (const T& value);
01501
01505 void remove (const PP_List<T>& lst);
01506
01508
01509 void remove (PP_ListIterator<T>& lit);
01510
01512
01513 void replace (PP_ListIterator<T>& li,
01514 const T& val);
01515
01519 void addAfter (PP_ListIterator<T>& lit,
01520 const T& val);
01521
01525 void addBefore (PP_ListIterator<T>& lit,
01526 const T& val);
01527
01529
01530 PP_ListIterator<T> first () const;
01531
01533
01534 PP_ListIterator<T> last () const;
01535
01536 protected:
01537
01538
01539
01540 void remove (PP_ListLink<T> *ln);
01541
01542
01543
01544 PP_ListLink<T>* addBefore (PP_ListLink<T>* ln,
01545 const T& val);
01546
01547
01548
01549 PP_ListLink<T>* addAfter (PP_ListLink<T>* ln,
01550 const T& val);
01551
01552
01553
01554 PP_ListLink<T>* head;
01555
01556
01557
01558 PP_ListLink<T>* tail;
01559
01560
01561
01562 friend class PP_ListIterator<T>;
01563 };
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573 template <class T>
01574 inline
01575 PP_ListIterator<T>::PP_ListIterator (const PP_List<T>& _list,
01576 PP_ListLink<T>* _p)
01577 :
01578 list(_list),
01579 p(_p)
01580 {}
01581
01582 template <class T>
01583 inline
01584 PP_ListIterator<T>::PP_ListIterator (const PP_List<T>& aList)
01585 :
01586 list(aList)
01587 {
01588 p = list.head;
01589 }
01590
01591 template <class T>
01592 inline
01593 PP_ListIterator<T>::PP_ListIterator (const PP_ListIterator<T>& li)
01594 :
01595 list(li.list),
01596 p(li.p)
01597 {}
01598
01599 template <class T>
01600 inline
01601 void
01602 PP_ListIterator<T>::rewind ()
01603 {
01604 p = list.head;
01605 }
01606
01607 template <class T>
01608 inline
01609 const T&
01610 PP_ListIterator<T>::operator() () const
01611 {
01612 CH_assert(p != 0);
01613 return p->val;
01614 }
01615
01616 template <class T>
01617 inline
01618 const T&
01619 PP_ListIterator<T>::operator* () const
01620 {
01621 CH_assert(p != 0);
01622 return p->val;
01623 }
01624
01625 template <class T>
01626 inline
01627 PP_ListIterator<T>::operator void* ()
01628 {
01629 return p != 0 ? this : 0;
01630 }
01631
01632 template <class T>
01633 inline
01634 bool
01635 PP_ListIterator<T>::operator! () const
01636 {
01637 return p == 0 ? true : false;
01638 }
01639
01640 template <class T>
01641 inline
01642 const T&
01643 PP_ListIterator<T>::value () const
01644 {
01645 CH_assert(p != 0);
01646 return p->val;
01647 }
01648
01649 template <class T>
01650 inline
01651 PP_ListIterator<T>&
01652 PP_ListIterator<T>::operator++ ()
01653 {
01654 if (p)
01655 p = p->suc;
01656 return *this;
01657 }
01658
01659 template <class T>
01660 inline
01661 PP_ListIterator<T>&
01662 PP_ListIterator<T>::operator-- ()
01663 {
01664 if (p)
01665 p = p->pre;
01666 return *this;
01667 }
01668
01669 template <class T>
01670 inline
01671 PP_ListIterator<T>
01672 PP_ListIterator<T>::operator++ (int)
01673 {
01674 const PP_ListIterator<T> li = *this;
01675 ++(*this);
01676 return li;
01677 }
01678
01679 template <class T>
01680 inline
01681 PP_ListIterator<T>
01682 PP_ListIterator<T>::operator-- (int)
01683 {
01684 const PP_ListIterator<T> li = *this;
01685 --(*this);
01686 return li;
01687 }
01688
01689 template <class T>
01690 inline
01691 bool
01692 PP_ListIterator<T>::operator== (const PP_ListIterator<T>& _li) const
01693 {
01694 return (&list == &_li.list && p == _li.p) ? true : false;
01695 }
01696
01697 template <class T>
01698 inline
01699 bool
01700 PP_ListIterator<T>::operator!= (const PP_ListIterator<T>& _li) const
01701 {
01702 return ! PP_ListIterator<T>::operator==(_li);
01703 }
01704
01705
01706
01707
01708
01709 template <class T>
01710 inline
01711 PP_List<T>::PP_List ()
01712 :
01713 head(0),
01714 tail(0)
01715 {}
01716
01717 template <class T>
01718 inline
01719 PP_List<T>::~PP_List ()
01720 {
01721 clear();
01722 }
01723
01724 template <class T>
01725 inline
01726 void
01727 PP_List<T>::prepend (const T& value)
01728 {
01729 addBefore(head, value);
01730 }
01731
01732 template <class T>
01733 inline
01734 void
01735 PP_List<T>::append (const T& value)
01736 {
01737 addAfter(tail, value);
01738 }
01739
01740 template <class T>
01741 inline
01742 T&
01743 PP_List<T>::firstElement () const
01744 {
01745 CH_assert(head != 0);
01746 return head->val;
01747 }
01748
01749 template <class T>
01750 inline
01751 T&
01752 PP_List<T>::lastElement () const
01753 {
01754 CH_assert(tail != 0);
01755 return tail->val;
01756 }
01757
01758 template <class T>
01759 inline
01760 bool
01761 PP_List<T>::isEmpty () const
01762 {
01763 return head == 0 && tail == 0;
01764 }
01765
01766 template <class T>
01767 inline
01768 bool
01769 PP_List<T>::isNotEmpty () const
01770 {
01771 return !isEmpty();
01772 }
01773
01774 template <class T>
01775 inline
01776 void
01777 PP_List<T>::removeFirst ()
01778 {
01779 remove(head);
01780 }
01781
01782 template <class T>
01783 inline
01784 void
01785 PP_List<T>::removeLast ()
01786 {
01787 remove(tail);
01788 }
01789
01790 template <class T>
01791 inline
01792 const T&
01793 PP_List<T>::operator[] (const PP_ListIterator<T>& li) const
01794 {
01795 CH_assert(li.p != 0);
01796 return li.p->val;
01797 }
01798
01799 template <class T>
01800 inline
01801 T&
01802 PP_List<T>::operator[] (const PP_ListIterator<T>& li)
01803 {
01804 CH_assert(li.p != 0);
01805 return li.p->val;
01806 }
01807
01808 template <class T>
01809 inline
01810 void
01811 PP_List<T>::replace (PP_ListIterator<T>& li,
01812 const T& _val)
01813 {
01814 CH_assert(li.p != 0);
01815 li.p->val = _val;
01816 }
01817
01818 template <class T>
01819 inline
01820 void
01821 PP_List<T>::addAfter (PP_ListIterator<T>& lit,
01822 const T& val)
01823 {
01824 addAfter(lit.p, val);
01825 }
01826
01827 template <class T>
01828 inline
01829 void
01830 PP_List<T>::addBefore (PP_ListIterator<T>& lit,
01831 const T& val)
01832 {
01833 addBefore(lit.p, val);
01834 }
01835
01836 template <class T>
01837 inline
01838 PP_ListIterator<T>
01839 PP_List<T>::first () const
01840 {
01841 return PP_ListIterator<T>(*this,head);
01842 }
01843
01844 template <class T>
01845 inline
01846 PP_ListIterator<T>
01847 PP_List<T>::last () const
01848 {
01849 return PP_ListIterator<T>(*this,tail);
01850 }
01851
01852
01853
01854
01855
01856 template <class T>
01857 inline
01858 PP_List<T>::PP_List (const PP_List<T>& source)
01859 :
01860 head(0),
01861 tail(0)
01862 {
01863 if (source.isEmpty())
01864 tail = head = 0;
01865 else
01866 for (PP_ListIterator<T> li(source); li; ++li)
01867 append(li());
01868 }
01869
01870
01871
01872
01873
01874 template <class T>
01875 inline void
01876 PP_List<T>::add (const T& value)
01877 {
01878 append(value);
01879 }
01880
01881 template <class T>
01882 inline
01883 int
01884 PP_List<T>::length () const
01885 {
01886 int len = 0;
01887 for (PP_ListIterator<T> li(*this); li; ++li)
01888 len++;
01889 return len;
01890 }
01891
01892 template <class T>
01893 inline
01894 PP_List<T>&
01895 PP_List<T>::operator= (const PP_List<T>& source)
01896 {
01897 if (!(this == &source))
01898 {
01899 clear();
01900 for (PP_ListIterator<T> li(source); li; ++li)
01901 append(li());
01902 }
01903 return *this;
01904 }
01905
01906 template <class T>
01907 inline PP_ListLink<T> *
01908 PP_List<T>::addBefore (PP_ListLink<T>* ln,
01909 const T& val)
01910 {
01911 CH_assert(ln != 0 || head == 0);
01912
01913 PP_ListLink<T>* newlink;
01914
01915 if (ln == head)
01916 {
01917 head = newlink = new PP_ListLink<T>(val, 0, head);
01918
01919 if (tail == 0)
01920 tail = head;
01921 else
01922 head->suc->pre = newlink;
01923 }
01924 else
01925 {
01926 newlink = new PP_ListLink<T>(val, ln->pre, ln);
01927
01928 ln->pre->suc = newlink;
01929 ln->pre = newlink;
01930 }
01931
01932 return newlink;
01933 }
01934
01935 template <class T>
01936 inline
01937 PP_ListLink<T>*
01938 PP_List<T>::addAfter (PP_ListLink<T>* ln,
01939 const T& val)
01940 {
01941 CH_assert(ln != 0 || tail == 0);
01942
01943 PP_ListLink<T>* newlink;
01944
01945
01946
01947
01948
01949
01950
01951 if (ln == tail)
01952 {
01953 tail = newlink = new PP_ListLink<T>(val,tail,0);
01954
01955 if (head == 0)
01956 head = tail;
01957 else
01958 tail->pre->suc = newlink;
01959 }
01960 else
01961 {
01962 newlink = new PP_ListLink<T>(val, ln, ln->suc);
01963
01964 ln->suc->pre = newlink;
01965 ln->suc = newlink;
01966 }
01967
01968 return newlink;
01969 }
01970
01971 template <class T>
01972 inline void
01973 PP_List<T>::join (const PP_List<T>& list2)
01974 {
01975 for (PP_ListIterator<T> li2(list2); li2; ++li2)
01976 append(li2());
01977 }
01978
01979 template <class T>
01980 inline void
01981 PP_List<T>::catenate (PP_List<T>& list2)
01982 {
01983 if (list2.isEmpty())
01984
01985
01986
01987 ;
01988 else if (isEmpty())
01989 {
01990 head = list2.head;
01991 tail = list2.tail;
01992 list2.head = 0;
01993 list2.tail = 0;
01994 }
01995 else
01996 {
01997 tail->suc = list2.head;
01998 list2.head->pre = tail;
01999 tail = list2.tail;
02000 list2.head = 0;
02001 list2.tail = 0;
02002 }
02003 }
02004
02005 template <class T>
02006 inline void
02007 PP_List<T>::clear ()
02008 {
02009 PP_ListLink<T>* next = 0;
02010
02011 for (PP_ListLink<T>* p = head; p != 0; p = next)
02012 {
02013 next = p->suc;
02014 p->suc = 0;
02015 delete p;
02016 }
02017 tail = head = 0;
02018 }
02019
02020 template <class T>
02021 inline bool
02022 PP_List<T>::includes (const T& v) const
02023 {
02024 bool rc = false;
02025 for (PP_ListIterator<T> li(*this); li && !rc; ++li)
02026 if (v == li())
02027 rc = true;
02028 return rc;
02029 }
02030
02031 template<class T>
02032 inline bool
02033 PP_List<T>::operator== (const PP_List<T>& rhs) const
02034 {
02035 if (length() == rhs.length())
02036 {
02037 for (PP_ListIterator<T> li(*this), ri(rhs); li; ++li, ++ri)
02038 if (li() != ri())
02039 return false;
02040 return true;
02041 }
02042
02043 return false;
02044 }
02045
02046 template<class T>
02047 inline bool
02048 PP_List<T>::operator!= (const PP_List<T>& rhs) const
02049 {
02050 return !operator==(rhs);
02051 }
02052
02053 template <class T>
02054 inline void
02055 PP_List<T>::remove (PP_ListIterator<T>& li)
02056 {
02057 PP_ListLink<T> *np = li.p->suc;
02058 remove(li.p);
02059 li.p = np;
02060 }
02061
02062 template <class T>
02063 inline void
02064 PP_List<T>::remove (const T& _v)
02065 {
02066 for (PP_ListIterator<T> litr(*this); litr; ++litr)
02067 if (litr() == _v)
02068 remove(litr);
02069 }
02070
02071 template <class T>
02072 inline void
02073 PP_List<T>::remove (const PP_List<T>& _lv)
02074 {
02075 for (PP_ListIterator<T> litr(_lv); litr; ++litr)
02076 remove(litr());
02077 }
02078
02079 template <class T>
02080 inline void
02081 PP_List<T>::remove (PP_ListLink<T>* ln)
02082 {
02083 CH_assert(head !=0 && tail != 0);
02084
02085 if (head == ln && tail == ln)
02086 head = tail = 0;
02087 else if (head == ln)
02088 {
02089 CH_assert(ln->pre == 0);
02090 head = ln->suc;
02091 head->pre = 0;
02092 }
02093 else if (tail == ln)
02094 {
02095 CH_assert(ln->suc == 0);
02096 tail = ln->pre;
02097 tail->suc = 0;
02098 }
02099 else
02100 {
02101 CH_assert(ln->suc != 0 && ln->pre != 0);
02102 ln->suc->pre = ln->pre;
02103 ln->pre->suc = ln->suc;
02104 }
02105 delete ln;
02106 ln = 0;
02107 }
02108
02109 template <class T> class PP_Array;
02110
02112
02150 template <class T>
02151 class PP_Array
02152 {
02153 public:
02154
02156
02157 PP_Array ();
02158
02162 PP_Array (long len);
02163
02167 PP_Array (long len,
02168 const T& initialvalue);
02169
02173 PP_Array (const T* vec,
02174 long len);
02175
02177
02178 PP_Array (const PP_Array<T>& rhs);
02179
02183 PP_Array<T>& operator= (const PP_Array<T>& rhs);
02184
02186
02187 ~PP_Array ();
02188
02192 void clear ();
02193
02195
02196 bool ready () const;
02197
02201 void reserve (long _truesize);
02202
02209 void shrinkWrap ();
02210
02219 void resize (long newlen);
02220
02229 void resize (long newlen,
02230 const T& initialvalue);
02231
02233
02234 long length () const;
02235
02239 long trueSize () const;
02240
02245 T& operator[] (long K);
02246
02248
02249 const T& operator[] (long K) const;
02250
02252
02253 T& get (long i);
02254
02256
02257 const T& get (long i) const;
02258
02263 T* dataPtr ();
02264
02266
02267 const T* dataPtr () const;
02268
02270
02271 void set (long i,
02272 const T& elem);
02273
02275
02276 void swap (long i,
02277 long j);
02278
02280
02281 bool operator== (const PP_Array<T>& rhs) const;
02282
02284
02285 bool operator!= (const PP_Array<T>& rhs) const;
02286
02287 protected:
02288
02289
02290
02291 long truesize;
02292
02293
02294
02295 long nelem;
02296
02297
02298
02299 T* vp;
02300
02301 private:
02302
02303
02304
02305 PP_Array<T>& operator= (int);
02306 };
02307
02308
02309
02310
02311
02312 template <class T>
02313 inline
02314 PP_Array<T>::PP_Array ()
02315 {
02316 nelem = 0;
02317 vp = new T[1];
02318 truesize = 1;
02319 }
02320
02321 template <class T>
02322 inline
02323 PP_Array<T>::PP_Array (long len)
02324 {
02325 CH_assert(len >= 0);
02326 nelem = len;
02327 vp = new T[len];
02328 truesize = nelem;
02329 }
02330
02331 template <class T>
02332 inline
02333 void
02334 PP_Array<T>::clear ()
02335 {
02336 delete [] vp;
02337 vp = 0;
02338 nelem = 0;
02339 truesize = 0;
02340 }
02341
02342 template <class T>
02343 inline
02344 PP_Array<T>::~PP_Array ()
02345 {
02346 clear();
02347 }
02348
02349 template <class T>
02350 inline
02351 bool
02352 PP_Array<T>::ready () const
02353 {
02354 return vp != 0 && nelem != 0;
02355 }
02356
02357 template <class T>
02358 inline
02359 long
02360 PP_Array<T>::length () const
02361 {
02362 return nelem;
02363 }
02364
02365 template <class T>
02366 inline
02367 long
02368 PP_Array<T>::trueSize () const
02369 {
02370 return truesize;
02371 }
02372
02373 template <class T>
02374 inline
02375 T&
02376 PP_Array<T>::operator[] (long i)
02377 {
02378 CH_assert(vp != 0);
02379 CH_assert(i >= 0 && i < nelem);
02380 return vp[i];
02381 }
02382
02383 template <class T>
02384 inline
02385 const T&
02386 PP_Array<T>::operator[] (long i) const
02387 {
02388 CH_assert(vp != 0);
02389 CH_assert(i >= 0 && i < nelem);
02390 return vp[i];
02391 }
02392
02393 template <class T>
02394 inline
02395 T&
02396 PP_Array<T>::get (long i)
02397 {
02398 CH_assert(vp != 0);
02399 CH_assert(i >= 0 && i < nelem);
02400 return vp[i];
02401 }
02402
02403 template <class T>
02404 inline
02405 const T&
02406 PP_Array<T>::get (long i) const
02407 {
02408 CH_assert(vp != 0);
02409 CH_assert(i >= 0 && i < nelem);
02410 return vp[i];
02411 }
02412
02413 template <class T>
02414 inline
02415 void
02416 PP_Array<T>::set (long i,
02417 const T& elem)
02418 {
02419 CH_assert(vp != 0);
02420 CH_assert(i >= 0 && i < nelem);
02421 vp[i] = elem;
02422 }
02423
02424 template <class T>
02425 inline
02426 T*
02427 PP_Array<T>::dataPtr ()
02428 {
02429 return vp;
02430 }
02431
02432 template <class T>
02433 inline
02434 const T*
02435 PP_Array<T>::dataPtr () const
02436 {
02437 return vp;
02438 }
02439
02440 template <class T>
02441 inline
02442 void
02443 PP_Array<T>::swap (long i,
02444 long j)
02445 {
02446 CH_assert(i >= 0 && i < nelem);
02447 CH_assert(j >= 0 && j < nelem);
02448 T tmp = vp[i];
02449 vp[i] = vp[j];
02450 vp[j] = tmp;
02451 }
02452
02453 template <class T>
02454 inline
02455 bool
02456 PP_Array<T>::operator!= (const PP_Array<T>& rhs) const
02457 {
02458 return !(operator==(rhs));
02459 }
02460
02461
02462
02463
02464
02465 template <class T>
02466 PP_Array<T>::PP_Array (long len,
02467 const T& initialValue)
02468 {
02469 CH_assert(len >= 0);
02470 nelem = len;
02471 vp = new T[len];
02472 truesize = nelem;
02473 for(long i = 0; i < nelem; ++i)
02474 vp[i] = initialValue;
02475 }
02476
02477 template <class T>
02478 PP_Array<T>::PP_Array (const T* vec,
02479 long len)
02480 {
02481 CH_assert(len >= 0);
02482 nelem = len;
02483 vp = new T[len];
02484 truesize = nelem;
02485 for(long i = 0; i < nelem; ++i)
02486 vp[i] = vec[i];
02487 }
02488
02489 template <class T>
02490 PP_Array<T>::PP_Array (const PP_Array<T>& a)
02491 {
02492 nelem = a.nelem;
02493 vp = new T[nelem];
02494 truesize = nelem;
02495 for (long i = 0; i < nelem; i++)
02496 vp[i] = a.vp[i];
02497 }
02498
02499 template <class T>
02500 PP_Array<T>&
02501 PP_Array<T>::operator= (const PP_Array<T>& sa)
02502 {
02503 if (this != &sa)
02504 {
02505 clear();
02506 vp = new T[sa.nelem];
02507 nelem = sa.nelem;
02508 truesize = nelem;
02509 for(long i = 0; i < nelem; i++)
02510 vp[i] = sa.vp[i];
02511 }
02512 return *this;
02513 }
02514
02515 template <class T>
02516 inline
02517 void
02518 PP_Array<T>::resize (long newlen)
02519 {
02520 if (newlen == nelem)
02521 return;
02522 if (newlen <= truesize)
02523 {
02524 nelem = newlen;
02525 return;
02526 }
02527 T* newvp = new T[newlen];
02528 long len = Min(newlen,nelem);
02529 for (long i = 0; i < len; i++)
02530 newvp[i] = vp[i];
02531 delete [] vp;
02532 vp = newvp;
02533 nelem = newlen;
02534 truesize = newlen;
02535 }
02536
02537 template <class T>
02538 inline
02539 void PP_Array<T>::resize (long newlen,
02540 const T& initialValue)
02541 {
02542 if (newlen == nelem)
02543 return;
02544 if (newlen <= truesize)
02545 {
02546 for(long i = nelem; i < newlen; ++i)
02547 vp[i] = initialValue;
02548 nelem = newlen;
02549 return;
02550 }
02551 T* newvp = new T[newlen];
02552 long len = Min(newlen,nelem);
02553 long i;
02554 for (i = 0; i < len; i++)
02555 newvp[i] = vp[i];
02556 for(i = len; i < newlen; ++i)
02557 newvp[i] = initialValue;
02558 delete [] vp;
02559 vp = newvp;
02560 nelem = newlen;
02561 truesize = newlen;
02562 }
02563
02564 template <class T>
02565 void
02566 PP_Array<T>::reserve (long _truesize)
02567 {
02568 if (_truesize > truesize)
02569 {
02570 T* newvp = new T[_truesize];
02571 for (long i = 0; i < nelem; i++)
02572 newvp[i] = vp[i];
02573 delete [] vp;
02574 vp = newvp;
02575 truesize = _truesize;
02576 }
02577 }
02578
02579 template <class T>
02580 void
02581 PP_Array<T>::shrinkWrap ()
02582 {
02583 if (nelem != truesize)
02584 {
02585 T* newvp = new T[nelem];
02586 for (long i = 0; i < nelem; i++)
02587 newvp[i] = vp[i];
02588 delete [] vp;
02589 vp = newvp;
02590 truesize = nelem;
02591 }
02592 }
02593
02594 template <class T>
02595 bool
02596 PP_Array<T>::operator== (const PP_Array<T>& rhs) const
02597 {
02598 if (length() != rhs.length())
02599 return false;
02600
02601 for (long i = 0; i < length(); ++i)
02602 if (!((*this)[i] == rhs[i]))
02603 return false;
02604
02605 return true;
02606 }
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758 class PP_entry;
02759
02760 #endif //for the doxygen thing
02761
02763
02834 class ParmParse
02835 {
02836 friend class PP_entry;
02837 public:
02838
02840
02848 ParmParse (int argc,
02849 char** argv,
02850 const char* prefix = 0,
02851 const char* parfile = 0);
02852
02854
02856 void define (int argc,
02857 char** argv,
02858 const char* prefix = 0,
02859 const char* parfile = 0);
02860
02868 ParmParse (const char* prefix = 0);
02869
02873 ~ParmParse();
02874
02876
02879 bool contains (const char* name);
02880
02882
02885 bool contains (const std::string& name);
02886
02888
02892 int countval (const char* name,
02893 int n = -1);
02894
02896
02899 int countname (const char* name);
02900
02902
02905 int countname (const std::string& name);
02906
02908
02911 void dumpTable (std::ostream& os);
02912
02914
02922 void get (const char* name,
02923 int& ref,
02924 int ival=0);
02925
02927
02936 int query (const char* name,
02937 int& ref,
02938 int ival=0);
02939
02941
02949 void get (const char* name,
02950 unsigned long& ref,
02951 int ival=0);
02952
02954
02963 int query (const char* name,
02964 unsigned long& ref,
02965 int ival=0);
02966
02968
02976 void get (const char* name,
02977 float& ref,
02978 int ival=0);
02979
02981
02990 int query (const char* name,
02991 float& ref,
02992 int ival=0);
02993
02995
03003 void get (const char* name,
03004 double& ref,
03005 int ival=0);
03006
03008
03017 int query (const char* name,
03018 double& ref,
03019 int ival=0);
03020
03022
03030 void get (const char* name,
03031 std::string& ref,
03032 int ival=0);
03033
03035
03044 int query (const char* name,
03045 std::string& ref,
03046 int ival=0);
03047
03049
03059 void get (const char* name,
03060 bool& ref,
03061 int ival=0);
03062
03064
03075 int query (const char* name,
03076 bool& ref,
03077 int ival=0);
03078
03079
03081
03093 void getarr (const char* name,
03094 Vector<int>& ref,
03095 int start_ix,
03096 int num_val);
03097
03099
03111 void getarr (const char* name,
03112 std::vector<int>& ref,
03113 int start_ix,
03114 int num_val);
03115
03117
03130 int queryarr (const char* name,
03131 Vector<int>& ref,
03132 int start_ix,
03133 int num_val);
03134
03136
03149 int queryarr (const char* name,
03150 std::vector<int>& ref,
03151 int start_ix,
03152 int num_val);
03153
03155
03167 void getarr (const char* name,
03168 Vector<unsigned long>& ref,
03169 int start_ix,
03170 int num_val);
03171
03173
03185 void getarr (const char* name,
03186 std::vector<unsigned long>& ref,
03187 int start_ix,
03188 int num_val);
03189
03191
03204 int queryarr (const char* name,
03205 Vector<unsigned long>& ref,
03206 int start_ix,
03207 int num_val);
03208
03210
03223 int queryarr (const char* name,
03224 std::vector<unsigned long>& ref,
03225 int start_ix,
03226 int num_val);
03227
03229
03241 void getarr (const char* name,
03242 Vector<float>& ref,
03243 int start_ix,
03244 int num_val);
03245
03247
03259 void getarr (const char* name,
03260 std::vector<float>& ref,
03261 int start_ix,
03262 int num_val);
03263
03265
03278 int queryarr (const char* name,
03279 Vector<float>& ref,
03280 int start_ix,
03281 int num_val);
03282
03284
03297 int queryarr (const char* name,
03298 std::vector<float>& ref,
03299 int start_ix,
03300 int num_val);
03301
03303
03315 void getarr (const char* name,
03316 Vector<double>& ref,
03317 int start_ix,
03318 int num_val);
03319
03321
03333 void getarr (const char* name,
03334 std::vector<double>& ref,
03335 int start_ix,
03336 int num_val);
03337
03339
03352 int queryarr (const char* name,
03353 Vector<double>& ref,
03354 int start_ix,
03355 int num_val);
03356
03358
03371 int queryarr (const char* name,
03372 std::vector<double>& ref,
03373 int start_ix,
03374 int num_val);
03375
03377
03389 void getarr (const char* name,
03390 Vector<std::string>& ref,
03391 int start_ix,
03392 int num_val);
03393
03395
03407 void getarr (const char* name,
03408 std::vector<std::string>& ref,
03409 int start_ix,
03410 int num_val);
03411
03413
03426 int queryarr (const char* name,
03427 Vector<std::string>& ref,
03428 int start_ix,
03429 int num_val);
03430
03432
03445 int queryarr (const char* name,
03446 std::vector<std::string>& ref,
03447 int start_ix,
03448 int num_val);
03449
03451
03463 void getarr (const char* name,
03464 Vector<bool>& ref,
03465 int start_ix,
03466 int num_val);
03467
03469
03481 void getarr (const char* name,
03482 std::vector<bool>& ref,
03483 int start_ix,
03484 int num_val);
03485
03487
03500 int queryarr (const char* name,
03501 Vector<bool>& ref,
03502 int start_ix,
03503 int num_val);
03504
03506
03519 int queryarr (const char* name,
03520 std::vector<bool>& ref,
03521 int start_ix,
03522 int num_val);
03523
03524 #ifndef DOXYGEN
03525
03526
03527
03528 enum PPType
03529 {
03530 ppDefn,
03531 ppOption,
03532 ppInt,
03533 ppUnsignedLong,
03534 ppFloat,
03535 ppDouble,
03536 ppString,
03537 ppBool,
03538 ppEQ_sign,
03539 ppEOF
03540 };
03541
03542
03543 protected:
03544
03545
03546
03547 static PP_List<PP_entry*> table;
03548
03549
03550
03551 static int xargc;
03552 static char** xargv;
03553
03554
03555
03556 static int num_obj;
03557
03558
03559
03560 void bldTable (const char* str,
03561 int lenstr,
03562 PP_List<PP_entry*>& tab);
03563
03564
03565
03566 void addDefn (PP_String& def,
03567 PP_List<PP_String>& val,
03568 PP_List<PP_entry*>& tab);
03569
03570
03571
03572 void read_file (const char* fname,
03573 PP_List<PP_entry*>& tab);
03574
03575
03576
03577 PPType getToken (const char*,
03578 int&,
03579 int,
03580 char*);
03581
03582
03583
03584 void rmTable ();
03585
03586
03587
03588 PP_String thePrefix;
03589
03590
03591
03592 void ppinit (const char* parfile);
03593
03594
03595
03596 const PP_entry* ppindex (int n,
03597 const char* name) const;
03598
03599
03600
03601
03602
03603
03604
03605
03606 void getval (const char* name,
03607 const PPType type,
03608 void* ptr,
03609 int ival,
03610 int k=-1);
03611
03612
03613
03614 void getarr (const char* name,
03615 const PPType type,
03616 void* ptr,
03617 int start_ix,
03618 int num_val,
03619 int k=-1);
03620 int queryval (const char* name,
03621 const PPType type,
03622 void* ptr,
03623 int ival,
03624 int k=-1);
03625 int queryarr (const char* name,
03626 const PPType type,
03627 void* ptr,
03628 int start_ix,
03629 int num_val,
03630 int k=-1);
03631
03632 bool isInteger (const PP_String& str, int& val);
03633 bool isUnsigned(const PP_String& str, unsigned long& val);
03634 int isDouble (const PP_String& str, double& val);
03635 bool isBool (const PP_String& str, bool& val);
03636
03637 #endif
03638
03639 };
03640
03641 #ifndef DOXYGEN
03642 class PP_entry
03643 {
03644 private:
03645 friend class ParmParse;
03646 PP_entry()
03647 {}
03648
03649 PP_entry (PP_String& name,
03650 ParmParse::PPType typ,
03651 PP_List<PP_String>& vals);
03652
03653 ~PP_entry()
03654 {}
03655
03656 PP_String defname;
03657 ParmParse::PPType deftype;
03658 PP_Array<PP_String> val;
03659
03660 void dump (std::ostream& os) const;
03661 };
03662 #endif //doxygen
03663
03664
03665
03666
03667
03668 inline
03669 int
03670 ParmParse::countval (const char* name,
03671 int n)
03672 {
03673
03674
03675
03676 const PP_entry* def = ppindex(n,name);
03677 return def == 0 ? 0 : def->val.length();
03678 }
03679
03680 inline
03681 void
03682 ParmParse::get (const char* name,
03683 int& ptr,
03684 int ival)
03685 {
03686 getval(name,ppInt,&ptr,ival,-1);
03687 }
03688
03689 inline
03690 int
03691 ParmParse::query (const char* name,
03692 int& ptr,
03693 int ival)
03694 {
03695 return queryval(name,ppInt,&ptr,ival,-1);
03696 }
03697
03698 inline
03699 void
03700 ParmParse::get (const char* name,
03701 unsigned long& ptr,
03702 int ival)
03703 {
03704 getval(name,ppUnsignedLong,&ptr,ival,-1);
03705 }
03706
03707 inline
03708 int
03709 ParmParse::query (const char* name,
03710 unsigned long& ptr,
03711 int ival)
03712 {
03713 return queryval(name,ppUnsignedLong,&ptr,ival,-1);
03714 }
03715
03716 inline
03717 void
03718 ParmParse::get (const char* name,
03719 float& ptr,
03720 int ival)
03721 {
03722 getval(name,ppFloat,&ptr,ival,-1);
03723 }
03724
03725 inline
03726 int
03727 ParmParse::query (const char* name,
03728 float& ptr,
03729 int ival)
03730 {
03731 return queryval(name,ppFloat,&ptr,ival,-1);
03732 }
03733
03734 inline
03735 void
03736 ParmParse::get (const char* name,
03737 double& ptr,
03738 int ival)
03739 {
03740 getval(name,ppDouble,&ptr,ival,-1);
03741 }
03742
03743 inline
03744 int
03745 ParmParse::query (const char* name,
03746 double& ptr,
03747 int ival)
03748 {
03749 return queryval(name,ppDouble,&ptr,ival,-1);
03750 }
03751
03752 inline
03753 void
03754 ParmParse::get (const char* name,
03755 std::string& ptr,
03756 int ival)
03757 {
03758 PP_String pp_string;
03759 getval(name,ppString,&pp_string,ival,-1);
03760 ptr = pp_string.c_str();
03761 }
03762
03763 inline
03764 int
03765 ParmParse::query (const char* name,
03766 std::string& ptr,
03767 int ival)
03768 {
03769 PP_String pp_string;
03770 int status = queryval(name,ppString,&pp_string,ival,-1);
03771 if (status != 0)
03772 ptr = pp_string.c_str();
03773 return status;
03774 }
03775
03776 inline
03777 void
03778 ParmParse::get(const char* name,
03779 bool& ptr,
03780 int ival)
03781 {
03782 getval(name,ppBool,&ptr,ival,-1);
03783 }
03784
03785 inline
03786 int
03787 ParmParse::query (const char* name,
03788 bool& ptr,
03789 int ival)
03790 {
03791 return queryval(name,ppBool,&ptr,ival,-1);
03792 }
03793
03794 inline
03795 void
03796 ParmParse::getarr (const char* name,
03797 std::vector<int>& ptr,
03798 int start_ix,
03799 int num_val)
03800 {
03801 if (ptr.size() < num_val)
03802 ptr.resize(num_val);
03803 int* c_array = new int[num_val];
03804 getarr(name,ppInt,c_array,start_ix,num_val,-1);
03805 for (int i = 0; i < num_val; ++i)
03806 {
03807 ptr[i] = c_array[i];
03808 }
03809 delete[] c_array;
03810 }
03811
03812 inline
03813 void
03814 ParmParse::getarr (const char* name,
03815 Vector<int>& ptr,
03816 int start_ix,
03817 int num_val)
03818 {
03819 if (ptr.size() < num_val)
03820 ptr.resize(num_val);
03821 int* c_array = new int[num_val];
03822 getarr(name,ppInt,c_array,start_ix,num_val,-1);
03823 for (int i = 0; i < num_val; ++i)
03824 {
03825 ptr[i] = c_array[i];
03826 }
03827 delete[] c_array;
03828 }
03829
03830 inline
03831 int
03832 ParmParse::queryarr (const char* name,
03833 std::vector<int>& ptr,
03834 int start_ix,
03835 int num_val)
03836 {
03837 if (ptr.size() < num_val)
03838 ptr.resize(num_val);
03839 int* c_array = new int[num_val];
03840 int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03841 if (status != 0 )
03842 {
03843 for (int i = 0; i < num_val; ++i)
03844 {
03845 ptr[i] = c_array[i];
03846 }
03847 }
03848 delete [] c_array;
03849 return status;
03850 }
03851
03852 inline
03853 int
03854 ParmParse::queryarr (const char* name,
03855 Vector<int>& ptr,
03856 int start_ix,
03857 int num_val)
03858 {
03859 if (ptr.size() < num_val)
03860 ptr.resize(num_val);
03861 int* c_array = new int[num_val];
03862 int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03863 if (status != 0 )
03864 {
03865 for (int i = 0; i < num_val; ++i)
03866 {
03867 ptr[i] = c_array[i];
03868 }
03869 }
03870 return status;
03871 }
03872
03873 inline
03874 void
03875 ParmParse::getarr (const char* name,
03876 std::vector<float>& ptr,
03877 int start_ix,
03878 int num_val)
03879 {
03880 if (ptr.size() < num_val)
03881 ptr.resize(num_val);
03882 float* c_array = new float[num_val];
03883 getarr(name,ppFloat,c_array,start_ix,num_val,-1);
03884 for (int i = 0; i < num_val; ++i)
03885 {
03886 ptr[i] = c_array[i];
03887 }
03888 delete[] c_array;
03889 }
03890
03891 inline
03892 void
03893 ParmParse::getarr (const char* name,
03894 Vector<float>& ptr,
03895 int start_ix,
03896 int num_val)
03897 {
03898 if (ptr.size() < num_val)
03899 ptr.resize(num_val);
03900 float* c_array = new float[num_val];
03901 getarr(name,ppFloat,c_array,start_ix,num_val,-1);
03902 for (int i = 0; i < num_val; ++i)
03903 {
03904 ptr[i] = c_array[i];
03905 }
03906 delete[] c_array;
03907 }
03908
03909 inline
03910 int
03911 ParmParse::queryarr (const char* name,
03912 std::vector<float>& ptr,
03913 int start_ix,
03914 int num_val)
03915 {
03916 if (ptr.size() < num_val)
03917 ptr.resize(num_val);
03918 float* c_array = new float[num_val];
03919 int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03920 if (status != 0)
03921 {
03922 for (int i = 0; i < num_val; ++i)
03923 {
03924 ptr[i] = c_array[i];
03925 }
03926 }
03927 delete[] c_array;
03928 return status;
03929 }
03930
03931 inline
03932 int
03933 ParmParse::queryarr (const char* name,
03934 Vector<float>& ptr,
03935 int start_ix,
03936 int num_val)
03937 {
03938 if (ptr.size() < num_val)
03939 ptr.resize(num_val);
03940 float* c_array = new float[num_val];
03941 int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03942 if (status != 0)
03943 {
03944 for (int i = 0; i < num_val; ++i)
03945 {
03946 ptr[i] = c_array[i];
03947 }
03948 }
03949 delete[] c_array;
03950 return status;
03951 }
03952
03953 inline
03954 void
03955 ParmParse::getarr (const char* name,
03956 std::vector<double>& ptr,
03957 int start_ix,
03958 int num_val)
03959 {
03960 if (ptr.size() < num_val)
03961 ptr.resize(num_val);
03962 double* c_array = new double[num_val];
03963 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03964 if (status == 0)
03965 {
03966 cerr << "ParmParse::getarr(): "
03967 << name
03968 << " not found in table" << endl;
03969 dumpTable(cerr);
03970 MayDay::Abort();
03971 }
03972 for (int i = 0; i < num_val; ++i)
03973 {
03974 ptr[i] = c_array[i];
03975 }
03976 delete[] c_array;
03977 }
03978
03979 inline
03980 void
03981 ParmParse::getarr (const char* name,
03982 Vector<double>& ptr,
03983 int start_ix,
03984 int num_val)
03985 {
03986 if (ptr.size() < num_val)
03987 ptr.resize(num_val);
03988 double* c_array = new double[num_val];
03989 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03990 if (status == 0)
03991 {
03992 cerr << "ParmParse::getarr(): "
03993 << name
03994 << " not found in table" << endl;
03995 dumpTable(cerr);
03996 MayDay::Abort();
03997 }
03998 for (int i = 0; i < num_val; ++i)
03999 {
04000 ptr[i] = c_array[i];
04001 }
04002 delete[] c_array;
04003 }
04004
04005 inline
04006 int
04007 ParmParse::queryarr (const char* name,
04008 std::vector<double>& ptr,
04009 int start_ix,
04010 int num_val)
04011 {
04012 if (ptr.size() < num_val)
04013 ptr.resize(num_val);
04014 double* c_array = new double[num_val];
04015 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04016 if (status != 0)
04017 {
04018 for (int i = 0; i < num_val; ++i)
04019 {
04020 ptr[i] = c_array[i];
04021 }
04022 }
04023 delete[] c_array;
04024 return status;
04025 }
04026
04027 inline
04028 int
04029 ParmParse::queryarr (const char* name,
04030 Vector<double>& ptr,
04031 int start_ix,
04032 int num_val)
04033 {
04034 if (ptr.size() < num_val)
04035 ptr.resize(num_val);
04036 double* c_array = new double[num_val];
04037 int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
04038 if (status != 0)
04039 {
04040 for (int i = 0; i < num_val; ++i)
04041 {
04042 ptr[i] = c_array[i];
04043 }
04044 }
04045 delete[] c_array;
04046 return status;
04047 }
04048
04049 inline
04050 void
04051 ParmParse::getarr (const char* name,
04052 std::vector<std::string>& ptr,
04053 int start_ix,
04054 int num_val)
04055 {
04056 if (ptr.size() < num_val)
04057 ptr.resize(num_val);
04058 PP_String* c_array = new PP_String[num_val];
04059 getarr(name,ppString,c_array,start_ix,num_val,-1);
04060 for (int i = 0; i < num_val; ++i)
04061 {
04062 ptr[i] = c_array[i].c_str();
04063 }
04064 delete[] c_array;
04065 }
04066
04067 inline
04068 void
04069 ParmParse::getarr (const char* name,
04070 Vector<std::string>& ptr,
04071 int start_ix,
04072 int num_val)
04073 {
04074 if (ptr.size() < num_val)
04075 ptr.resize(num_val);
04076 PP_String* c_array = new PP_String[num_val];
04077 getarr(name,ppString,c_array,start_ix,num_val,-1);
04078 for (int i = 0; i < num_val; ++i)
04079 {
04080 ptr[i] = c_array[i].c_str();
04081 }
04082 delete[] c_array;
04083 }
04084
04085 inline
04086 int
04087 ParmParse::queryarr (const char* name,
04088 std::vector<std::string>& ptr,
04089 int start_ix,
04090 int num_val)
04091 {
04092 if (ptr.size() < num_val)
04093 ptr.resize(num_val);
04094 PP_String* c_array = new PP_String[num_val];
04095 int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
04096 if (status != 0)
04097 {
04098 for (int i = 0; i < num_val; ++i)
04099 {
04100 ptr[i] = c_array[i].c_str();
04101 }
04102 }
04103 delete[] c_array;
04104 return status;
04105 }
04106
04107 inline
04108 int
04109 ParmParse::queryarr (const char* name,
04110 Vector<std::string>& ptr,
04111 int start_ix,
04112 int num_val)
04113 {
04114 if (ptr.size() < num_val)
04115 ptr.resize(num_val);
04116 PP_String* c_array = new PP_String[num_val];
04117 int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
04118 if (status != 0)
04119 {
04120 for (int i = 0; i < num_val; ++i)
04121 {
04122 ptr[i] = c_array[i].c_str();
04123 }
04124 }
04125 delete[] c_array;
04126 return status;
04127 }
04128
04129
04130 inline
04131 void
04132 ParmParse::getarr (const char* name,
04133 std::vector<bool>& ptr,
04134 int start_ix,
04135 int num_val)
04136 {
04137 if (ptr.size() < num_val)
04138 ptr.resize(num_val);
04139 bool* c_array = new bool[num_val];
04140 getarr(name,ppBool,c_array,start_ix,num_val,-1);
04141 for (int i = 0; i < num_val; ++i)
04142 {
04143 ptr[i] = c_array[i];
04144 }
04145 delete[] c_array;
04146 }
04147
04148 inline
04149 int
04150 ParmParse::queryarr (const char* name,
04151 std::vector<bool>& ptr,
04152 int start_ix,
04153 int num_val)
04154 {
04155 if (ptr.size() < num_val)
04156 ptr.resize(num_val);
04157 bool* c_array = new bool[num_val];
04158 int status = queryarr(name,ppBool,c_array,start_ix,num_val,-1);
04159 if (status != 0 )
04160 {
04161 for (int i = 0; i < num_val; ++i)
04162 {
04163 ptr[i] = c_array[i];
04164 }
04165 }
04166 delete [] c_array;
04167 return status;
04168 }
04169
04170
04171
04172 inline
04173 bool
04174 ParmParse::isInteger (const PP_String& str,
04175 int& val)
04176 {
04177
04178
04179
04180 char* endp = 0;
04181 val = (int) strtol(str.c_str(), &endp, 10);
04182 return *endp == 0;
04183 }
04184
04185 inline
04186 bool
04187 ParmParse::isUnsigned (const PP_String& str,
04188 unsigned long & val)
04189 {
04190 char* endp = 0;
04191 val = strtoul(str.c_str(), &endp, 10);
04192 return *endp == 0;
04193 }
04194
04195 inline
04196 int
04197 ParmParse::isDouble (const PP_String& str,
04198 double& val)
04199 {
04200 char* endp = 0;
04201 val = std::strtod(str.c_str(), &endp);
04202 return *endp == 0;
04203 }
04204
04205 inline
04206 bool
04207 ParmParse::isBool (const PP_String& str,
04208 bool& val)
04209 {
04210 PP_String str_lc( str );
04211 str_lc.toLower();
04212 if( str_lc == "true" || str_lc == "1" ){
04213 return val = true ;
04214 }else if( str_lc == "false" || str_lc == "0" ){
04215 val = false ;
04216 return true ;
04217 }else{
04218 return false ;
04219 }
04220 }
04221
04222 inline
04223 int
04224 ParmParse::countname (const std::string& name)
04225 {
04226 return countname(name.c_str());
04227 }
04228
04229 #include "BaseNamespaceFooter.H"
04230 #endif