00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <winstd.H>
00027
00028 #include <typeinfo>
00029
00030 #if defined(BL_OLD_STL)
00031 #include <stdlib.h>
00032 #include <stddef.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035 #include <ctype.h>
00036 #else
00037 #include <cstdlib>
00038 #include <cstddef>
00039 #include <cstdio>
00040 #include <cstring>
00041 #include <cctype>
00042 #endif
00043
00044 #include <iostream>
00045
00046 #include <strstream>
00047
00048 #include <string>
00049 #include <vector>
00050 #include <list>
00051
00052 #include <BoxLib.H>
00053 #include <ParmParse.H>
00054 #include <ParallelDescriptor.H>
00055 #include <Box.H>
00056 #include <IntVect.H>
00057
00058
00059
00060
00061 ParmParse::PP_entry::PP_entry (const std::string& name,
00062 const std::list<std::string>& vals)
00063 :
00064 m_name(name),
00065 m_table(0),
00066 m_queried(false)
00067 {
00068 for ( std::list<std::string>::const_iterator li = vals.begin(); li != vals.end(); ++li )
00069 {
00070 m_vals.push_back(*li);
00071 }
00072 }
00073
00074 ParmParse::PP_entry::PP_entry (const std::string& name,
00075 const std::list<PP_entry>& table)
00076 :
00077 m_name(name),
00078 m_table(new Table(table)),
00079 m_queried(false)
00080 {
00081 }
00082
00083 ParmParse::PP_entry::PP_entry (const PP_entry& pe)
00084 : m_name(pe.m_name),
00085 m_vals(pe.m_vals),
00086 m_table(0),
00087 m_queried(pe.m_queried)
00088 {
00089 if ( pe.m_table )
00090 {
00091 m_table = new Table(*pe.m_table);
00092 }
00093 }
00094
00095 ParmParse::PP_entry::~PP_entry ()
00096 {
00097 delete m_table;
00098 }
00099
00100 ParmParse::PP_entry&
00101 ParmParse::PP_entry::operator= (const PP_entry& pe)
00102 {
00103 if ( &pe == this ) return *this;
00104 m_name = pe.m_name;
00105 m_vals = pe.m_vals;
00106 m_table = 0;
00107 m_queried = pe.m_queried;
00108 if ( pe.m_table )
00109 {
00110 m_table = new Table(*pe.m_table);
00111 }
00112 return *this;
00113 }
00114
00115 std::ostream&
00116 operator<< (std::ostream& os, const ParmParse::PP_entry& pp)
00117 {
00118 os << pp.m_name << "(nvals = " << pp.m_vals.size() << ") " << " :: [";
00119 int n = pp.m_vals.size();
00120 for ( int i = 0; i < n; i++ )
00121 {
00122 os << pp.m_vals[i];
00123 if ( i < n-1 ) os << ", ";
00124 }
00125 os << "]";
00126
00127 if ( !os )
00128 {
00129 BoxLib::Error("write on ostream failed");
00130 }
00131 return os;
00132 }
00133
00134 namespace
00135 {
00136 enum PType
00137 {
00138 pDefn,
00139 pValue,
00140 pEQ_sign,
00141 pOpenBracket,
00142 pCloseBracket,
00143 pEOF
00144 };
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 template <class T>
00158 bool
00159 is (const std::string& str, T& val)
00160 {
00161 const char* cstr = str.c_str();
00162 std::istrstream s(cstr);
00163 s >> val;
00164 if ( !s ) return false;
00165 return true;
00166 }
00167
00168 template <>
00169 bool
00170 is (const std::string& str, std::string& val)
00171 {
00172 val = str;
00173 return true;
00174 }
00175
00176 template <>
00177 bool
00178 is (const std::string& str, bool& val)
00179 {
00180 if ( str == "true" || str == "t" )
00181 {
00182 val = true;
00183 return true;
00184 }
00185 if ( str == "false" || str == "f" )
00186 {
00187 val = false;
00188 return true;
00189 }
00190 int int_val;
00191 if ( is(str, int_val) )
00192 {
00193 val = int_val != 0;
00194 return true;
00195 }
00196 double dbl_val;
00197 if ( is(str, dbl_val) )
00198 {
00199 val = dbl_val != 0;
00200 return true;
00201 }
00202 return false;
00203 }
00204
00205 ParmParse::Table g_table;
00206 typedef std::list<ParmParse::PP_entry>::iterator list_iterator;
00207 typedef std::list<ParmParse::PP_entry>::const_iterator const_list_iterator;
00208
00209 template <class T> const char* tok_name(const T&) { return typeid(T).name(); }
00210 template <class T> const char* tok_name(std::vector<T>&) { return tok_name(T());}
00211
00212 #if 0
00213 template <> const char* tok_name(const bool&) { return "bool"; }
00214 template <> const char* tok_name(const int&) { return "int"; }
00215 template <> const char* tok_name(const float&) { return "float"; }
00216 template <> const char* tok_name(const double&) { return "double"; }
00217 template <> const char* tok_name(const std::string&) { return "std::string"; }
00218 template <> const char* tok_name(const Box&) { return "Box"; }
00219 template <> const char* tok_name(const IntVect&) { return "IntVect"; }
00220 #endif
00221
00222
00223
00224
00225
00226 enum lexState
00227 {
00228 START,
00229 STRING,
00230 QUOTED_STRING,
00231 IDENTIFIER,
00232 LIST
00233 };
00234
00235 const char* const
00236 state_name[] =
00237 {
00238 "START",
00239 "STRING",
00240 "QUOTED_STRING",
00241 "IDENTIFIER",
00242 "LIST"
00243 };
00244
00245 void
00246 eat_garbage (const char*& str)
00247 {
00248 for (;;)
00249 {
00250 if ( *str == 0 ) break;
00251 else if ( *str == '#' )
00252 {
00253 while ( *str && *str != '\n' )
00254 {
00255 str++;
00256 }
00257 continue;
00258 }
00259 else if ( isspace(*str) )
00260 {
00261 str++;
00262 }
00263 else
00264 {
00265 break;
00266 }
00267 }
00268 }
00269
00270 PType
00271 getToken (const char*& str,
00272 char* ostr)
00273 {
00274 #define ERROR_MESS \
00275 ostr[k++] = '\0'; \
00276 std::cerr << "ParmParse::getToken(): invalid string = " << ostr << '\n'; \
00277 std::cerr << "STATE = " << state_name[state] \
00278 << ", next char = " << ch << '\n'; \
00279 std::cerr << ", rest of input = \n" << str << '\n'; \
00280 BoxLib::Abort()
00281
00282
00283
00284 eat_garbage(str);
00285
00286
00287
00288 if ( *str == 0 )
00289 {
00290 return pEOF;
00291 }
00292
00293
00294
00295 lexState state = START;
00296 int k = 0;
00297 int pcnt = 0;
00298 while (1)
00299 {
00300 char ch = *str;
00301 if ( ch == 0 )
00302 {
00303 BoxLib::Error("ParmParse::getToken: EOF while parsing");
00304 }
00305 switch (state)
00306 {
00307 case START:
00308 if ( ch == '=' )
00309 {
00310 ostr[k++] = ch; str++;
00311 ostr[k++] = 0;
00312 return pEQ_sign;
00313 }
00314 else if ( ch == '"' )
00315 {
00316 str++;
00317 state = QUOTED_STRING;
00318 }
00319 else if ( ch == '(' )
00320 {
00321 ostr[k++] = ch; str++; pcnt = 1;
00322 state = LIST;
00323 }
00324 else if ( ch == '{' )
00325 {
00326 str++;
00327 return pOpenBracket;
00328 }
00329 else if ( ch == '}' )
00330 {
00331 str++;
00332 return pCloseBracket;
00333 }
00334 else if ( isalpha(ch) )
00335 {
00336 ostr[k++] = ch; str++;
00337 state = IDENTIFIER;
00338 }
00339 else
00340 {
00341 ostr[k++] = ch; str++;
00342 state = STRING;
00343 }
00344 break;
00345 case IDENTIFIER:
00346 if ( isalnum(ch) || ch == '_' || ch == '.' || ch == '[' || ch == ']' )
00347 {
00348 ostr[k++] = ch; str++;
00349 }
00350 else if ( isspace(ch) || ch == '=' )
00351 {
00352 ostr[k++] = 0;
00353 return pDefn;
00354 }
00355 else
00356 {
00357 ostr[k++] = ch; str++;
00358 state = STRING;
00359 }
00360 break;
00361 case LIST:
00362 if ( ch == '(' )
00363 {
00364 ostr[k++] = ch; str++; pcnt++;
00365 }
00366 else if ( ch == ')' )
00367 {
00368 ostr[k++] = ch; str++; pcnt--;
00369 if ( pcnt == 0 )
00370 {
00371 ostr[k++] = 0;
00372 return pValue;
00373 }
00374 }
00375 else
00376 {
00377 ostr[k++] = ch; str++;
00378 }
00379 break;
00380 case STRING:
00381 if ( isspace(ch) || ch == '=' )
00382 {
00383 ostr[k++] = 0;
00384 return pValue;
00385 }
00386 else
00387 {
00388 ostr[k++] = ch; str++;
00389 }
00390 break;
00391 case QUOTED_STRING:
00392 if ( ch == '"' )
00393 {
00394 str++;
00395 ostr[k++] = 0;
00396 return pValue;
00397 }
00398 else
00399 {
00400 ostr[k++] = ch; str++;
00401 }
00402 break;
00403 default:
00404 ERROR_MESS;
00405 }
00406 }
00407 #undef ERROR_MESS
00408 }
00409
00410
00411
00412
00413
00414
00415 static
00416 bool
00417 ppfound (const std::string& keyword,
00418 const ParmParse::PP_entry& pe,
00419 bool recordQ)
00420 {
00421 return (recordQ == (pe.m_table!=0)) && (keyword == pe.m_name);
00422 }
00423
00424
00425
00426
00427
00428
00429
00430 const ParmParse::PP_entry*
00431 ppindex (const ParmParse::Table& table,
00432 int n,
00433 const std::string& name,
00434 bool recordQ)
00435 {
00436 const ParmParse::PP_entry* fnd = 0;
00437
00438 if ( n == ParmParse::LAST )
00439 {
00440
00441
00442
00443 for (std::list<ParmParse::PP_entry>::const_reverse_iterator li = table.rbegin(); li != table.rend(); ++li)
00444 {
00445 if ( ppfound(name, *li, recordQ) )
00446 {
00447 fnd = &*li;
00448 break;
00449 }
00450 }
00451 }
00452 else
00453 {
00454 for ( const_list_iterator li=table.begin(); li != table.end(); ++li )
00455 {
00456 if ( ppfound(name, *li, recordQ) )
00457 {
00458 fnd = &*li;
00459 if ( --n < 0 )
00460 {
00461 break;
00462 }
00463 }
00464 }
00465 if ( n >= 0)
00466 {
00467 fnd = 0;
00468 }
00469 }
00470
00471 if ( fnd )
00472 {
00473
00474
00475
00476 for ( const_list_iterator li=table.begin(); li != table.end(); ++li )
00477 {
00478 if ( ppfound(name, *li, recordQ) )
00479 {
00480 li->m_queried = true;
00481 }
00482 }
00483 }
00484 return fnd;
00485 }
00486
00487 void
00488 bldTable (const char*& str, std::list<ParmParse::PP_entry>& tab);
00489
00490 static void
00491 read_file (const char* fname,
00492 std::list<ParmParse::PP_entry>& tab)
00493 {
00494
00495
00496
00497
00498 if ( fname != 0 && fname[0] != 0 )
00499 {
00500 FILE* pffd = fopen(fname, "rb");
00501 if ( pffd == 0 )
00502 {
00503 std::cerr << "ParmParse::read_file(): couldn't open \""
00504 << fname
00505 << "\"";
00506 BoxLib::Abort();
00507 }
00508
00509
00510
00511 fseek(pffd, 0, 2);
00512 int pflen = (int)ftell(pffd);
00513 rewind(pffd);
00514 char* str = new char[pflen+1];
00515 memset(str,0,pflen+1);
00516 int nread = fread(str, 1, pflen, pffd);
00517 if ( !(nread == pflen) )
00518 {
00519 std::cerr << "ParmParse::read_file(): fread() only "
00520 << nread
00521 << " bytes out of "
00522 << pflen
00523 << " from "
00524 << fname;
00525 BoxLib::Abort();
00526 }
00527 fclose(pffd);
00528 const char* b = str;
00529 bldTable(b, tab);
00530 delete [] str;
00531 }
00532 }
00533
00534 void
00535 addDefn (std::string& def,
00536 std::list<std::string>& val,
00537 std::list<ParmParse::PP_entry>& tab)
00538 {
00539 static const std::string FileKeyword("FILE");
00540
00541
00542
00543 if ( def.empty() )
00544 {
00545 val.clear();
00546 return;
00547 }
00548
00549
00550
00551 if ( val.empty() )
00552 {
00553 std::cerr << "ParmParse::addDefn(): no values for definition " << def << "\n";
00554 BoxLib::Abort();
00555 }
00556
00557
00558
00559 if ( def == FileKeyword && val.size() == 1 )
00560 {
00561
00562
00563
00564 const char* fname = val.front().c_str();
00565 read_file(fname, tab);
00566 }
00567 else
00568 {
00569 tab.push_back(ParmParse::PP_entry(def,val));
00570 }
00571 val.clear();
00572 def = std::string();
00573 }
00574
00575 void
00576 addTable (std::string& def,
00577 ParmParse::Table& val,
00578 std::list<ParmParse::PP_entry>& tab)
00579 {
00580 if ( def.empty() )
00581 {
00582 val.clear();
00583 return;
00584 }
00585
00586
00587
00588 if ( val.empty() )
00589 {
00590 std::cerr << "ParmParse::addTable(): no values for Table " << def << "\n";
00591 BoxLib::Abort();
00592 }
00593 tab.push_back(ParmParse::PP_entry(def, val));
00594 val.clear();
00595 def = std::string();
00596 }
00597
00598 void
00599 bldTable (const char*& str,
00600 std::list<ParmParse::PP_entry>& tab)
00601 {
00602 std::string cur_name;
00603 std::list<std::string> cur_list;
00604 ParmParse::Table cur_table;
00605 std::string tmp_str;
00606
00607 PType token;
00608 const int SCRATCH_STR_LEN = 200;
00609 char tokname[SCRATCH_STR_LEN];
00610
00611 for (;;)
00612 {
00613 token = getToken(str, tokname);
00614
00615 switch (token)
00616 {
00617 case pCloseBracket:
00618 if ( !cur_name.empty() && cur_list.empty() )
00619 {
00620 BoxLib::Abort("ParmParse::bldTable() defn with no list");
00621 }
00622 case pEOF:
00623 addDefn(cur_name,cur_list,tab);
00624 return;
00625 case pOpenBracket:
00626 if ( cur_name.empty() )
00627 {
00628 BoxLib::Abort("ParmParse::bldTabe() '{' with no blocknamne");
00629 }
00630 if ( !cur_list.empty() )
00631 {
00632 tmp_str = cur_list.back();
00633 cur_list.pop_back();
00634 addDefn(cur_name, cur_list, tab);
00635 cur_name = tmp_str;
00636 }
00637 bldTable(str, cur_table);
00638 addTable(cur_name, cur_table, tab);
00639 break;
00640 case pEQ_sign:
00641 if ( cur_name.empty() )
00642 {
00643 BoxLib::Abort("ParmParse::bldTable() EQ with no current defn");
00644 }
00645 if ( !cur_list.empty() )
00646 {
00647 tmp_str = cur_list.back();
00648 cur_list.pop_back();
00649 addDefn(cur_name,cur_list,tab);
00650 cur_name = tmp_str;
00651 }
00652
00653
00654
00655 break;
00656 case pDefn:
00657 if ( cur_name.empty() )
00658 {
00659 cur_name = tokname;
00660 break;
00661 }
00662
00663
00664
00665 case pValue:
00666 if ( cur_name.empty() )
00667 {
00668 tokname[SCRATCH_STR_LEN-1] = 0;
00669 std::string msg("ParmParse::bldTable(): value with no defn: ");
00670 msg += tokname;
00671 BoxLib::Abort(msg.c_str());
00672 }
00673 cur_list.push_back(tokname);
00674 break;
00675 }
00676 }
00677 }
00678
00679 namespace
00680 {
00681 template <class T>
00682 bool
00683 squeryval (const ParmParse::Table& table,
00684 const std::string& name,
00685 T& ptr,
00686 int ival,
00687 int occurence)
00688 {
00689
00690
00691
00692 const ParmParse::PP_entry* def = ppindex(table, occurence, name, false);
00693 if ( def == 0 )
00694 {
00695 return false;
00696 }
00697
00698
00699
00700 if ( ival >= def->m_vals.size() )
00701 {
00702 std::cerr << "ParmParse::queryval no value number"
00703 << ival << " for ";
00704 if ( occurence == ParmParse::LAST )
00705 {
00706 std::cerr << "last occurence of ";
00707 }
00708 else
00709 {
00710 std::cerr << " occurence " << occurence << " of ";
00711 }
00712 std::cerr << def->m_name << '\n' << *def << '\n';
00713 BoxLib::Abort();
00714 }
00715
00716 const std::string& valname = def->m_vals[ival];
00717
00718 bool ok = is(valname, ptr);
00719 if ( !ok )
00720 {
00721 std::cerr << "ParmParse::queryval type mismatch on value number "
00722 << ival << " of " << '\n';
00723 if ( occurence == ParmParse::LAST )
00724 {
00725 std::cerr << " last occurence of ";
00726 }
00727 else
00728 {
00729 std::cerr << " occurence number " << occurence << " of ";
00730 }
00731 std::cerr << def->m_name << '\n';
00732 std::cerr << " Expected an \""
00733 << tok_name(ptr)
00734 << "\" type which can't be parsed from the string \""
00735 << valname << "\"\n"
00736 << *def << '\n';
00737 BoxLib::Abort();
00738 }
00739 return true;
00740 }
00741
00742 template <class T>
00743 void
00744 sgetval (const ParmParse::Table& table,
00745 const std::string& name,
00746 T& ptr,
00747 int ival,
00748 int occurence)
00749 {
00750 if ( squeryval(table, name,ptr,ival,occurence) == 0 )
00751 {
00752 std::cerr << "ParmParse::getval ";
00753 if ( occurence >= 0 )
00754 {
00755 std::cerr << "occurence number "
00756 << occurence
00757 << " of ";
00758 }
00759
00760 std::cerr << "ParmParse::getval(): "
00761 << name
00762 << " not found in table"
00763 << '\n';
00764 ParmParse::dumpTable(std::cerr);
00765 BoxLib::Abort();
00766 }
00767 }
00768
00769 bool
00770 squeryarr (const ParmParse::Table& table,
00771 const std::string& name,
00772 std::vector<int>& ptr,
00773 int start_ix,
00774 int num_val,
00775 int occurence)
00776 {
00777
00778
00779
00780 const ParmParse::PP_entry *def = ppindex(table,occurence, name, false);
00781 if ( def == 0 )
00782 {
00783 return false;
00784 }
00785
00786
00787
00788
00789 if ( num_val == ParmParse::ALL )
00790 {
00791 num_val = def->m_vals.size();
00792 }
00793
00794 if ( num_val == 0 ) return true;
00795
00796 int stop_ix = start_ix + num_val - 1;
00797 if ( ptr.size() < stop_ix )
00798 {
00799 ptr.resize(stop_ix + 1);
00800 }
00801 if ( stop_ix >= def->m_vals.size() )
00802 {
00803 std::cerr << "ParmParse::queryarr too many values requested for";
00804 if ( occurence == ParmParse::LAST )
00805 {
00806 std::cerr << " last occurence of ";
00807 }
00808 else
00809 {
00810 std::cerr << " occurence " << occurence << " of ";
00811 }
00812 std::cerr << def->m_name << '\n' << *def << '\n';
00813 BoxLib::Abort();
00814 }
00815 for ( int n = start_ix; n <= stop_ix; n++ )
00816 {
00817 const std::string& valname = def->m_vals[n];
00818 bool ok = is(valname, ptr[n]);
00819 if ( !ok )
00820 {
00821 std::cerr << "ParmParse::queryarr type mismatch on value number "
00822 << n << " of ";
00823 if ( occurence == ParmParse::LAST )
00824 {
00825 std::cerr << " last occurence of ";
00826 }
00827 else
00828 {
00829 std::cerr << " occurence number " << occurence << " of ";
00830 }
00831 std::cerr << def->m_name << '\n';
00832 std::cerr << " Expected an \""
00833 << tok_name(ptr)
00834 << "\" type which can't be parsed from the string \""
00835 << valname << "\"\n"
00836 << *def << '\n';
00837 BoxLib::Abort();
00838 }
00839 }
00840 return true;
00841 }
00842
00843 void
00844 sgetarr (const ParmParse::Table& table,
00845 const std::string& name,
00846 std::vector<int>& ptr,
00847 int start_ix,
00848 int num_val,
00849 int occurence)
00850 {
00851 if ( squeryarr(table,name,ptr,start_ix,num_val,occurence) == 0 )
00852 {
00853 std::cerr << "ParmParse::sgetarr ";
00854 if ( occurence >= 0 )
00855 {
00856 std::cerr << "occurence number " << occurence << " of ";
00857 }
00858 std::cerr << "ParmParse::sgetarr(): "
00859 << name
00860 << " not found in table"
00861 << '\n';
00862 ParmParse::dumpTable(std::cerr);
00863 BoxLib::Abort();
00864 }
00865 }
00866
00867 bool
00868 squeryarr (const ParmParse::Table& table,
00869 const std::string& name,
00870 std::vector<float>& ptr,
00871 int start_ix,
00872 int num_val,
00873 int occurence)
00874 {
00875
00876
00877
00878 const ParmParse::PP_entry *def = ppindex(table,occurence, name, false);
00879 if ( def == 0 )
00880 {
00881 return false;
00882 }
00883
00884
00885
00886
00887 if ( num_val == ParmParse::ALL )
00888 {
00889 num_val = def->m_vals.size();
00890 }
00891
00892 if ( num_val == 0 ) return true;
00893
00894 int stop_ix = start_ix + num_val - 1;
00895 if ( ptr.size() < stop_ix )
00896 {
00897 ptr.resize(stop_ix + 1);
00898 }
00899 if ( stop_ix >= def->m_vals.size() )
00900 {
00901 std::cerr << "ParmParse::queryarr too many values requested for";
00902 if ( occurence == ParmParse::LAST )
00903 {
00904 std::cerr << " last occurence of ";
00905 }
00906 else
00907 {
00908 std::cerr << " occurence " << occurence << " of ";
00909 }
00910 std::cerr << def->m_name << '\n' << *def << '\n';
00911 BoxLib::Abort();
00912 }
00913 for ( int n = start_ix; n <= stop_ix; n++ )
00914 {
00915 const std::string& valname = def->m_vals[n];
00916 bool ok = is(valname, ptr[n]);
00917 if ( !ok )
00918 {
00919 std::cerr << "ParmParse::queryarr type mismatch on value number "
00920 << n << " of ";
00921 if ( occurence == ParmParse::LAST )
00922 {
00923 std::cerr << " last occurence of ";
00924 }
00925 else
00926 {
00927 std::cerr << " occurence number " << occurence << " of ";
00928 }
00929 std::cerr << def->m_name << '\n';
00930 std::cerr << " Expected an \""
00931 << tok_name(ptr)
00932 << "\" type which can't be parsed from the string \""
00933 << valname << "\"\n"
00934 << *def << '\n';
00935 BoxLib::Abort();
00936 }
00937 }
00938 return true;
00939 }
00940
00941 void
00942 sgetarr (const ParmParse::Table& table,
00943 const std::string& name,
00944 std::vector<float>& ptr,
00945 int start_ix,
00946 int num_val,
00947 int occurence)
00948 {
00949 if ( squeryarr(table,name,ptr,start_ix,num_val,occurence) == 0 )
00950 {
00951 std::cerr << "ParmParse::sgetarr ";
00952 if ( occurence >= 0 )
00953 {
00954 std::cerr << "occurence number " << occurence << " of ";
00955 }
00956 std::cerr << "ParmParse::sgetarr(): "
00957 << name
00958 << " not found in table"
00959 << '\n';
00960 ParmParse::dumpTable(std::cerr);
00961 BoxLib::Abort();
00962 }
00963 }
00964
00965 bool
00966 squeryarr (const ParmParse::Table& table,
00967 const std::string& name,
00968 std::vector<double>& ptr,
00969 int start_ix,
00970 int num_val,
00971 int occurence)
00972 {
00973
00974
00975
00976 const ParmParse::PP_entry *def = ppindex(table,occurence, name, false);
00977 if ( def == 0 )
00978 {
00979 return false;
00980 }
00981
00982
00983
00984
00985 if ( num_val == ParmParse::ALL )
00986 {
00987 num_val = def->m_vals.size();
00988 }
00989
00990 if ( num_val == 0 ) return true;
00991
00992 int stop_ix = start_ix + num_val - 1;
00993 if ( ptr.size() < stop_ix )
00994 {
00995 ptr.resize(stop_ix + 1);
00996 }
00997 if ( stop_ix >= def->m_vals.size() )
00998 {
00999 std::cerr << "ParmParse::queryarr too many values requested for";
01000 if ( occurence == ParmParse::LAST )
01001 {
01002 std::cerr << " last occurence of ";
01003 }
01004 else
01005 {
01006 std::cerr << " occurence " << occurence << " of ";
01007 }
01008 std::cerr << def->m_name << '\n' << *def << '\n';
01009 BoxLib::Abort();
01010 }
01011 for ( int n = start_ix; n <= stop_ix; n++ )
01012 {
01013 const std::string& valname = def->m_vals[n];
01014 bool ok = is(valname, ptr[n]);
01015 if ( !ok )
01016 {
01017 std::cerr << "ParmParse::queryarr type mismatch on value number "
01018 << n << " of ";
01019 if ( occurence == ParmParse::LAST )
01020 {
01021 std::cerr << " last occurence of ";
01022 }
01023 else
01024 {
01025 std::cerr << " occurence number " << occurence << " of ";
01026 }
01027 std::cerr << def->m_name << '\n';
01028 std::cerr << " Expected an \""
01029 << tok_name(ptr)
01030 << "\" type which can't be parsed from the string \""
01031 << valname << "\"\n"
01032 << *def << '\n';
01033 BoxLib::Abort();
01034 }
01035 }
01036 return true;
01037 }
01038
01039 void
01040 sgetarr (const ParmParse::Table& table,
01041 const std::string& name,
01042 std::vector<double>& ptr,
01043 int start_ix,
01044 int num_val,
01045 int occurence)
01046 {
01047 if ( squeryarr(table,name,ptr,start_ix,num_val,occurence) == 0 )
01048 {
01049 std::cerr << "ParmParse::sgetarr ";
01050 if ( occurence >= 0 )
01051 {
01052 std::cerr << "occurence number " << occurence << " of ";
01053 }
01054 std::cerr << "ParmParse::sgetarr(): "
01055 << name
01056 << " not found in table"
01057 << '\n';
01058 ParmParse::dumpTable(std::cerr);
01059 BoxLib::Abort();
01060 }
01061 }
01062
01063 bool
01064 squeryarr (const ParmParse::Table& table,
01065 const std::string& name,
01066 std::vector<std::string>& ptr,
01067 int start_ix,
01068 int num_val,
01069 int occurence)
01070 {
01071
01072
01073
01074 const ParmParse::PP_entry *def = ppindex(table,occurence, name, false);
01075 if ( def == 0 )
01076 {
01077 return false;
01078 }
01079
01080
01081
01082
01083 if ( num_val == ParmParse::ALL )
01084 {
01085 num_val = def->m_vals.size();
01086 }
01087
01088 if ( num_val == 0 ) return true;
01089
01090 int stop_ix = start_ix + num_val - 1;
01091 if ( ptr.size() < stop_ix )
01092 {
01093 ptr.resize(stop_ix + 1);
01094 }
01095 if ( stop_ix >= def->m_vals.size() )
01096 {
01097 std::cerr << "ParmParse::queryarr too many values requested for";
01098 if ( occurence == ParmParse::LAST )
01099 {
01100 std::cerr << " last occurence of ";
01101 }
01102 else
01103 {
01104 std::cerr << " occurence " << occurence << " of ";
01105 }
01106 std::cerr << def->m_name << '\n' << *def << '\n';
01107 BoxLib::Abort();
01108 }
01109 for ( int n = start_ix; n <= stop_ix; n++ )
01110 {
01111 const std::string& valname = def->m_vals[n];
01112 bool ok = is(valname, ptr[n]);
01113 if ( !ok )
01114 {
01115 std::cerr << "ParmParse::queryarr type mismatch on value number "
01116 << n << " of ";
01117 if ( occurence == ParmParse::LAST )
01118 {
01119 std::cerr << " last occurence of ";
01120 }
01121 else
01122 {
01123 std::cerr << " occurence number " << occurence << " of ";
01124 }
01125 std::cerr << def->m_name << '\n';
01126 std::cerr << " Expected an \""
01127 << tok_name(ptr)
01128 << "\" type which can't be parsed from the string \""
01129 << valname << "\"\n"
01130 << *def << '\n';
01131 BoxLib::Abort();
01132 }
01133 }
01134 return true;
01135 }
01136
01137 void
01138 sgetarr (const ParmParse::Table& table,
01139 const std::string& name,
01140 std::vector<std::string>& ptr,
01141 int start_ix,
01142 int num_val,
01143 int occurence)
01144 {
01145 if ( squeryarr(table,name,ptr,start_ix,num_val,occurence) == 0 )
01146 {
01147 std::cerr << "ParmParse::sgetarr ";
01148 if ( occurence >= 0 )
01149 {
01150 std::cerr << "occurence number " << occurence << " of ";
01151 }
01152 std::cerr << "ParmParse::sgetarr(): "
01153 << name
01154 << " not found in table"
01155 << '\n';
01156 ParmParse::dumpTable(std::cerr);
01157 BoxLib::Abort();
01158 }
01159 }
01160
01161 bool
01162 squeryarr (const ParmParse::Table& table,
01163 const std::string& name,
01164 std::vector<IntVect>& ptr,
01165 int start_ix,
01166 int num_val,
01167 int occurence)
01168 {
01169
01170
01171
01172 const ParmParse::PP_entry *def = ppindex(table,occurence, name, false);
01173 if ( def == 0 )
01174 {
01175 return false;
01176 }
01177
01178
01179
01180
01181 if ( num_val == ParmParse::ALL )
01182 {
01183 num_val = def->m_vals.size();
01184 }
01185
01186 if ( num_val == 0 ) return true;
01187
01188 int stop_ix = start_ix + num_val - 1;
01189 if ( ptr.size() < stop_ix )
01190 {
01191 ptr.resize(stop_ix + 1);
01192 }
01193 if ( stop_ix >= def->m_vals.size() )
01194 {
01195 std::cerr << "ParmParse::queryarr too many values requested for";
01196 if ( occurence == ParmParse::LAST )
01197 {
01198 std::cerr << " last occurence of ";
01199 }
01200 else
01201 {
01202 std::cerr << " occurence " << occurence << " of ";
01203 }
01204 std::cerr << def->m_name << '\n' << *def << '\n';
01205 BoxLib::Abort();
01206 }
01207 for ( int n = start_ix; n <= stop_ix; n++ )
01208 {
01209 const std::string& valname = def->m_vals[n];
01210 bool ok = is(valname, ptr[n]);
01211 if ( !ok )
01212 {
01213 std::cerr << "ParmParse::queryarr type mismatch on value number "
01214 << n << " of ";
01215 if ( occurence == ParmParse::LAST )
01216 {
01217 std::cerr << " last occurence of ";
01218 }
01219 else
01220 {
01221 std::cerr << " occurence number " << occurence << " of ";
01222 }
01223 std::cerr << def->m_name << '\n';
01224 std::cerr << " Expected an \""
01225 << tok_name(ptr)
01226 << "\" type which can't be parsed from the string \""
01227 << valname << "\"\n"
01228 << *def << '\n';
01229 BoxLib::Abort();
01230 }
01231 }
01232 return true;
01233 }
01234
01235 void
01236 sgetarr (const ParmParse::Table& table,
01237 const std::string& name,
01238 std::vector<IntVect>& ptr,
01239 int start_ix,
01240 int num_val,
01241 int occurence)
01242 {
01243 if ( squeryarr(table,name,ptr,start_ix,num_val,occurence) == 0 )
01244 {
01245 std::cerr << "ParmParse::sgetarr ";
01246 if ( occurence >= 0 )
01247 {
01248 std::cerr << "occurence number " << occurence << " of ";
01249 }
01250 std::cerr << "ParmParse::sgetarr(): "
01251 << name
01252 << " not found in table"
01253 << '\n';
01254 ParmParse::dumpTable(std::cerr);
01255 BoxLib::Abort();
01256 }
01257 }
01258
01259 bool
01260 squeryarr (const ParmParse::Table& table,
01261 const std::string& name,
01262 std::vector<Box>& ptr,
01263 int start_ix,
01264 int num_val,
01265 int occurence)
01266 {
01267
01268
01269
01270 const ParmParse::PP_entry *def = ppindex(table,occurence, name, false);
01271 if ( def == 0 )
01272 {
01273 return false;
01274 }
01275
01276
01277
01278
01279 if ( num_val == ParmParse::ALL )
01280 {
01281 num_val = def->m_vals.size();
01282 }
01283
01284 if ( num_val == 0 ) return true;
01285
01286 int stop_ix = start_ix + num_val - 1;
01287 if ( ptr.size() < stop_ix )
01288 {
01289 ptr.resize(stop_ix + 1);
01290 }
01291 if ( stop_ix >= def->m_vals.size() )
01292 {
01293 std::cerr << "ParmParse::queryarr too many values requested for";
01294 if ( occurence == ParmParse::LAST )
01295 {
01296 std::cerr << " last occurence of ";
01297 }
01298 else
01299 {
01300 std::cerr << " occurence " << occurence << " of ";
01301 }
01302 std::cerr << def->m_name << '\n' << *def << '\n';
01303 BoxLib::Abort();
01304 }
01305 for ( int n = start_ix; n <= stop_ix; n++ )
01306 {
01307 const std::string& valname = def->m_vals[n];
01308 bool ok = is(valname, ptr[n]);
01309 if ( !ok )
01310 {
01311 std::cerr << "ParmParse::queryarr type mismatch on value number "
01312 << n << " of ";
01313 if ( occurence == ParmParse::LAST )
01314 {
01315 std::cerr << " last occurence of ";
01316 }
01317 else
01318 {
01319 std::cerr << " occurence number " << occurence << " of ";
01320 }
01321 std::cerr << def->m_name << '\n';
01322 std::cerr << " Expected an \""
01323 << tok_name(ptr)
01324 << "\" type which can't be parsed from the string \""
01325 << valname << "\"\n"
01326 << *def << '\n';
01327 BoxLib::Abort();
01328 }
01329 }
01330 return true;
01331 }
01332
01333 void
01334 sgetarr (const ParmParse::Table& table,
01335 const std::string& name,
01336 std::vector<Box>& ptr,
01337 int start_ix,
01338 int num_val,
01339 int occurence)
01340 {
01341 if ( squeryarr(table,name,ptr,start_ix,num_val,occurence) == 0 )
01342 {
01343 std::cerr << "ParmParse::sgetarr ";
01344 if ( occurence >= 0 )
01345 {
01346 std::cerr << "occurence number " << occurence << " of ";
01347 }
01348 std::cerr << "ParmParse::sgetarr(): "
01349 << name
01350 << " not found in table"
01351 << '\n';
01352 ParmParse::dumpTable(std::cerr);
01353 BoxLib::Abort();
01354 }
01355 }
01356 }
01357
01358
01359
01360
01361
01362
01363
01364 bool initialized = false;
01365
01366 void
01367 ppinit (int argc, char** argv, const char* parfile, ParmParse::Table& table)
01368 {
01369 if ( parfile != 0 )
01370 {
01371 read_file(parfile, table);
01372 }
01373
01374 if ( argc > 0 )
01375 {
01376 std::string argstr;
01377 const char SPACE = ' ';
01378 for ( int i = 0; i < argc; i++ )
01379 {
01380 argstr += argv[i];
01381 argstr += SPACE;
01382 }
01383 std::list<ParmParse::PP_entry> arg_table;
01384 const char* b = argstr.c_str();
01385 bldTable(b, arg_table);
01386
01387
01388
01389 g_table.splice(table.end(), arg_table);
01390 }
01391 initialized = true;
01392 }
01393
01394 }
01395
01396 std::string
01397 ParmParse::prefixedName (const std::string& str) const
01398 {
01399 if ( str.empty() )
01400 {
01401 BoxLib::Error("ParmParse::prefixedName: has empty name");
01402 }
01403 if ( !m_pstack.top().empty())
01404 {
01405 return m_pstack.top() + '.' + str;
01406 }
01407 return str;
01408 }
01409
01410 void
01411 ParmParse::pushPrefix (const std::string& str)
01412 {
01413 std::string s(str);
01414 if ( !s.empty() )
01415 {
01416 if ( !m_pstack.top().empty() )
01417 {
01418 s = m_pstack.top() + "." + s;
01419 }
01420 m_pstack.push(s);
01421 }
01422 }
01423
01424 void
01425 ParmParse::popPrefix ()
01426 {
01427 if ( m_pstack.size() <= 1 )
01428 {
01429 BoxLib::Error("ParmParse::popPrefix: stack underflow");
01430 }
01431 m_pstack.pop();
01432 }
01433
01434 std::string
01435 ParmParse::getPrefix() const
01436 {
01437 return m_pstack.top();
01438 }
01439
01440 void
01441 ParmParse::Initialize (int argc,
01442 char** argv,
01443 const char* parfile)
01444 {
01445 if ( initialized )
01446 {
01447 BoxLib::Error("ParmParse::Initialize(): already initialized!");
01448 }
01449 ppinit(argc, argv, parfile, g_table);
01450 }
01451
01452 ParmParse::ParmParse (const std::string& prefix)
01453 :
01454 m_table(g_table)
01455 {
01456 m_pstack.push(prefix);
01457 }
01458
01459 ParmParse::ParmParse (const Table& table)
01460 : m_table(table)
01461 {
01462 m_pstack.push("");
01463 }
01464
01465 ParmParse::Frame::Frame (ParmParse& pp, const std::string& pfix)
01466 :
01467 m_pp(pp), m_np(0)
01468 {
01469 push(pfix);
01470 BL_ASSERT( m_np == 1 );
01471 }
01472
01473 ParmParse::Frame::~Frame ()
01474 {
01475 BL_ASSERT( m_np > 0 );
01476 while ( m_np )
01477 {
01478 pop();
01479 }
01480 BL_ASSERT( m_np == 0 );
01481 }
01482
01483 void
01484 ParmParse::Frame::push (const std::string& str)
01485 {
01486 m_pp.pushPrefix(str);
01487 m_np++;
01488 }
01489
01490 void
01491 ParmParse::Frame::pop ()
01492 {
01493 BL_ASSERT( m_np > 0);
01494 m_pp.popPrefix();
01495 m_np--;
01496 }
01497
01498 std::string
01499 ParmParse::Frame::getPrefix () const
01500 {
01501 return m_pp.getPrefix();
01502 }
01503
01504 namespace
01505 {
01506 bool
01507 unused_table_entries_q (const ParmParse::Table& table)
01508 {
01509 for ( const_list_iterator li = table.begin(); li != table.end(); ++li )
01510 {
01511 if ( li->m_table )
01512 {
01513 if ( !li->m_queried )
01514 {
01515 return true;
01516 }
01517 else
01518 {
01519 return unused_table_entries_q(*li->m_table);
01520 }
01521 }
01522 else if ( !li->m_queried )
01523 {
01524 return true;
01525 }
01526 }
01527 return false;
01528 }
01529
01530 void
01531 finalize_table (std::string pfx, const ParmParse::Table& table)
01532 {
01533 for ( const_list_iterator li = table.begin(); li != table.end(); ++li )
01534 {
01535 if ( li->m_table )
01536 {
01537 if ( !li->m_queried )
01538 {
01539 std::cout << "Record " << li->m_name << std::endl;
01540 }
01541 else
01542 {
01543 finalize_table(pfx + "::" + li->m_name, *li->m_table);
01544 }
01545 }
01546 else if ( !li->m_queried )
01547 {
01548 std::cout << pfx << "::" << *li << std::endl;
01549 }
01550 }
01551 }
01552 }
01553
01554
01555 void
01556 ParmParse::Finalize ()
01557 {
01558 if ( ParallelDescriptor::IOProcessor() && unused_table_entries_q(g_table))
01559 {
01560 std::cout << "Unused ParmParse Variables:\n";
01561 finalize_table("[TOP]", g_table);
01562 std::cout << "done.\n";
01563
01564
01565
01566 }
01567 g_table.clear();
01568 }
01569
01570 void
01571 ParmParse::dumpTable (std::ostream& os)
01572 {
01573 for ( const_list_iterator li=g_table.begin(); li != g_table.end(); ++li )
01574 {
01575 os << *li << std::endl;
01576 }
01577 }
01578
01579 int
01580 ParmParse::countval (const char* name,
01581 int n) const
01582 {
01583
01584
01585
01586 const PP_entry* def = ppindex(m_table, n, prefixedName(name), false);
01587 return def == 0 ? 0 : def->m_vals.size();
01588 }
01589
01590
01591 void
01592 ParmParse::getkth (const char* name,
01593 int k,
01594 bool& ptr,
01595 int ival) const
01596 {
01597 sgetval(m_table, prefixedName(name),ptr,ival,k);
01598 }
01599
01600 void
01601 ParmParse::get (const char* name,
01602 bool& ptr,
01603 int ival) const
01604 {
01605 sgetval(m_table, prefixedName(name),ptr,ival, LAST);
01606 }
01607
01608 int
01609 ParmParse::querykth (const char* name,
01610 int k,
01611 bool& ptr,
01612 int ival) const
01613 {
01614 return squeryval(m_table, prefixedName(name),ptr,ival,k);
01615 }
01616
01617 int
01618 ParmParse::query (const char* name,
01619 bool& ptr,
01620 int ival) const
01621 {
01622 return squeryval(m_table, prefixedName(name),ptr,ival, LAST);
01623 }
01624
01625
01626 void
01627 ParmParse::getkth (const char* name,
01628 int k,
01629 int& ptr,
01630 int ival) const
01631 {
01632 sgetval(m_table, prefixedName(name),ptr,ival,k);
01633 }
01634
01635 void
01636 ParmParse::get (const char* name,
01637 int& ptr,
01638 int ival) const
01639 {
01640 sgetval(m_table, prefixedName(name),ptr,ival, LAST);
01641 }
01642
01643 int
01644 ParmParse::querykth (const char* name,
01645 int k,
01646 int& ptr,
01647 int ival) const
01648 {
01649 return squeryval(m_table, prefixedName(name),ptr,ival,k);
01650 }
01651
01652 int
01653 ParmParse::query (const char* name,
01654 int& ptr,
01655 int ival) const
01656 {
01657 return squeryval(m_table, prefixedName(name),ptr,ival, LAST);
01658 }
01659
01660 void
01661 ParmParse::getktharr (const char* name,
01662 int k,
01663 std::vector<int>& ptr,
01664 int start_ix,
01665 int num_val) const
01666 {
01667 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val,k);
01668 }
01669
01670 void
01671 ParmParse::getarr (const char* name,
01672 std::vector<int>& ptr,
01673 int start_ix,
01674 int num_val) const
01675 {
01676 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01677 }
01678
01679 int
01680 ParmParse::queryktharr (const char* name,
01681 int k,
01682 std::vector<int>& ptr,
01683 int start_ix,
01684 int num_val) const
01685 {
01686 return squeryarr(m_table, prefixedName(name),ptr,start_ix,num_val,k);
01687 }
01688
01689 int
01690 ParmParse::queryarr (const char* name,
01691 std::vector<int>& ptr,
01692 int start_ix,
01693 int num_val) const
01694 {
01695 return squeryarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01696 }
01697
01698
01699 void
01700 ParmParse::getkth (const char* name,
01701 int k,
01702 float& ptr,
01703 int ival) const
01704 {
01705 sgetval(m_table, prefixedName(name),ptr,ival,k);
01706 }
01707
01708 void
01709 ParmParse::get (const char* name,
01710 float& ptr,
01711 int ival) const
01712 {
01713 sgetval(m_table, prefixedName(name),ptr,ival, LAST);
01714 }
01715
01716 int
01717 ParmParse::querykth (const char* name,
01718 int k,
01719 float& ptr,
01720 int ival) const
01721 {
01722 return squeryval(m_table, prefixedName(name),ptr,ival,k);
01723 }
01724
01725 int
01726 ParmParse::query (const char* name,
01727 float& ptr,
01728 int ival) const
01729 {
01730 return squeryval(m_table, prefixedName(name),ptr,ival, LAST);
01731 }
01732
01733 void
01734 ParmParse::getktharr (const char* name,
01735 int k,
01736 std::vector<float>& ptr,
01737 int start_ix,
01738 int num_val) const
01739 {
01740 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val,k);
01741 }
01742
01743 void
01744 ParmParse::getarr (const char* name,
01745 std::vector<float>& ptr,
01746 int start_ix,
01747 int num_val) const
01748 {
01749 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01750 }
01751
01752 int
01753 ParmParse::queryktharr (const char* name,
01754 int k,
01755 std::vector<float>& ptr,
01756 int start_ix,
01757 int num_val) const
01758 {
01759 return squeryarr(m_table, prefixedName(name),ptr,start_ix, num_val,k);
01760 }
01761
01762 int
01763 ParmParse::queryarr (const char* name,
01764 std::vector<float>& ptr,
01765 int start_ix,
01766 int num_val) const
01767 {
01768 return squeryarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01769 }
01770
01771
01772 void
01773 ParmParse::getkth (const char* name,
01774 int k,
01775 double& ptr,
01776 int ival) const
01777 {
01778 sgetval(m_table, prefixedName(name),ptr,ival,k);
01779 }
01780
01781 void
01782 ParmParse::get (const char* name,
01783 double& ptr,
01784 int ival) const
01785 {
01786 sgetval(m_table, prefixedName(name),ptr,ival, LAST);
01787 }
01788
01789 int
01790 ParmParse::querykth (const char* name,
01791 int k,
01792 double& ptr,
01793 int ival) const
01794 {
01795 return squeryval(m_table, prefixedName(name),ptr,ival,k);
01796 }
01797
01798 int
01799 ParmParse::query (const char* name,
01800 double& ptr,
01801 int ival) const
01802 {
01803 return squeryval(m_table, prefixedName(name),ptr,ival, LAST);
01804 }
01805
01806 void
01807 ParmParse::getktharr (const char* name,
01808 int k,
01809 std::vector<double>& ptr,
01810 int start_ix,
01811 int num_val) const
01812 {
01813 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val,k);
01814 }
01815
01816 void
01817 ParmParse::getarr (const char* name,
01818 std::vector<double>& ptr,
01819 int start_ix,
01820 int num_val) const
01821 {
01822 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01823 }
01824
01825 int
01826 ParmParse::queryktharr (const char* name,
01827 int k,
01828 std::vector<double>& ptr,
01829 int start_ix,
01830 int num_val) const
01831 {
01832 return squeryarr(m_table, prefixedName(name),ptr,start_ix, num_val,k);
01833 }
01834
01835 int
01836 ParmParse::queryarr (const char* name,
01837 std::vector<double>& ptr,
01838 int start_ix,
01839 int num_val) const
01840 {
01841 return squeryarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01842 }
01843
01844
01845 void
01846 ParmParse::getkth (const char* name,
01847 int k,
01848 std::string& ptr,
01849 int ival) const
01850 {
01851 sgetval(m_table, prefixedName(name),ptr,ival,k);
01852 }
01853
01854 void
01855 ParmParse::get (const char* name,
01856 std::string& ptr,
01857 int ival) const
01858 {
01859 sgetval(m_table, prefixedName(name),ptr,ival, LAST);
01860 }
01861
01862 int
01863 ParmParse::querykth (const char* name,
01864 int k,
01865 std::string& ptr,
01866 int ival) const
01867 {
01868 return squeryval(m_table, prefixedName(name),ptr,ival,k);
01869 }
01870
01871 int
01872 ParmParse::query (const char* name,
01873 std::string& ptr,
01874 int ival) const
01875 {
01876 return squeryval(m_table, prefixedName(name),ptr,ival, LAST);
01877 }
01878
01879 void
01880 ParmParse::getktharr (const char* name,
01881 int k,
01882 std::vector<std::string>& ptr,
01883 int start_ix,
01884 int num_val) const
01885 {
01886 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val,k);
01887 }
01888
01889 void
01890 ParmParse::getarr (const char* name,
01891 std::vector<std::string>& ptr,
01892 int start_ix,
01893 int num_val) const
01894 {
01895 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01896 }
01897
01898 int
01899 ParmParse::queryktharr (const char* name,
01900 int k,
01901 std::vector<std::string>& ptr,
01902 int start_ix,
01903 int num_val) const
01904 {
01905 return squeryarr(m_table, prefixedName(name),ptr,start_ix, num_val,k);
01906 }
01907
01908 int
01909 ParmParse::queryarr (const char* name,
01910 std::vector<std::string>& ptr,
01911 int start_ix,
01912 int num_val) const
01913 {
01914 return squeryarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01915 }
01916
01917
01918 void
01919 ParmParse::getkth (const char* name,
01920 int k,
01921 IntVect& ptr,
01922 int ival) const
01923 {
01924 sgetval(m_table, prefixedName(name),ptr,ival,k);
01925 }
01926
01927 void
01928 ParmParse::get (const char* name,
01929 IntVect& ptr,
01930 int ival) const
01931 {
01932 sgetval(m_table, prefixedName(name),ptr,ival, LAST);
01933 }
01934
01935 int
01936 ParmParse::querykth (const char* name,
01937 int k,
01938 IntVect& ptr,
01939 int ival) const
01940 {
01941 return squeryval(m_table, prefixedName(name),ptr,ival,k);
01942 }
01943
01944 int
01945 ParmParse::query (const char* name,
01946 IntVect& ptr,
01947 int ival) const
01948 {
01949 return squeryval(m_table, prefixedName(name),ptr,ival, LAST);
01950 }
01951
01952 void
01953 ParmParse::getktharr (const char* name,
01954 int k,
01955 std::vector<IntVect>& ptr,
01956 int start_ix,
01957 int num_val) const
01958 {
01959 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val,k);
01960 }
01961
01962 void
01963 ParmParse::getarr (const char* name,
01964 std::vector<IntVect>& ptr,
01965 int start_ix,
01966 int num_val) const
01967 {
01968 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01969 }
01970
01971 int
01972 ParmParse::queryktharr (const char* name,
01973 int k,
01974 std::vector<IntVect>& ptr,
01975 int start_ix,
01976 int num_val) const
01977 {
01978 return squeryarr(m_table, prefixedName(name),ptr,start_ix, num_val,k);
01979 }
01980
01981 int
01982 ParmParse::queryarr (const char* name,
01983 std::vector<IntVect>& ptr,
01984 int start_ix,
01985 int num_val) const
01986 {
01987 return squeryarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
01988 }
01989
01990
01991 void
01992 ParmParse::getkth (const char* name,
01993 int k,
01994 Box& ptr,
01995 int ival) const
01996 {
01997 sgetval(m_table, prefixedName(name),ptr,ival,k);
01998 }
01999
02000 void
02001 ParmParse::get (const char* name,
02002 Box& ptr,
02003 int ival) const
02004 {
02005 sgetval(m_table, prefixedName(name),ptr,ival, LAST);
02006 }
02007
02008 int
02009 ParmParse::querykth (const char* name,
02010 int k,
02011 Box& ptr,
02012 int ival) const
02013 {
02014 return squeryval(m_table, prefixedName(name),ptr,ival,k);
02015 }
02016
02017 int
02018 ParmParse::query (const char* name,
02019 Box& ptr,
02020 int ival) const
02021 {
02022 return squeryval(m_table, prefixedName(name),ptr,ival, LAST);
02023 }
02024
02025 void
02026 ParmParse::getktharr (const char* name,
02027 int k,
02028 std::vector<Box>& ptr,
02029 int start_ix,
02030 int num_val) const
02031 {
02032 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val,k);
02033 }
02034
02035 void
02036 ParmParse::getarr (const char* name,
02037 std::vector<Box>& ptr,
02038 int start_ix,
02039 int num_val) const
02040 {
02041 sgetarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
02042 }
02043
02044 int
02045 ParmParse::queryktharr (const char* name,
02046 int k,
02047 std::vector<Box>& ptr,
02048 int start_ix,
02049 int num_val) const
02050 {
02051 return squeryarr(m_table, prefixedName(name),ptr,start_ix, num_val,k);
02052 }
02053
02054 int
02055 ParmParse::queryarr (const char* name,
02056 std::vector<Box>& ptr,
02057 int start_ix,
02058 int num_val) const
02059 {
02060 return squeryarr(m_table, prefixedName(name),ptr,start_ix,num_val, LAST);
02061 }
02062
02063
02064
02065
02066
02067
02068 int
02069 ParmParse::countname (const std::string& name) const
02070 {
02071 int cnt = 0;
02072 for ( const_list_iterator li=m_table.begin(); li != m_table.end(); ++li )
02073 {
02074 if ( ppfound(prefixedName(name), *li, false) )
02075 {
02076 cnt++;
02077 }
02078 }
02079 return cnt;
02080 }
02081
02082 int
02083 ParmParse::countRecords (const std::string& name) const
02084 {
02085 int cnt = 0;
02086 for ( const_list_iterator li=m_table.begin(); li != m_table.end(); ++li )
02087 {
02088 if ( ppfound(prefixedName(name), *li, true) )
02089 {
02090 cnt++;
02091 }
02092 }
02093 return cnt;
02094 }
02095
02096
02097
02098
02099
02100 bool
02101 ParmParse::contains (const char* name) const
02102 {
02103 for ( const_list_iterator li = m_table.begin(); li != m_table.end(); ++li )
02104 {
02105 if ( ppfound(prefixedName(name), *li, false))
02106 {
02107
02108
02109
02110 for ( const_list_iterator lli = m_table.begin(); lli != m_table.end(); ++lli )
02111 {
02112 if ( ppfound(prefixedName(name), *lli, false) )
02113 {
02114 lli->m_queried = true;
02115 }
02116 }
02117 return true;
02118 }
02119 }
02120 return false;
02121 }
02122
02123 ParmParse::Record
02124 ParmParse::getRecord (const std::string& name, int n) const
02125 {
02126 const PP_entry* pe = ppindex(m_table, n, prefixedName(name), true);
02127 if ( pe == 0 )
02128 {
02129 std::cerr << "ParmParse::getRecord: record " << name << " not found" << std::endl;
02130 BoxLib::Abort();
02131 }
02132 return Record(ParmParse(*pe->m_table));
02133 }
02134
02135
02136
02137
02138
02139
02140 ParmParse::Record::Record ( const ParmParse& pp )
02141 : m_pp(pp)
02142 {
02143 }
02144
02145 const ParmParse*
02146 ParmParse::Record::operator-> () const
02147 {
02148 return &m_pp;
02149 }
02150
02151 const ParmParse&
02152 ParmParse::Record::operator* () const
02153 {
02154 return m_pp;
02155 }