Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

ParmParse.H

Go to the documentation of this file.
00001 /* _______              __
00002    / ___/ /  ___  __ _  / /  ___
00003    / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004    \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 /*
00029   DISCLAIMER:
00030   This is ugly because it consists of four files from boxlib
00031   concatenated together and munged hopelessly.  This was done
00032   (1) to greatly reduce the size of the API of boxlib
00033   (2) to avoid the godawful task of rewriting parmparse
00034   (3) to avoid cluttering the global namespace
00035   We deeply apologize.
00036 
00037   Any class that begins with PP_ is a convenience
00038   and will not be in any way supported by anyone at ANAG.
00039 */
00040 
00041 #ifndef CH_PARMPARSE_H
00042 #define CH_PARMPARSE_H
00043 
00044 #include <iostream>
00045 #include <iomanip>
00046 #include <cstdlib>
00047 #include <string>
00048 #include <vector>
00049 
00050 #include <cassert>
00051 #include "MayDay.H"
00052 #include "Misc.H"
00053 #include "Vector.H"
00054 using std::cout;
00055 using std::cerr;
00056 using std::endl;
00057 //#include <aString.H>
00058 
00059 //#include <Pointers.H>
00060 
00061 //#include <UseCount.H>
00062 
00063 
00064 //
00065 //@Man:
00066 //@Memo: A Class Encapsulating Reference Counts for ParmParse
00067 /*@Doc:
00068 
00069 This class encapsulates reference counts.  
00070 
00071 This is a convenience class for ParmParse
00072 and will not be in any way supported by anyone at ANAG.
00073 */
00074 #ifndef DOXYGEN
00075 class PP_UseCount
00076 {
00077 public:
00078   //
00080   //
00081   PP_UseCount ();
00082   //
00084   //
00085   PP_UseCount (const PP_UseCount& rhs);
00086 
00091   PP_UseCount& operator= (const PP_UseCount& rhs);
00092   //
00094   //
00095   ~PP_UseCount ();
00096   //
00098   //
00099   bool unique () const;
00100   //
00102   //
00103   int linkCount () const;
00104 
00105 private:
00106   //
00107   // A pointer to the reference count.
00108   //
00109   unsigned int* cnt;
00110   //
00111   // Decrement the reference count and delete the reference
00112   // counter if there are no more references.
00113   //
00114   void decrement ();
00115 };
00116 
00117 //
00118 // Inlines.
00119 //
00120 
00121 inline
00122 PP_UseCount::PP_UseCount ()
00123   :
00124   cnt(new unsigned int(1))
00125 {}
00126 
00127 inline
00128 PP_UseCount::PP_UseCount (const PP_UseCount& rhs)
00129   :
00130   cnt(rhs.cnt)
00131 {
00132   ++*cnt;
00133 }
00134 
00135 inline
00136 bool
00137 PP_UseCount::unique () const
00138 {
00139   return *cnt == 1;
00140 }
00141 
00142 inline
00143 void
00144 PP_UseCount::decrement ()
00145 {
00146   if (unique())
00147     {
00148       delete cnt;
00149       cnt = 0;
00150     }
00151   else
00152     --*cnt;
00153 }
00154 
00155 inline
00156 PP_UseCount&
00157 PP_UseCount::operator= (const PP_UseCount& rhs)
00158 {
00159   ++*rhs.cnt;
00160   decrement();
00161   cnt = rhs.cnt;
00162   return *this;
00163 }
00164 
00165 inline
00166 PP_UseCount::~PP_UseCount ()
00167 {
00168   decrement();
00169 }
00170 
00171 inline
00172 int
00173 PP_UseCount::linkCount () const
00174 {
00175   return *cnt;
00176 }
00177 
00178 
00179 
00181 
00198 template <class T>
00199 class PP_CpPtr
00200 {
00201 public:
00202   //
00204   //
00205   PP_CpPtr ();
00206   //
00208   //
00209   /*explicit*/ PP_CpPtr (T* rhs);
00210   //
00212   //
00213   ~PP_CpPtr ();
00214 
00223   PP_CpPtr (const PP_CpPtr<T>& rhs);
00224 
00228   PP_CpPtr<T>& operator= (T* rhs);
00229 
00238   PP_CpPtr<T>& operator= (const PP_CpPtr<T>& rhs);
00239 
00245   T& operator* () const;
00246   //
00248   //
00249   bool isNull () const;
00250   //
00252   //
00253   T* release ();
00254   //
00256   //
00257   bool operator== (const PP_CpPtr<T>& rhs) const;
00258   //
00260   //
00261   bool operator!= (const PP_CpPtr<T>& rhs) const;
00262 
00263 protected:
00264   T* ptr;
00265 };
00266 
00268 
00281 template<class T>
00282 class PP_CpClassPtr :
00283   public PP_CpPtr<T>
00284 {
00285 public:
00286   //
00288   //
00289   PP_CpClassPtr ();
00290   //
00292   //
00293   /*explicit*/ PP_CpClassPtr (T* rhs);
00294 
00303   PP_CpClassPtr (const PP_CpClassPtr<T>& rhs);
00304 
00308   PP_CpClassPtr<T>& operator= (T* rhs);
00309 
00318   PP_CpClassPtr<T>& operator= (const PP_CpClassPtr<T>& rhs);
00319   //
00321   //
00322   T* operator-> () const;
00323 };
00324 
00325 
00327 
00341 template<class T>
00342 class PP_LnPtr
00343 {
00344 public:
00345   //
00347   //
00348   PP_LnPtr ();
00349   //
00351   //
00352   /*explicit*/ PP_LnPtr (T* rhs);
00353 
00359   PP_LnPtr<T>& operator= (const PP_LnPtr<T>& rhs);
00360 
00365   PP_LnPtr<T>& operator= (T* rhs)
00366   {
00367     //
00368     // This is inlined here as OCC won't have it any other way :-(
00369     //
00370     if (unique())
00371       delete ptr;
00372     ptr = rhs;
00373     ucnt = PP_UseCount();
00374     return *this;
00375   }
00376 
00380   ~PP_LnPtr ();
00381   //
00383   //
00384   bool unique () const;
00385   //
00387   //
00388   int linkCount () const;
00389 
00395   T& operator* () const;
00396   //
00398   //
00399   bool isNull () const;
00400   //
00402   //
00403   bool operator== (const PP_LnPtr<T>& rhs) const;
00404   //
00406   //
00407   bool operator!= (const PP_LnPtr<T>& rhs) const;
00408 
00409 protected:
00410   T*       ptr;
00411 
00412 private:
00413   PP_UseCount ucnt;
00414 };
00415 
00416 
00418 
00430 template<class T>
00431 class PP_LnClassPtr
00432   : public PP_LnPtr<T>
00433 {
00434 public:
00435   //
00437   //
00438   PP_LnClassPtr ();
00439   //
00441   //
00442   /*explicit*/ PP_LnClassPtr (T* rhs);
00443 
00449   PP_LnClassPtr<T>& operator= (const PP_LnClassPtr<T>& rhs);
00450 
00455   PP_LnClassPtr<T>& operator= (T* rhs);
00456   //
00458   //
00459   T* operator->() const;
00460 };
00461 
00462 //
00463 // Inlines.
00464 //
00465 
00466 template <class T>
00467 inline
00468 PP_CpPtr<T>::PP_CpPtr ()
00469   : ptr(0)
00470 {}
00471 
00472 template <class T>
00473 inline
00474 PP_CpPtr<T>::PP_CpPtr(T* rhs)
00475   : ptr(rhs)
00476 {}
00477 
00478 template <class T>
00479 inline
00480 PP_CpPtr<T>::~PP_CpPtr()
00481 {
00482   delete ptr;
00483 }
00484 
00485 template <class T>
00486 inline
00487 bool
00488 PP_CpPtr<T>::isNull () const
00489 {
00490   return ptr == 0;
00491 }
00492 
00493 template <class T>
00494 inline
00495 PP_CpPtr<T>::PP_CpPtr (const PP_CpPtr<T>& rhs)
00496 {
00497   ptr = rhs.isNull() ?  0 : new T(*rhs.ptr);
00498 }
00499 
00500 template <class T>
00501 inline
00502 PP_CpPtr<T>&
00503 PP_CpPtr<T>::operator= (const PP_CpPtr<T>& rhs)
00504 {
00505   if (!(ptr == rhs.ptr))
00506     {
00507       delete ptr;
00508       ptr = rhs.isNull() ? 0 : new T(*rhs.ptr);
00509     }
00510   return *this;
00511 }
00512 
00513 template <class T>
00514 inline
00515 PP_CpPtr<T>&
00516 PP_CpPtr<T>::operator= (T* rhs)
00517 {
00518   delete ptr;
00519   ptr = rhs;
00520   return *this;
00521 }
00522 
00523 template <class T>
00524 inline
00525 T&
00526 PP_CpPtr<T>::operator* () const
00527 {
00528   assert(ptr != 0);
00529   return *ptr;
00530 }
00531 
00532 template <class T>
00533 inline
00534 T*
00535 PP_CpPtr<T>::release ()
00536 {
00537   T* old = ptr;
00538   ptr = 0;
00539   return old;
00540 }
00541 
00542 template <class T>
00543 inline
00544 bool
00545 PP_CpPtr<T>::operator== (const PP_CpPtr<T>& rhs) const
00546 {
00547   return ptr == rhs.ptr;
00548 }
00549 
00550 template <class T>
00551 inline
00552 bool
00553 PP_CpPtr<T>::operator!= (const PP_CpPtr<T>& rhs) const
00554 {
00555   return ptr != rhs.ptr;
00556 }
00557 
00558 template <class T>
00559 inline
00560 PP_CpClassPtr<T>::PP_CpClassPtr ()
00561   : PP_CpPtr<T>()
00562 {}
00563 
00564 template <class T>
00565 inline
00566 PP_CpClassPtr<T>::PP_CpClassPtr (T* rhs)
00567   : PP_CpPtr<T>(rhs)
00568 {}
00569 
00570 template <class T>
00571 inline
00572 PP_CpClassPtr<T>::PP_CpClassPtr (const PP_CpClassPtr<T>& rhs)
00573   : PP_CpPtr<T>(rhs) {}
00574 
00575 template <class T>
00576 inline
00577 PP_CpClassPtr<T>&
00578 PP_CpClassPtr<T>::operator= (T* rhs)
00579 {
00580   PP_CpPtr<T>::operator= (rhs);
00581   return *this;
00582 }
00583 
00584 template <class T>
00585 inline
00586 PP_CpClassPtr<T>&
00587 PP_CpClassPtr<T>::operator= (const PP_CpClassPtr<T>& rhs)
00588 {
00589   PP_CpPtr<T>::operator= (rhs);
00590   return *this;
00591 }
00592 
00593 template <class T>
00594 inline
00595 T*
00596 PP_CpClassPtr<T>::operator-> () const
00597 {
00598   return this->ptr;
00599 }
00600 
00601 template <class T>
00602 inline
00603 PP_LnPtr<T>::PP_LnPtr ()
00604   : ptr(0)
00605 {}
00606 
00607 template <class T>
00608 inline
00609 PP_LnPtr<T>::PP_LnPtr(T* rhs)
00610   : ptr(rhs)
00611 {}
00612 
00613 template <class T>
00614 inline
00615 bool
00616 PP_LnPtr<T>::unique () const
00617 { 
00618   return ucnt.unique();
00619 }
00620 
00621 template <class T>
00622 inline
00623 PP_LnPtr<T>::~PP_LnPtr ()
00624 { 
00625   if (ucnt.unique())
00626     delete ptr;
00627 }
00628 
00629 template <class T>
00630 inline
00631 PP_LnPtr<T>&
00632 PP_LnPtr<T>::operator= (const PP_LnPtr<T>& rhs)
00633 {
00634   if (ptr != rhs.ptr)
00635     {
00636       if (unique())
00637         delete ptr;
00638       ptr = rhs.ptr;
00639       ucnt = rhs.ucnt;
00640     }
00641   return *this;
00642 }
00643 
00644 template <class T>
00645 inline
00646 int
00647 PP_LnPtr<T>::linkCount () const
00648 { 
00649   return ucnt.linkCount();
00650 }
00651 
00652 template <class T>
00653 inline
00654 T&
00655 PP_LnPtr<T>::operator* () const
00656 {
00657   assert(ptr != 0);
00658   return *ptr;
00659 }
00660 
00661 template <class T>
00662 inline
00663 bool
00664 PP_LnPtr<T>::isNull () const
00665 {
00666   return ptr == 0;
00667 }
00668 
00669 template <class T>
00670 inline
00671 bool
00672 PP_LnPtr<T>::operator== (const PP_LnPtr<T>& rhs) const
00673 {
00674   return ptr == rhs.ptr;
00675 }
00676 
00677 template <class T>
00678 inline
00679 bool
00680 PP_LnPtr<T>::operator!= (const PP_LnPtr<T>& rhs) const
00681 {
00682   return ptr != rhs.ptr;
00683 }
00684 
00685 template <class T>
00686 inline
00687 PP_LnClassPtr<T>::PP_LnClassPtr ()
00688 {}
00689 
00690 template <class T>
00691 inline
00692 PP_LnClassPtr<T>::PP_LnClassPtr (T* rhs)
00693   : PP_LnPtr<T>(rhs)
00694 {}
00695 
00696 template <class T>
00697 inline
00698 PP_LnClassPtr<T>&
00699 PP_LnClassPtr<T>::operator= (const PP_LnClassPtr<T>& rhs)
00700 {
00701   PP_LnPtr<T>::operator=(rhs);
00702   return *this;
00703 }
00704 
00705 template <class T>
00706 inline
00707 PP_LnClassPtr<T>&
00708 PP_LnClassPtr<T>::operator= (T* rhs)
00709 {
00710   PP_LnPtr<T>::operator=(rhs);
00711   return *this;
00712 }
00713 
00714 template <class T>
00715 inline
00716 T*
00717 PP_LnClassPtr<T>::operator->() const
00718 {
00719   return this->ptr;
00720 }
00721 
00722 
00723 
00724 //
00725 // Helper class for class PP_String.
00726 //
00727 
00728 class PP_StringRep
00729 {
00730   friend class PP_String;
00731   char* s;
00732   int   bufferlength;
00733 public:
00734   /*explicit*/ PP_StringRep (int _len = 0);
00735   ~PP_StringRep ();
00736   //
00737   // Resized the buffer and copies the contents of old buffer to new one.
00738   //
00739   void resize (int n);
00740 };
00741 
00742 //
00743 // PP_StringRep inlines.
00744 //
00745 
00746 inline
00747 PP_StringRep::PP_StringRep (int _len)
00748 {
00749   bufferlength = _len;
00750   s = new char [bufferlength];
00751 }
00752 
00753 inline
00754 PP_StringRep::~PP_StringRep ()
00755 {
00756   delete [] s;
00757   s = 0;
00758 }
00759 
00761 
00785 class PP_String
00786 {
00787 public:
00788   //
00790   //
00791   PP_String ();
00792 
00796   /*explicit*/ PP_String (char c);
00797 
00806   /*explicit*/ PP_String (int len);
00807 
00811   PP_String (const char* s);
00812   //
00814   //
00815   PP_String (const PP_String& rhs);
00816   //
00818   //
00819   PP_String& operator= (const PP_String& rhs);
00820 
00824   PP_String& operator+= (const PP_String& right);
00825 
00830   PP_String& operator+= (const char* right);
00831 
00836   PP_String& operator+= (char c);
00837 
00841   PP_String& toUpper ();
00842 
00846   PP_String& toLower ();
00847 
00854   std::istream& getline (std::istream& strm);
00855 
00859   int length () const;
00860 
00861   //
00863   //
00864   bool isNull () const;
00865 
00869   char& operator [] (int k);
00870 
00874   char operator[] (int k) const;
00875 
00879   const char* c_str () const;
00880 
00886   double toDouble () const;
00887 
00893   int toInteger () const;
00894 
00900   long toLong () const;
00901   //
00903   //
00904   friend std::ostream& operator<< (std::ostream&       os,
00905                                    const PP_String& str);
00906 
00919   friend std::istream& operator>> (std::istream& is,
00920                                    PP_String& str);
00921 
00922 protected:
00923   void copyModify ();
00924 
00925 private:
00926   PP_LnClassPtr<PP_StringRep> p;
00927   int                   len;
00928 
00929   //
00930   // None of the following functions need to be friends.  I've made
00931   // them friends solely so they'll show up nicely in the HTML documentaion
00932   // spewed out by doc++.
00933   //
00934 
00935   //
00936   // Is left lexically less than right?
00937   //
00938   friend inline bool operator<  (const PP_String& left,
00939                                  const PP_String& right);
00940   //
00941   // Is left lexically less than or equal to right?
00942   //
00943   friend inline bool operator<= (const PP_String& left,
00944                                  const PP_String& right);
00945   //
00946   // Is left not equal to right?
00947   //
00948   friend inline bool operator!= (const PP_String& left,
00949                                  const PP_String& right);
00950   //
00951   // Is left equal to right?
00952   //
00953   friend inline bool operator== (const PP_String& left,
00954                                  const PP_String& right);
00955   //
00956   // Is left lexically greater than or equal to right?
00957   //
00958   friend inline bool operator>= (const PP_String& left,
00959                                  const PP_String& right);
00960   //
00961   // Is left lexically greater than right?
00962   //
00963   friend inline bool operator>  (const PP_String& left,
00964                                  const PP_String& right);
00965   //
00966   // Is left lexically less than right?
00967   //
00968   friend inline bool operator<  (const PP_String& left,
00969                                  const char*    right);
00970   //
00971   // Is left lexically less than or equal to right?
00972   //
00973   friend inline bool operator<= (const PP_String& left,
00974                                  const char*    right);
00975   //
00976   // Is left not equal to right?
00977   //
00978   friend inline bool operator!= (const PP_String& left,
00979                                  const char*    right);
00980   //
00981   // Is left equal to right?
00982   //
00983   friend inline bool operator== (const PP_String& left,
00984                                  const char*    right);
00985   //
00986   // Is left lexically greater than or equal to right?
00987   //
00988   friend inline bool operator>= (const PP_String& left,
00989                                  const char*    right);
00990   //
00991   // Is left lexically greater than right?
00992   //
00993   friend inline bool operator>  (const PP_String& left,
00994                                  const char*    right);
00995   //
00996   // Is left lexically less than right?
00997   //
00998   friend inline bool operator<  (const char*    left,
00999                                  const PP_String& right);
01000   //
01001   // Is left lexically less than or equal to right?
01002   //
01003   friend inline bool operator<= (const char*    left,
01004                                  const PP_String& right);
01005   //
01006   // Is left not equal to right?
01007   //
01008   friend inline bool operator!= (const char*    left,
01009                                  const PP_String& right);
01010   //
01011   // Is left equal to right?
01012   //
01013   friend inline bool operator== (const char*    left,
01014                                  const PP_String& right);
01015   //
01016   // Is left lexically greater than or equal to right?
01017   //
01018   friend inline bool operator>= (const char*    left,
01019                                  const PP_String& right);
01020   //
01021   // Is left lexically greater than right?
01022   //
01023   friend inline bool operator>  (const char*    left,
01024                                  const PP_String& right);
01025 };
01026 
01027 //
01028 // PP_String inlines.
01029 //
01030 
01031 inline
01032 bool
01033 PP_String::isNull () const
01034 {
01035   return len == 0;
01036 }
01037 
01038 inline
01039 int
01040 PP_String::length () const
01041 {
01042   return len;
01043 }
01044 
01045 inline
01046 double
01047 PP_String::toDouble () const
01048 {
01049   return len == 0 ? 0 : std::atof(p->s);
01050 }
01051 
01052 inline
01053 int
01054 PP_String::toInteger () const
01055 {
01056   return len == 0 ? 0 : atoi(p->s);
01057 }
01058 
01059 inline
01060 long
01061 PP_String::toLong () const
01062 {
01063   return len == 0 ? 0 : atol(p->s);
01064 }
01065 
01066 inline
01067 const char*
01068 PP_String::c_str () const
01069 {
01070   return p->s;
01071 }
01072 
01073 inline
01074 char
01075 PP_String::operator[] (int index) const
01076 {
01077   assert(index >=0 && index < len);
01078   return p->s[index];
01079 }
01080 
01081 inline
01082 PP_String
01083 operator+ (const PP_String& left,
01084            const PP_String& right)
01085 {
01086   PP_String result(left);
01087   return result += right;
01088 }
01089 
01090 inline
01091 bool
01092 operator< (const PP_String& left,
01093            const PP_String& right)
01094 {
01095   return ::strcmp(left.c_str(), right.c_str()) < 0;
01096 }
01097 
01098 inline
01099 bool
01100 operator<= (const PP_String& left,
01101             const PP_String& right)
01102 {
01103   return ::strcmp(left.c_str(), right.c_str()) <= 0;
01104 }
01105 
01106 inline
01107 bool
01108 operator!= (const PP_String& left,
01109             const PP_String& right)
01110 {
01111   return ::strcmp(left.c_str(), right.c_str()) != 0;
01112 }
01113 
01114 inline
01115 bool
01116 operator== (const PP_String& left,
01117             const PP_String& right)
01118 {
01119   return ::strcmp(left.c_str(), right.c_str()) == 0;
01120 }
01121 
01122 inline
01123 bool
01124 operator>= (const PP_String& left,
01125             const PP_String& right)
01126 {
01127   return ::strcmp(left.c_str(), right.c_str()) >= 0;
01128 }
01129 
01130 inline
01131 bool
01132 operator>  (const PP_String& left,
01133             const PP_String& right)
01134 {
01135   return ::strcmp(left.c_str(), right.c_str()) > 0;
01136 }
01137 
01138 inline
01139 bool
01140 operator< (const PP_String& left,
01141            const char*    right)
01142 {
01143   return ::strcmp(left.c_str(), right) < 0;
01144 }
01145 
01146 inline
01147 bool
01148 operator<= (const PP_String& left,
01149             const char*    right)
01150 {
01151   return ::strcmp(left.c_str(), right) <= 0;
01152 }
01153 
01154 inline
01155 bool
01156 operator!= (const PP_String& left,
01157             const char*    right)
01158 {
01159   return ::strcmp(left.c_str(), right) != 0;
01160 }
01161 
01162 inline
01163 bool
01164 operator== (const PP_String& left,
01165             const char*    right)
01166 {
01167   return ::strcmp(left.c_str(), right) == 0;
01168 }
01169 
01170 inline
01171 bool
01172 operator>= (const PP_String& left,
01173             const char*    right)
01174 {
01175   return ::strcmp(left.c_str(), right) >= 0;
01176 }
01177 
01178 inline
01179 bool
01180 operator>  (const PP_String& left,
01181             const char*    right)
01182 {
01183   return ::strcmp(left.c_str(), right) > 0;
01184 }
01185 
01186 inline
01187 bool
01188 operator< (const char*    left,
01189            const PP_String& right)
01190 {
01191   return ::strcmp(left, right.c_str()) < 0;
01192 }
01193 
01194 inline
01195 bool
01196 operator<= (const char*    left,
01197             const PP_String& right)
01198 {
01199   return ::strcmp(left, right.c_str()) <= 0;
01200 }
01201 
01202 inline
01203 bool
01204 operator!= (const char*    left, 
01205             const PP_String& right)
01206 {
01207   return ::strcmp(left, right.c_str()) != 0;
01208 }
01209 
01210 inline
01211 bool
01212 operator== (const char*    left,
01213             const PP_String& right)
01214 {
01215   return ::strcmp(left, right.c_str()) == 0;
01216 }
01217 
01218 inline
01219 bool
01220 operator>= (const char*    left,
01221             const PP_String& right)
01222 {
01223   return ::strcmp(left, right.c_str()) >= 0;
01224 }
01225 
01226 inline
01227 bool
01228 operator>  (const char*    left,
01229             const PP_String& right)
01230 {
01231   return ::strcmp(left, right.c_str()) > 0;
01232 }
01233 
01234 
01235 //#include <List.H>
01236 
01237 template <class T> class PP_ListLink;
01238 template <class T> class PP_ListIterator;
01239 template <class T> class PP_List;
01240 
01241 template <class T>
01242 class PP_ListLink
01243 {
01244 private:
01245   friend class PP_List<T>;
01246   friend class PP_ListIterator<T>;
01247 
01248   PP_ListLink (const T&     _val,
01249                PP_ListLink<T>* _pre,
01250                PP_ListLink<T>* _suc)
01251     :
01252     val(_val),
01253     pre(_pre),
01254     suc(_suc) {}
01255 
01256 private:
01257   T            val;
01258   PP_ListLink<T>* pre;
01259   PP_ListLink<T>* suc;
01260 };
01261 
01263 
01275 template <class T>
01276 class PP_ListIterator
01277 {
01278 public:
01279   //
01281   //
01282   /*explicit*/ PP_ListIterator (const PP_List<T>& aList);
01283   //
01285   //
01286   PP_ListIterator (const PP_ListIterator<T>& rhs);
01287 
01291   void rewind ();
01292 
01296   const T& operator() () const;
01297 
01301   const T& operator* () const;
01302 
01309   operator void* ();
01310 
01314   bool operator! () const;
01315 
01319   const T& value () const;
01320 
01326   PP_ListIterator<T>& operator++ ();
01327 
01333   PP_ListIterator<T>& operator-- ();
01334 
01341   PP_ListIterator<T> operator-- (int);
01342 
01348   PP_ListIterator<T> operator++ (int);
01349 
01353   bool operator== (const PP_ListIterator<T>&) const;
01354   //
01356   //
01357   bool operator!= (const PP_ListIterator<T>&) const;
01358 
01359 protected:
01360   //
01361   // Construct a PP_ListIterator<T> to a PP_List<T> and object in that PP_List<T>.
01362   //
01363   PP_ListIterator (const PP_List<T>& _list,
01364                    PP_ListLink<T>*   _p);
01365   //
01366   // A reference to the PP_List<T> to which we point.
01367   //
01368   const PP_List<T>& list;
01369   //
01370   // A pointer to the element in the PP_List<T> to which we point.
01371   //
01372   PP_ListLink<T>* p;
01373 
01374 private:
01375   friend class PP_List<T>;
01376   //
01377   // These are disallowed.
01378   //
01379   PP_ListIterator ();
01380   PP_ListIterator<T>& operator= (const PP_ListIterator<T>&);
01381 };
01382 
01384 
01417 template <class T>
01418 class PP_List
01419 {
01420 public:
01421   //
01423   //
01424   PP_List ();
01425   //
01427   //
01428   PP_List (const PP_List<T>& rhs);
01429   //
01431   //
01432   PP_List<T>& operator= (const PP_List<T>& rhs);
01433   //
01435   //
01436   ~PP_List();
01437   //
01439   //
01440   void prepend (const T& value);
01441   //
01443   //
01444   void append (const T& value);
01445   //
01447   //
01448   void add (const T& value);
01449   //
01451   //
01452   void join (const PP_List<T>& src);
01453 
01460   void catenate (PP_List<T>& src);
01461   //
01463   //
01464   void clear ();
01465   //
01467   //
01468   T& firstElement () const;
01469   //
01471   //
01472   T& lastElement () const;
01473 
01478   bool includes (const T& value) const;
01479 
01485   bool operator== (const PP_List<T>& rhs) const;
01486   //
01488   //
01489   bool operator!= (const PP_List<T>& rhs) const;
01490   //
01492   //
01493   bool isEmpty () const;
01494   //
01496   //
01497   bool isNotEmpty () const;
01498   //
01500   //
01501   int length () const;
01502   //
01504   //
01505   void removeFirst ();
01506   //
01508   //
01509   void removeLast ();
01510   //
01512   //
01513   const T& operator[] (const PP_ListIterator<T>& li) const;
01514   //
01516   //
01517   T& operator[] (const PP_ListIterator<T>& li);
01518   //
01520   //
01521   void remove (const T& value);
01522 
01526   void remove (const PP_List<T>& lst);
01527   //
01529   //
01530   void remove (PP_ListIterator<T>& lit);
01531   //
01533   //
01534   void replace (PP_ListIterator<T>& li,
01535                 const T&         val);
01536 
01540   void addAfter (PP_ListIterator<T>& lit,
01541                  const T&         val);
01542 
01546   void addBefore (PP_ListIterator<T>& lit,
01547                   const T&         val);
01548   //
01550   //
01551   PP_ListIterator<T> first () const;
01552   //
01554   //
01555   PP_ListIterator<T> last () const;
01556 
01557 protected:
01558   //
01559   // A helper function for removing nodes.
01560   //
01561   void remove (PP_ListLink<T> *ln);
01562   //
01563   // A helper function for adding nodes.
01564   //
01565   PP_ListLink<T>* addBefore (PP_ListLink<T>* ln,
01566                              const T&     val);
01567   //
01568   // A helper function for adding nodes.
01569   //
01570   PP_ListLink<T>* addAfter (PP_ListLink<T>* ln,
01571                             const T&     val);
01572   //
01573   // The head of the list.
01574   //
01575   PP_ListLink<T>* head;
01576   //
01577   // The tail of the list.
01578   //
01579   PP_ListLink<T>* tail;
01580   //
01581   // Our good and trusted friend.
01582   //
01583   friend class PP_ListIterator<T>;
01584 };
01585 
01586 //
01587 // Inlines.
01588 //
01589 
01590 //
01591 // The ListIterator stuff.
01592 //
01593 
01594 template <class T>
01595 inline
01596 PP_ListIterator<T>::PP_ListIterator (const PP_List<T>& _list,
01597                                      PP_ListLink<T>*   _p)
01598   :
01599   list(_list),
01600   p(_p)
01601 {}
01602 
01603 template <class T>
01604 inline
01605 PP_ListIterator<T>::PP_ListIterator (const PP_List<T>& aList)
01606   :
01607   list(aList)
01608 {
01609   p = list.head;
01610 }
01611 
01612 template <class T>
01613 inline
01614 PP_ListIterator<T>::PP_ListIterator (const PP_ListIterator<T>& li)
01615   :
01616   list(li.list),
01617   p(li.p)
01618 {}
01619 
01620 template <class T>
01621 inline
01622 void
01623 PP_ListIterator<T>::rewind ()
01624 {
01625   p = list.head;
01626 }
01627 
01628 template <class T>
01629 inline
01630 const T&
01631 PP_ListIterator<T>::operator() () const
01632 {
01633   assert(p != 0);
01634   return p->val;
01635 }
01636 
01637 template <class T>
01638 inline
01639 const T&
01640 PP_ListIterator<T>::operator* () const
01641 {
01642   assert(p != 0);
01643   return p->val;
01644 }
01645 
01646 template <class T>
01647 inline
01648 PP_ListIterator<T>::operator void* ()
01649 {
01650   return p != 0 ? this : 0;
01651 }
01652 
01653 template <class T>
01654 inline
01655 bool
01656 PP_ListIterator<T>::operator! () const
01657 {
01658   return p == 0 ? true : false;
01659 }
01660 
01661 template <class T>
01662 inline
01663 const T&
01664 PP_ListIterator<T>::value () const
01665 {
01666   assert(p != 0);
01667   return p->val;
01668 }
01669 
01670 template <class T>
01671 inline
01672 PP_ListIterator<T>&
01673 PP_ListIterator<T>::operator++ ()
01674 {
01675   if (p)
01676     p = p->suc;
01677   return *this;
01678 }
01679 
01680 template <class T>
01681 inline
01682 PP_ListIterator<T>&
01683 PP_ListIterator<T>::operator-- ()
01684 {
01685   if (p)
01686     p = p->pre;
01687   return *this;
01688 }
01689 
01690 template <class T>
01691 inline
01692 PP_ListIterator<T>
01693 PP_ListIterator<T>::operator++ (int)
01694 {
01695   const PP_ListIterator<T> li = *this;
01696   ++(*this);
01697   return li;
01698 }
01699 
01700 template <class T>
01701 inline
01702 PP_ListIterator<T>
01703 PP_ListIterator<T>::operator-- (int)
01704 {
01705   const PP_ListIterator<T> li = *this;
01706   --(*this);
01707   return li;
01708 }
01709 
01710 template <class T>
01711 inline
01712 bool
01713 PP_ListIterator<T>::operator== (const PP_ListIterator<T>& _li) const
01714 {
01715   return (&list == &_li.list && p == _li.p) ? true : false;
01716 }
01717 
01718 template <class T>
01719 inline
01720 bool
01721 PP_ListIterator<T>::operator!= (const PP_ListIterator<T>& _li) const
01722 {
01723   return ! PP_ListIterator<T>::operator==(_li);
01724 }
01725 
01726 //
01727 // List stuff.
01728 //
01729 
01730 template <class T>
01731 inline
01732 PP_List<T>::PP_List ()
01733   :
01734   head(0),
01735   tail(0)
01736 {}
01737 
01738 template <class T>
01739 inline
01740 PP_List<T>::~PP_List ()
01741 {
01742   clear();
01743 }
01744 
01745 template <class T>
01746 inline
01747 void
01748 PP_List<T>::prepend (const T& value)
01749 {
01750   addBefore(head, value);
01751 }
01752 
01753 template <class T>
01754 inline
01755 void
01756 PP_List<T>::append (const T& value)
01757 {
01758   addAfter(tail, value);
01759 }
01760 
01761 template <class T>
01762 inline
01763 T&
01764 PP_List<T>::firstElement () const
01765 {
01766   assert(head != 0);
01767   return head->val;
01768 }
01769 
01770 template <class T>
01771 inline
01772 T&
01773 PP_List<T>::lastElement () const
01774 {
01775   assert(tail != 0);
01776   return tail->val;
01777 }
01778 
01779 template <class T>
01780 inline
01781 bool
01782 PP_List<T>::isEmpty () const
01783 {
01784   return head == 0 && tail == 0;
01785 }
01786 
01787 template <class T>
01788 inline
01789 bool
01790 PP_List<T>::isNotEmpty () const
01791 {
01792   return !isEmpty();
01793 }
01794 
01795 template <class T>
01796 inline
01797 void
01798 PP_List<T>::removeFirst ()
01799 {
01800   remove(head);
01801 }
01802 
01803 template <class T>
01804 inline
01805 void
01806 PP_List<T>::removeLast ()
01807 {
01808   remove(tail);
01809 }
01810 
01811 template <class T>
01812 inline
01813 const T&
01814 PP_List<T>::operator[] (const PP_ListIterator<T>& li) const
01815 {
01816   assert(li.p != 0);
01817   return li.p->val;
01818 }
01819 
01820 template <class T>
01821 inline
01822 T&
01823 PP_List<T>::operator[] (const PP_ListIterator<T>& li)
01824 {
01825   assert(li.p != 0);
01826   return li.p->val;
01827 }
01828 
01829 template <class T>
01830 inline
01831 void
01832 PP_List<T>::replace (PP_ListIterator<T>& li,
01833                      const T&         _val)
01834 {
01835   assert(li.p != 0);
01836   li.p->val = _val;
01837 }
01838 
01839 template <class T>
01840 inline
01841 void
01842 PP_List<T>::addAfter (PP_ListIterator<T>& lit,
01843                       const T&         val)
01844 {
01845   addAfter(lit.p, val);
01846 }
01847 
01848 template <class T>
01849 inline
01850 void
01851 PP_List<T>::addBefore (PP_ListIterator<T>& lit,
01852                        const T&         val)
01853 {
01854   addBefore(lit.p, val);
01855 }
01856 
01857 template <class T>
01858 inline
01859 PP_ListIterator<T>
01860 PP_List<T>::first () const
01861 {
01862   return PP_ListIterator<T>(*this,head);
01863 }
01864 
01865 template <class T>
01866 inline
01867 PP_ListIterator<T>
01868 PP_List<T>::last () const
01869 {
01870   return PP_ListIterator<T>(*this,tail);
01871 }
01872 
01873 //
01874 // List members
01875 //
01876 
01877 template <class T>
01878 inline
01879 PP_List<T>::PP_List (const PP_List<T>& source)
01880   :
01881   head(0),
01882   tail(0)
01883 {
01884   if (source.isEmpty())
01885     tail = head = 0;
01886   else
01887     for (PP_ListIterator<T> li(source); li; ++li)
01888       append(li());
01889 }
01890 
01891 //
01892 // This isn't inlined as it's declared virtual.
01893 //
01894 
01895 template <class T>
01896 inline void
01897 PP_List<T>::add (const T& value)
01898 {
01899   append(value);
01900 }
01901 
01902 template <class T>
01903 inline
01904 int
01905 PP_List<T>::length () const
01906 {
01907   int len = 0;
01908   for (PP_ListIterator<T> li(*this); li; ++li)
01909     len++;
01910   return len;
01911 }
01912 
01913 template <class T>
01914 inline
01915 PP_List<T>&
01916 PP_List<T>::operator= (const PP_List<T>& source)
01917 {
01918   if (!(this == &source))
01919     {
01920       clear();
01921       for (PP_ListIterator<T> li(source); li; ++li)
01922         append(li());
01923     }
01924   return *this;
01925 }
01926 
01927 template <class T>
01928 inline PP_ListLink<T> *
01929 PP_List<T>::addBefore (PP_ListLink<T>* ln,
01930                        const T&     val)
01931 {
01932   assert(ln != 0 || head == 0);
01933 
01934   PP_ListLink<T>* newlink;
01935 
01936   if (ln == head)
01937     {
01938       head = newlink = new PP_ListLink<T>(val, 0, head);
01939 
01940       if (tail == 0)
01941         tail = head;
01942       else
01943         head->suc->pre = newlink;
01944     }
01945   else
01946     {
01947       newlink = new PP_ListLink<T>(val, ln->pre, ln);
01948 
01949       ln->pre->suc = newlink;
01950       ln->pre = newlink;
01951     }
01952 
01953   return newlink;
01954 }
01955 
01956 template <class T>
01957 inline
01958 PP_ListLink<T>*
01959 PP_List<T>::addAfter (PP_ListLink<T>* ln,
01960                       const T&     val)
01961 {
01962   assert(ln != 0 || tail == 0);
01963 
01964   PP_ListLink<T>* newlink;
01965 
01966   // trying this here to satisfy icc -O2 (ndk)
01967   // this worked for me -- but since we aren't actively using icc, i'll
01968   // leave it commented.
01969   //newlink = new PP_ListLink<T>(val,tail,0);
01970   //delete newlink;
01971 
01972   if (ln == tail)
01973     {
01974       tail = newlink = new PP_ListLink<T>(val,tail,0);
01975 
01976       if (head == 0)
01977         head = tail;
01978       else
01979         tail->pre->suc = newlink;
01980     }
01981   else
01982     {
01983       newlink = new PP_ListLink<T>(val, ln, ln->suc);
01984 
01985       ln->suc->pre = newlink;
01986       ln->suc = newlink;
01987     }
01988 
01989   return newlink;
01990 }
01991 
01992 template <class T>
01993 inline void
01994 PP_List<T>::join (const PP_List<T>& list2)
01995 {
01996   for (PP_ListIterator<T> li2(list2); li2; ++li2)
01997     append(li2());
01998 }
01999 
02000 template <class T>
02001 inline void
02002 PP_List<T>::catenate (PP_List<T>& list2)
02003 {
02004   if (list2.isEmpty())
02005     //
02006     // Do nothing.
02007     //
02008     ;
02009   else if (isEmpty())
02010     {
02011       head = list2.head;
02012       tail = list2.tail;
02013       list2.head = 0;
02014       list2.tail = 0;
02015     }
02016   else
02017     {
02018       tail->suc = list2.head;
02019       list2.head->pre = tail;
02020       tail = list2.tail;
02021       list2.head = 0;
02022       list2.tail = 0;
02023     }
02024 }
02025 
02026 template <class T>
02027 inline void
02028 PP_List<T>::clear ()
02029 {
02030   PP_ListLink<T>* next = 0;
02031 
02032   for (PP_ListLink<T>* p = head; p != 0; p = next)
02033     {
02034       next = p->suc;
02035       p->suc = 0;
02036       delete p;
02037     }
02038   tail = head = 0;
02039 }
02040 
02041 template <class T>
02042 inline bool
02043 PP_List<T>::includes (const T& v) const
02044 {
02045   bool rc = false;
02046   for (PP_ListIterator<T> li(*this); li && !rc; ++li)
02047     if (v == li())
02048       rc = true;
02049   return rc;
02050 }
02051 
02052 template<class T>
02053 inline bool
02054 PP_List<T>::operator== (const PP_List<T>& rhs) const
02055 {
02056   if (length() == rhs.length())
02057     {
02058       for (PP_ListIterator<T> li(*this), ri(rhs); li; ++li, ++ri)
02059         if (li() != ri())
02060           return false;
02061       return true;
02062     }
02063 
02064   return false;
02065 }
02066 
02067 template<class T>
02068 inline bool
02069 PP_List<T>::operator!= (const PP_List<T>& rhs) const
02070 {
02071   return !operator==(rhs);
02072 }
02073 
02074 template <class T>
02075 inline void
02076 PP_List<T>::remove (PP_ListIterator<T>& li)
02077 {
02078   PP_ListLink<T> *np = li.p->suc;
02079   remove(li.p);
02080   li.p = np;
02081 }
02082 
02083 template <class T>
02084 inline void
02085 PP_List<T>::remove (const T& _v)
02086 {
02087   for (PP_ListIterator<T> litr(*this); litr; ++litr)
02088     if (litr() == _v)
02089       remove(litr);
02090 }
02091 
02092 template <class T>
02093 inline void
02094 PP_List<T>::remove (const PP_List<T>& _lv)
02095 {
02096   for (PP_ListIterator<T> litr(_lv); litr; ++litr)
02097     remove(litr());
02098 }
02099 
02100 template <class T>
02101 inline void
02102 PP_List<T>::remove (PP_ListLink<T>* ln)
02103 {
02104   assert(head !=0 && tail != 0);
02105 
02106   if (head == ln && tail == ln)
02107     head = tail = 0;
02108   else if (head == ln)
02109     {
02110       assert(ln->pre == 0);
02111       head = ln->suc;
02112       head->pre = 0;
02113     }
02114   else if (tail == ln)
02115     {
02116       assert(ln->suc == 0);
02117       tail = ln->pre;
02118       tail->suc  = 0;
02119     }
02120   else
02121     {
02122       assert(ln->suc != 0 && ln->pre != 0);
02123       ln->suc->pre = ln->pre;
02124       ln->pre->suc = ln->suc;
02125     }
02126   delete ln;
02127   ln = 0;
02128 }
02129 
02130 
02131 
02132 template <class T> class PP_Array;
02133 
02135 
02174 template <class T>
02175 class PP_Array
02176 {
02177 public:
02178   //
02180   //
02181   PP_Array ();
02182 
02186   /*explicit*/ PP_Array (long len);
02187 
02191   PP_Array (long     len,
02192             const T& initialvalue);
02193 
02197   PP_Array (const T* vec,
02198             long     len);
02199   //
02201   //
02202   PP_Array (const PP_Array<T>& rhs);
02203 
02207   PP_Array<T>& operator= (const PP_Array<T>& rhs);
02208   //
02210   //
02211   ~PP_Array ();
02212 
02216   void clear ();
02217   //
02219   //
02220   bool ready  () const;
02221 
02225   void reserve (long _truesize);
02226 
02233   void shrinkWrap ();
02234 
02243   void resize (long newlen);
02244 
02253   void resize (long     newlen,
02254                const T& initialvalue);
02255   //
02257   //
02258   long length () const;
02259 
02263   long trueSize () const;
02264 
02269   T& operator[] (long K);
02270   //
02272   //
02273   const T& operator[] (long K) const;
02274   //
02276   //
02277   T& get (long i);
02278   //
02280   //
02281   const T& get (long i) const;
02282 
02287   T* dataPtr ();
02288   //
02290   //
02291   const T* dataPtr () const;
02292   //
02294   //
02295   void set (long     i,
02296             const T& elem);
02297   //
02299   //
02300   void swap (long i,
02301              long j);
02302   //
02304   //
02305   bool operator== (const PP_Array<T>& rhs) const;
02306   //
02308   //
02309   bool operator!= (const PP_Array<T>& rhs) const;
02310 
02311 protected:
02312   //
02313   // The true size of the PP_Array.
02314   //
02315   long truesize;
02316   //
02317   // The number of elements in the PP_Array.
02318   //
02319   long nelem;
02320   //
02321   // The array itself.
02322   //
02323   T* vp;
02324 
02325 private:
02326   //
02327   // This is disallowed.
02328   //
02329   PP_Array<T>& operator= (int);
02330 };
02331 
02332 //
02333 // Inlines.
02334 //
02335 
02336 template <class T>
02337 inline
02338 PP_Array<T>::PP_Array ()
02339 {
02340   nelem    = 0;
02341   vp       = new T[1];
02342   truesize = 1;
02343 }
02344 
02345 template <class T>
02346 inline
02347 PP_Array<T>::PP_Array (long len)
02348 {
02349   assert(len >= 0);
02350   nelem    = len;
02351   vp       = new T[len];
02352   truesize = nelem;
02353 }
02354 
02355 template <class T>
02356 inline
02357 void
02358 PP_Array<T>::clear ()
02359 {
02360   delete [] vp;
02361   vp       = 0;
02362   nelem    = 0;
02363   truesize = 0;
02364 }
02365 
02366 template <class T>
02367 inline
02368 PP_Array<T>::~PP_Array ()
02369 {
02370   clear();
02371 }
02372 
02373 template <class T>
02374 inline
02375 bool
02376 PP_Array<T>::ready () const
02377 {
02378   return vp != 0 && nelem != 0;
02379 }
02380 
02381 template <class T>
02382 inline
02383 long
02384 PP_Array<T>::length () const
02385 {
02386   return nelem;
02387 }
02388 
02389 template <class T>
02390 inline
02391 long
02392 PP_Array<T>::trueSize () const
02393 {
02394   return truesize;
02395 }
02396 
02397 template <class T>
02398 inline
02399 T&
02400 PP_Array<T>::operator[] (long i)
02401 {
02402   assert(vp != 0);
02403   assert(i >= 0 && i < nelem);
02404   return vp[i];
02405 }
02406 
02407 template <class T>
02408 inline
02409 const T&
02410 PP_Array<T>::operator[] (long i) const
02411 {
02412   assert(vp != 0);
02413   assert(i >= 0 && i < nelem);
02414   return vp[i];
02415 }
02416 
02417 template <class T>
02418 inline
02419 T&
02420 PP_Array<T>::get (long i)
02421 {
02422   assert(vp != 0);
02423   assert(i >= 0 && i < nelem);
02424   return vp[i];
02425 }
02426 
02427 template <class T>
02428 inline
02429 const T&
02430 PP_Array<T>::get (long i) const
02431 {
02432   assert(vp != 0);
02433   assert(i >= 0 && i < nelem);
02434   return vp[i];
02435 }
02436 
02437 template <class T>
02438 inline
02439 void
02440 PP_Array<T>::set (long     i,
02441                   const T& elem)
02442 {
02443   assert(vp != 0);
02444   assert(i >= 0 && i < nelem);
02445   vp[i] = elem;
02446 }
02447 
02448 template <class T>
02449 inline
02450 T*
02451 PP_Array<T>::dataPtr ()
02452 {
02453   return vp;
02454 }
02455 
02456 template <class T>
02457 inline
02458 const T*
02459 PP_Array<T>::dataPtr () const
02460 {
02461   return vp;
02462 }
02463 
02464 template <class T>
02465 inline
02466 void
02467 PP_Array<T>::swap (long i,
02468                    long j)
02469 {
02470   assert(i >= 0 && i < nelem);
02471   assert(j >= 0 && j < nelem);
02472   T tmp = vp[i];
02473   vp[i] = vp[j];
02474   vp[j] = tmp;
02475 }
02476 
02477 template <class T>
02478 inline
02479 bool
02480 PP_Array<T>::operator!= (const PP_Array<T>& rhs) const
02481 {
02482   return !(operator==(rhs));
02483 }
02484 
02485 //
02486 // Non-inlined stuff.
02487 //
02488 
02489 template <class T>
02490 PP_Array<T>::PP_Array (long     len,
02491                        const T& initialValue)
02492 {
02493   assert(len >= 0);
02494   nelem = len;
02495   vp    = new T[len];
02496   truesize = nelem;
02497   for(long i = 0; i < nelem; ++i)
02498     vp[i] = initialValue;
02499 }
02500 
02501 template <class T>
02502 PP_Array<T>::PP_Array (const T* vec,
02503                        long     len)
02504 {
02505   assert(len >= 0);
02506   nelem = len;
02507   vp    = new T[len];
02508   truesize = nelem;
02509   for(long i = 0; i < nelem; ++i)
02510     vp[i] = vec[i];
02511 }
02512 
02513 template <class T>
02514 PP_Array<T>::PP_Array (const PP_Array<T>& a)
02515 {
02516   nelem = a.nelem;
02517   vp    = new T[nelem];
02518   truesize = nelem;
02519   for (long i = 0; i < nelem; i++)
02520     vp[i] = a.vp[i];
02521 }
02522 
02523 template <class T>
02524 PP_Array<T>&
02525 PP_Array<T>::operator= (const PP_Array<T>& sa)
02526 {
02527   if (this != &sa)
02528     {
02529       clear();
02530       vp       = new T[sa.nelem];
02531       nelem    = sa.nelem;
02532       truesize = nelem;
02533       for(long i = 0; i < nelem; i++)
02534         vp[i] = sa.vp[i];
02535     }
02536   return *this;
02537 }
02538 
02539 template <class T>
02540 inline
02541 void
02542 PP_Array<T>::resize (long newlen)
02543 {
02544   if (newlen == nelem)
02545     return;
02546   if (newlen <= truesize)
02547     {
02548       nelem = newlen;
02549       return;
02550     }
02551   T* newvp = new T[newlen];
02552   long len = Min(newlen,nelem);
02553   for (long i = 0; i < len; i++)
02554     newvp[i] = vp[i];
02555   delete [] vp;
02556   vp = newvp;
02557   nelem = newlen;
02558   truesize = newlen;
02559 }
02560 
02561 template <class T>
02562 inline
02563 void PP_Array<T>::resize (long     newlen,
02564                           const T& initialValue)
02565 {
02566   if (newlen == nelem)
02567     return;
02568   if (newlen <= truesize)
02569     {
02570       for(long i = nelem; i < newlen; ++i)
02571         vp[i] = initialValue;
02572       nelem = newlen;
02573       return;
02574     }
02575   T* newvp = new T[newlen];
02576   long len = Min(newlen,nelem);
02577   long i;
02578   for (i = 0; i < len; i++)
02579     newvp[i] = vp[i];
02580   for(i = len; i < newlen; ++i)
02581     newvp[i] = initialValue;
02582   delete [] vp;
02583   vp = newvp;
02584   nelem = newlen;
02585   truesize = newlen;
02586 }
02587 
02588 template <class T>
02589 void
02590 PP_Array<T>::reserve (long _truesize)
02591 {
02592   if (_truesize > truesize)
02593     {
02594       T* newvp = new T[_truesize];
02595       for (long i = 0; i < nelem; i++)
02596         newvp[i] = vp[i];
02597       delete [] vp;
02598       vp = newvp;
02599       truesize = _truesize;
02600     }
02601 }
02602 
02603 template <class T>
02604 void
02605 PP_Array<T>::shrinkWrap ()
02606 {
02607   if (nelem != truesize)
02608     {
02609       T* newvp = new T[nelem];
02610       for (long i = 0; i < nelem; i++)
02611         newvp[i] = vp[i];
02612       delete [] vp;
02613       vp = newvp;
02614       truesize = nelem;
02615     }
02616 }
02617 
02618 template <class T>
02619 bool
02620 PP_Array<T>::operator== (const PP_Array<T>& rhs) const
02621 {
02622   if (length() != rhs.length())
02623     return false;
02624 
02625   for (long i = 0; i < length(); ++i)
02626     if (!((*this)[i] == rhs[i]))
02627       return false;
02628 
02629   return true;
02630 }
02631 
02632 
02633 
02634 // -----------------------------------------------------------------
02635 // ----------------------- COMMENTS -------------------------------
02636 // -----------------------------------------------------------------
02637 // The ParmParse class implements a simple database for the storage
02638 // and retrieval of command-line and input-file arguments.  The
02639 // entries are stored in a static table in (name,value_list) pairs.
02640 //
02641 // The format of the input file is a series of OPTIONS and DEFINITIONS.
02642 //
02643 // An OPTION is an entry of the form:  -<name> and has no associated list
02644 // of values.  For example, the command line:
02645 //        prog -verbose -no_opt
02646 // has two options: "verbose" and "no_opt".
02647 //
02648 // A DEFINITION is of the form  <name> = <value> <value> ...
02649 // The equal sign is important since the list of values can span multiple
02650 // lines.
02651 //
02652 // Comments in an input file include all text from a '#' character to the
02653 // end of the line.  Here is an example input file:
02654 //
02655 //   -no_garbage                # an OPTION
02656 //   niter = 100                # niter is an integer
02657 //   title = "Double Wammy"     # example of a string with spaces
02658 //   cell_size = 0.5 0.75       # cell spacing in each dimension
02659 //   plot.var = Density 1 10    # a list of values
02660 //   plot.var = Energy  5 12    # another list of values
02661 //   bigarray = 1 2 3 4 5 6 7 8 # first part of array
02662 //              9 10 11 12      # continuation of bigarray
02663 //   test = apple "boy blue" 10 20 30 40
02664 //   FILE = prob_file           # insert contents of this "prob_file" here
02665 //
02666 // The "FILE = <filename>" definition is special.  Rather than just
02667 // adding this entry to the database, it reads the contents of <filename>
02668 // into the database.
02669 //
02670 // ParmParse stores all entries in a static table which is built the
02671 // first time a ParmParse object is constructed (usually in main()).
02672 // Subsequent invocations have access to this table.
02673 // A ParmParse constructor has an optional "prefix" argument that will
02674 // limit the searches to only those entries of the table with this prefix
02675 // in name.  For example:
02676 //     ParmParse pp("plot");
02677 // will find only those entries with name given by "plot.<string>".
02678 //
02679 // All values in the table are stored as strings.  For example, the
02680 // values of "cell_size" in the above input file are stored as the
02681 // strings "0.5" and "0.75".  These strings can be returned as either
02682 // string of numeric values by the query functions.
02683 // Character strings with spaces must be delimited by double quotes
02684 // in the input file but the quotes are stripped before they are entered
02685 // into the table.  For example, 'title' in the above input file has a
02686 // single value, the string 'Double Wammy' (without the quotes).
02687 // Each value in the list associated with a definition can be referred to
02688 // by its index number.  The index numbers start at 0 just like an array
02689 // in the C programming language.  Consider the definition of "test" in
02690 // the above input file.  The first value 'apple'is a string with index
02691 // 0.  The second value 'boy blue' is a string with index 1.  The
02692 // remaining four values are integers indexed 2, 3, 4, and 5.
02693 //
02694 // For a string value to represent an integer or float it must fit the
02695 // following regular experssion:
02696 //   Sign    ::= '+' | '-'
02697 //   Digit   ::= '0' | '1' | ... | '9'
02698 //   Integer ::= [Sign]Digit+
02699 //   Exp     ::= ('e'|'E')Integer
02700 //   Float   ::= ( Integer[.Digit*][Exp] | [Integer].Digit+[Exp] )
02701 //
02702 // Where '+' indicates one or more occurences, '*' represents zero or
02703 // more occurences, '|' means one or the other and '[]' represents zero
02704 // or one occurence.
02705 //
02706 // Note that floats and doubles have the same string representation and
02707 // that the FORTRAN "double" exponent format is not supported.
02708 // That is, 1.0d+3 is not a valid representation of a floating point
02709 // number but that 1.0e+3 is acceptable.
02710 //
02711 // There are a host of functions allowing the user to query the database
02712 // and retrieve values.  Here are some general rules about the names of
02713 // the member functions:
02714 //
02715 // * Functions with the string "get" in their names attempt to get a
02716 //   value or an array of values from the table.  They generate a
02717 //   run-time error if they are not successful.
02718 //
02719 // * Functions with the string "query" in their names attempt to get a
02720 //   value or an array of values from the table.  They return the value 1
02721 //   (true) if they are successful and 0 (false) if not.
02722 //
02723 // * Functions with the string "arr" in their names get an Array of
02724 //   values from the given entry in the table.  The array argument is
02725 //   resized (if necessary) to hold all the values requested.
02726 //
02727 // * Functions without the string "arr" in their names get single
02728 //   values from the given entry in the table.
02729 //
02730 // The following is a code sample showing how to use ParmParse:
02731 //
02732 // main(int argc, char **argv)
02733 // {
02734 //     char* in_file_name = argv[1];
02735 //     ParmParse pp(argc-2, argv+2, 0, in_file_name);
02736 //
02737 //     // was the "-verbose" command line argument set?
02738 //     int verbose = pp.contains("verbose");
02739 //
02740 //     // Query table for value of "niter".  If not in table
02741 //     // then set to default value
02742 //     if (!pp.query("niter",niter)) niter = 20;
02743 //
02744 //     // read array of cell sizes if in table
02745 //     std::vector<float> dx;
02746 //     if (nx=pp.countval("cell_size")) {
02747 //        // get nx values starting at index 0 and store in dx.
02748 //        // dx is automatically resized here.
02749 //        pp.getarr("cell_size",dx,0,nx);
02750 //     }
02751 // }
02752 //
02753 // void do_graphics()
02754 // {
02755 //    //
02756 //    // Will only query entries with the "plot" prefix:
02757 //    //
02758 //    ParmParse pp("plot");
02759 //    //
02760 //    // Read all variables with "plot.var" keyword.
02761 //    //
02762 //    std::string var_name;
02763 //    std::vector<int> range;
02764 //    int num = pp.countname("var");
02765 //    //
02766 //    // Element 0 in list is a string.
02767 //    //
02768 //    pp.get("var",var_name,0);
02769 //    //
02770 //    // Elements 1 and 2 are integers.
02771 //    // Note that "range" will be resized to hold 2 elements.
02772 //    //
02773 //    pp.getarr("var",range,1,2);
02774 //    cout << "variable = " << var_name << "lo, hi = ",
02775 //         << range[0] << " " << range[1] << endl;
02776 // }
02777 // -----------------------------------------------------------------
02778 // -----------------------  END COMMENTS ---------------------------
02779 // -----------------------------------------------------------------
02780 
02781 //
02782 // Forward reference to private class.
02783 //
02784 class PP_entry;
02785 
02786 #endif //for the doxygen thing
02787 
02789 
02860 class ParmParse
02861 {
02862   friend class PP_entry;
02863 public:
02864 
02866 
02874   ParmParse (int         argc,
02875              char**      argv,
02876              const char* prefix  = 0,
02877              const char* parfile = 0);
02878 
02884   /*explicit*/ ParmParse (const char* prefix = 0);
02885 
02889   ~ParmParse();
02890 
02892 
02895   bool contains (const char* name);
02896 
02898 
02901   bool contains (const std::string& name);
02902 
02904 
02908   int countval (const char* name,
02909                 int         n = -1);
02910 
02912 
02915   int countname (const char* name);
02916 
02918 
02921   int countname (const std::string& name);
02922 
02924 
02927   void dumpTable (std::ostream& os);
02928 
02930 
02938   void get (const char* name,
02939             int&        ref,
02940             int         ival=0);
02941 
02943 
02952   int query (const char* name,
02953              int&        ref,
02954              int         ival=0);
02955 
02957 
02965   void get (const char* name,
02966             float&      ref,
02967             int         ival=0);
02968 
02970 
02979   int query (const char* name,
02980              float&      ref,
02981              int         ival=0);
02982 
02983 
02985 
02993   void get (const char* name,
02994             double&     ref,
02995             int         ival=0);
02996 
02998 
03007   int query (const char* name,
03008              double&     ref,
03009              int         ival=0);
03010 
03012 
03020   void get (const char*  name,
03021             std::string& ref,
03022             int          ival=0);
03023 
03025 
03034   int query (const char*  name,
03035              std::string& ref,
03036              int          ival=0);
03037 
03039 
03051   void getarr (const char* name,
03052                Vector<int>& ref,
03053                int         start_ix,
03054                int         num_val);
03055 
03057 
03069   void getarr (const char* name,
03070                std::vector<int>& ref,
03071                int         start_ix,
03072                int         num_val);
03073 
03075 
03088   int queryarr (const char* name,
03089                 Vector<int>& ref,
03090                 int         start_ix,
03091                 int         num_val);
03092 
03093 
03095 
03108   int queryarr (const char* name,
03109                 std::vector<int>& ref,
03110                 int         start_ix,
03111                 int         num_val);
03112 
03114 
03126   void getarr (const char*   name,
03127                Vector<float>& ref,
03128                int           start_ix,
03129                int           num_val);
03130 
03131 
03133 
03145   void getarr (const char*   name,
03146                std::vector<float>& ref,
03147                int           start_ix,
03148                int           num_val);
03149 
03150 
03152 
03165   int queryarr (const char*   name,
03166                 Vector<float>& ref,
03167                 int           start_ix,
03168                 int           num_val);
03169 
03170 
03172 
03185   int queryarr (const char*   name,
03186                 std::vector<float>& ref,
03187                 int           start_ix,
03188                 int           num_val);
03189 
03190 
03192 
03204   void getarr (const char*    name,
03205                Vector<double>& ref,
03206                int            start_ix,
03207                int            num_val);
03208 
03210 
03222   void getarr (const char*    name,
03223                std::vector<double>& ref,
03224                int            start_ix,
03225                int            num_val);
03226 
03228 
03241   int queryarr (const char*    name,
03242                 Vector<double>& ref,
03243                 int            start_ix,
03244                 int            num_val);
03245 
03247 
03260   int queryarr (const char*    name,
03261                 std::vector<double>& ref,
03262                 int            start_ix,
03263                 int            num_val);
03264 
03266 
03278   void getarr (const char*     name,
03279                Vector<std::string>& ref,
03280                int             start_ix,
03281                int             num_val);
03282 
03284 
03296   void getarr (const char*     name,
03297                std::vector<std::string>& ref,
03298                int             start_ix,
03299                int             num_val);
03300 
03302 
03315   int queryarr (const char*               name,
03316                 Vector<std::string>& ref,
03317                 int                       start_ix,
03318                 int                       num_val);
03319 
03321 
03334   int queryarr (const char*               name,
03335                 std::vector<std::string>& ref,
03336                 int                       start_ix,
03337                 int                       num_val);
03338 
03339 #ifndef DOXYGEN
03340   //
03341   // This should be protected, but cfront-derived compilers complain :-(
03342   //
03343   enum PPType
03344     {
03345       ppDefn,
03346       ppOption,
03347       ppInt,
03348       ppFloat,
03349       ppDouble,
03350       ppString,
03351       ppEQ_sign,
03352       ppEOF
03353     };
03354 protected:
03355 
03356 
03357   //
03358   // Table of entries common to all objects.
03359   //
03360   static PP_List<PP_entry*> table;
03361   //
03362   // Command line arguments.
03363   //
03364   static int    xargc;
03365   static char** xargv;
03366   //
03367   // Keep track of number of ParmParse objects out there.
03368   //
03369   static int num_obj;
03370   //
03371   // Parses string and builds table.
03372   //
03373   void bldTable (const char*      str,
03374                  int              lenstr,
03375                  PP_List<PP_entry*>& tab);
03376   //
03377   // Add defn to table, check for file inclusion.
03378   //
03379   void addDefn (PP_String&         def,
03380                 PP_List<PP_String>&   val,
03381                 PP_List<PP_entry*>& tab);
03382   //
03383   // Reads file into string then parses it with call to bldTable.
03384   //
03385   void read_file (const char*      fname,
03386                   PP_List<PP_entry*>& tab);
03387   //
03388   // Lexical analyser called by bldTable.
03389   //
03390   PPType getToken (const char*,
03391                    int&,
03392                    int,
03393                    char*);
03394   //
03395   // Reclaims memory used in table.
03396   //
03397   void rmTable ();
03398   //
03399   // Prefix used in keyword search.
03400   //
03401   PP_String thePrefix;
03402   //
03403   // Used by constructor to build table.
03404   //
03405   void ppinit (const char* parfile);
03406   //
03407   // Find n'th occurence of name in table.
03408   //
03409   const PP_entry* ppindex (int         n,
03410                            const char* name) const;
03411   //
03412   // Get ival_th value of k_th occurence of given name.
03413   // If k_th occurence does not exist or ival_th value does
03414   // not exist or if ival_type does not match with type, an
03415   // error message is reported and the program halts.
03416   // If successful, value is stored in ptr.
03417   // same as above but searches for last occurence of name.
03418   //
03419   void  getval (const char* name,
03420                 const PPType type,
03421                 void*        ptr,
03422                 int          ival,
03423                 int          k=-1);
03424   //
03425   // Get an array of values.
03426   //
03427   void getarr (const char*  name,
03428                const PPType type,
03429                void*        ptr,
03430                int          start_ix,
03431                int          num_val,
03432                int          k=-1);
03433   int queryval (const char*  name,
03434                 const PPType type,
03435                 void*        ptr,
03436                 int          ival,
03437                 int          k=-1);
03438   int queryarr (const char*  name,
03439                 const PPType type,
03440                 void*        ptr,
03441                 int          start_ix,
03442                 int          num_val,
03443                 int          k=-1);
03444 
03445   bool isInteger (const PP_String& str,
03446                   int&           val);
03447   int isDouble (const PP_String& str,
03448                 double&        val);
03449 
03450 #endif /* DOXYGEN ENDIF */
03451 
03452 };
03453 
03454 #ifndef DOXYGEN
03455 class PP_entry
03456 {
03457 private:
03458   friend class ParmParse;
03459   PP_entry() {}
03460   PP_entry (PP_String&          name,
03461             ParmParse::PPType typ,
03462             PP_List<PP_String>&    vals);
03463   ~PP_entry() {}
03464 
03465   PP_String               defname;
03466   ParmParse::PPType     deftype;
03467   PP_Array<PP_String>        val;
03468 
03469   void dump (std::ostream& os) const;
03470 };
03471 #endif //doxygen
03472 
03473 //
03474 // Inlines.
03475 //
03476 
03477 inline
03478 int
03479 ParmParse::countval (const char* name,
03480                      int         n)
03481 {
03482   //
03483   // First find n'th occurance of name in table.
03484   //
03485   const PP_entry* def = ppindex(n,name);
03486   return def == 0 ? 0 : def->val.length();
03487 }
03488 
03489 
03490 inline
03491 void
03492 ParmParse::get (const char* name,
03493                 int&        ptr,
03494                 int ival)
03495 {
03496   getval(name,ppInt,&ptr,ival,-1);
03497 }
03498 
03499 
03500 inline
03501 int
03502 ParmParse::query (const char* name,
03503                   int&        ptr,
03504                   int         ival)
03505 {
03506   return queryval(name,ppInt,&ptr,ival,-1);
03507 }
03508 
03509 
03510 inline
03511 void
03512 ParmParse::get (const char* name,
03513                 float&      ptr,
03514                 int         ival)
03515 {
03516   getval(name,ppFloat,&ptr,ival,-1);
03517 }
03518 
03519 
03520 inline
03521 int
03522 ParmParse::query (const char* name,
03523                   float&      ptr,
03524                   int         ival)
03525 {
03526   return queryval(name,ppFloat,&ptr,ival,-1);
03527 }
03528 
03529 
03530 inline
03531 void
03532 ParmParse::get (const char* name,
03533                 double&     ptr,
03534                 int         ival)
03535 {
03536   getval(name,ppDouble,&ptr,ival,-1);
03537 }
03538 
03539 
03540 inline
03541 int
03542 ParmParse::query (const char* name,
03543                   double&     ptr,
03544                   int         ival)
03545 {
03546   return queryval(name,ppDouble,&ptr,ival,-1);
03547 }
03548 
03549 
03550 inline
03551 void
03552 ParmParse::get (const char*  name,
03553                 std::string& ptr,
03554                 int          ival)
03555 {
03556   PP_String pp_string;
03557   getval(name,ppString,&pp_string,ival,-1);
03558   ptr = pp_string.c_str();
03559 }
03560 
03561 
03562 inline
03563 int
03564 ParmParse::query (const char*  name,
03565                   std::string& ptr,
03566                   int          ival)
03567 {
03568   PP_String pp_string;
03569   int status = queryval(name,ppString,&pp_string,ival,-1);
03570   if (status != 0) 
03571     ptr = pp_string.c_str();
03572   return status;
03573 }
03574 
03575 
03576 inline
03577 void
03578 ParmParse::getarr (const char* name,
03579                    std::vector<int>& ptr,
03580                    int         start_ix,
03581                    int         num_val)
03582 {
03583   if (ptr.size() < num_val)
03584     ptr.resize(num_val);
03585   int* c_array = new int[num_val];
03586   getarr(name,ppInt,c_array,start_ix,num_val,-1);
03587   for (int i = 0; i < num_val; ++i)
03588     {
03589       ptr[i] = c_array[i];
03590     }
03591   delete[] c_array;
03592 }
03593 
03594 
03595 inline
03596 void
03597 ParmParse::getarr (const char* name,
03598                    Vector<int>& ptr,
03599                    int         start_ix,
03600                    int         num_val)
03601 {
03602   if (ptr.size() < num_val)
03603     ptr.resize(num_val);
03604   int* c_array = new int[num_val];
03605   getarr(name,ppInt,c_array,start_ix,num_val,-1);
03606   for (int i = 0; i < num_val; ++i)
03607     {
03608       ptr[i] = c_array[i];
03609     }
03610   delete[] c_array;
03611 }
03612 
03613 
03614 inline
03615 int
03616 ParmParse::queryarr (const char* name,
03617                      std::vector<int>& ptr,
03618                      int         start_ix,
03619                      int         num_val)
03620 {
03621   if (ptr.size() < num_val)
03622     ptr.resize(num_val);
03623   int* c_array = new int[num_val];
03624   int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03625   if (status != 0 ) 
03626     {
03627       for (int i = 0; i < num_val; ++i)
03628         {
03629           ptr[i] = c_array[i];
03630         }
03631     }
03632   return status;
03633 }
03634 
03635 inline
03636 int
03637 ParmParse::queryarr (const char* name,
03638                      Vector<int>& ptr,
03639                      int         start_ix,
03640                      int         num_val)
03641 {
03642   if (ptr.size() < num_val)
03643     ptr.resize(num_val);
03644   int* c_array = new int[num_val];
03645   int status = queryarr(name,ppInt,c_array,start_ix,num_val,-1);
03646   if (status != 0 ) 
03647     {
03648       for (int i = 0; i < num_val; ++i)
03649         {
03650           ptr[i] = c_array[i];
03651         }
03652     }
03653   return status;
03654 }
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 
03694 inline
03695 int
03696 ParmParse::queryarr (const char*   name,
03697                      std::vector<float>& ptr,
03698                      int           start_ix,
03699                      int           num_val)
03700 {
03701   if (ptr.size() < num_val)
03702     ptr.resize(num_val);
03703   float* c_array = new float[num_val];
03704   int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03705   if (status != 0) 
03706     {
03707       for (int i = 0; i < num_val; ++i)
03708         {
03709           ptr[i] = c_array[i];
03710         }
03711     }
03712   delete[] c_array;
03713   return status;
03714 }
03715 
03716 
03717 inline
03718 int
03719 ParmParse::queryarr (const char*   name,
03720                      Vector<float>& ptr,
03721                      int           start_ix,
03722                      int           num_val)
03723 {
03724   if (ptr.size() < num_val)
03725     ptr.resize(num_val);
03726   float* c_array = new float[num_val];
03727   int status = queryarr(name,ppFloat,c_array,start_ix,num_val,-1);
03728   if (status != 0) 
03729     {
03730       for (int i = 0; i < num_val; ++i)
03731         {
03732           ptr[i] = c_array[i];
03733         }
03734     }
03735   delete[] c_array;
03736   return status;
03737 }
03738 
03739 
03740 inline
03741 void
03742 ParmParse::getarr (const char*    name,
03743                    std::vector<double>& ptr,
03744                    int            start_ix,
03745                    int            num_val)
03746 {
03747   if (ptr.size() < num_val)
03748     ptr.resize(num_val);
03749   double* c_array = new double[num_val];
03750   int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03751   if (status == 0)
03752     {
03753       cerr << "ParmParse::getarr(): " 
03754            << name 
03755            << " not found in table" << endl;
03756       dumpTable(cerr);      
03757       MayDay::Abort();
03758     }
03759   for (int i = 0; i < num_val; ++i)
03760     {
03761       ptr[i] = c_array[i];
03762     }
03763   delete[] c_array;
03764 }
03765 
03766 
03767 inline
03768 void
03769 ParmParse::getarr (const char*    name,
03770                    Vector<double>& ptr,
03771                    int            start_ix,
03772                    int            num_val)
03773 {
03774   if (ptr.size() < num_val)
03775     ptr.resize(num_val);
03776   double* c_array = new double[num_val];
03777   int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03778   if (status == 0)
03779     {
03780       cerr << "ParmParse::getarr(): " 
03781            << name 
03782            << " not found in table" << endl;
03783       dumpTable(cerr);      
03784       MayDay::Abort();
03785     }
03786   for (int i = 0; i < num_val; ++i)
03787     {
03788       ptr[i] = c_array[i];
03789     }
03790   delete[] c_array;
03791 }
03792 
03793 
03794 inline
03795 int
03796 ParmParse::queryarr (const char*    name,
03797                      std::vector<double>& ptr,
03798                      int            start_ix,
03799                      int            num_val)
03800 {
03801   if (ptr.size() < num_val)
03802     ptr.resize(num_val);
03803   double* c_array = new double[num_val];
03804   int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03805   if (status != 0) 
03806     {
03807       for (int i = 0; i < num_val; ++i)
03808         {
03809           ptr[i] = c_array[i];
03810         }
03811     }
03812   delete[] c_array;
03813   return status;
03814 }
03815 
03816 
03817 
03818 
03819 inline
03820 int
03821 ParmParse::queryarr (const char*    name,
03822                      Vector<double>& ptr,
03823                      int            start_ix,
03824                      int            num_val)
03825 {
03826   if (ptr.size() < num_val)
03827     ptr.resize(num_val);
03828   double* c_array = new double[num_val];
03829   int status = queryarr(name,ppDouble,c_array,start_ix,num_val,-1);
03830   if (status != 0) 
03831     {
03832       for (int i = 0; i < num_val; ++i)
03833         {
03834           ptr[i] = c_array[i];
03835         }
03836     }
03837   delete[] c_array;
03838   return status;
03839 }
03840 
03841 
03842 inline
03843 void
03844 ParmParse::getarr (const char*     name,
03845                    std::vector<std::string>& ptr,
03846                    int             start_ix,
03847                    int             num_val)
03848 {
03849   if (ptr.size() < num_val)
03850     ptr.resize(num_val);
03851   PP_String* c_array = new PP_String[num_val];
03852   getarr(name,ppString,c_array,start_ix,num_val,-1);
03853   for (int i = 0; i < num_val; ++i)
03854     {
03855       ptr[i] = c_array[i].c_str();
03856     }
03857   delete[] c_array;
03858 }
03859 
03860 
03861 
03862 inline
03863 void
03864 ParmParse::getarr (const char*     name,
03865                    Vector<std::string>& ptr,
03866                    int             start_ix,
03867                    int             num_val)
03868 {
03869   if (ptr.size() < num_val)
03870     ptr.resize(num_val);
03871   PP_String* c_array = new PP_String[num_val];
03872   getarr(name,ppString,c_array,start_ix,num_val,-1);
03873   for (int i = 0; i < num_val; ++i)
03874     {
03875       ptr[i] = c_array[i].c_str();
03876     }
03877   delete[] c_array;
03878 }
03879 
03880 
03881 inline
03882 int
03883 ParmParse::queryarr (const char*     name,
03884                      std::vector<std::string>& ptr,
03885                      int             start_ix,
03886                      int             num_val)
03887 {
03888   if (ptr.size() < num_val)
03889     ptr.resize(num_val);
03890   PP_String* c_array = new PP_String[num_val];
03891   int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
03892   if (status != 0) 
03893     {
03894       for (int i = 0; i < num_val; ++i)
03895         {
03896           ptr[i] = c_array[i].c_str();
03897         }
03898     }
03899   delete[] c_array;
03900   return status;
03901 }
03902 
03903 
03904 inline
03905 int
03906 ParmParse::queryarr (const char*     name,
03907                      Vector<std::string>& ptr,
03908                      int             start_ix,
03909                      int             num_val)
03910 {
03911   if (ptr.size() < num_val)
03912     ptr.resize(num_val);
03913   PP_String* c_array = new PP_String[num_val];
03914   int status = queryarr(name,ppString,c_array,start_ix,num_val,-1);
03915   if (status != 0) 
03916     {
03917       for (int i = 0; i < num_val; ++i)
03918         {
03919           ptr[i] = c_array[i].c_str();
03920         }
03921     }
03922   delete[] c_array;
03923   return status;
03924 }
03925 
03926 
03927 inline
03928 bool
03929 ParmParse::isInteger (const PP_String& str,
03930                       int&           val)
03931 {
03932   //
03933   // Start token scan.
03934   //
03935   char* endp = 0;
03936   val = (int) strtol(str.c_str(), &endp, 10);
03937   return *endp == 0;
03938 }
03939 
03940 
03941 inline
03942 int
03943 ParmParse::isDouble (const PP_String& str,
03944                      double&        val)
03945 {
03946   char* endp = 0;
03947   val = std::strtod(str.c_str(), &endp);
03948   return *endp == 0;
03949 }
03950 
03951 
03952 inline
03953 int
03954 ParmParse::countname (const std::string& name)
03955 {
03956   return countname(name.c_str());
03957 }
03958 
03959 #endif /*CH_PARMPARSE_H*/

Generated on Wed Jun 2 13:53:34 2004 for Chombo&INSwithParticles by doxygen 1.3.2