/************************************************************************* Copyright Rice University, 2004. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder. **************************************************************************/ #include "table.hh" namespace RVL { Table::Table(string fname,string prefix_str) : prefixes(prefix_str) { try { if (fname!="") { if (mergeFile(fname)) { RVLException e; e<<"error: Table constructor from Table::Merge\n"; e<<"failed to merge data from file \""<table.size()) { cerr<<"warning: Table::getKey: index greater than table size"; return ""; } else { const_iterator it = table.begin(); for (unsigned iter=0;iter<=i;++iter) ++it; return it->first; } } string Table::strValue(string key) { const_iterator it(table.find(key)),end_it(table.end()); if (it==end_it) { cerr<<"warning: Table::getValue: key \"" <second; } int Table::getValue(string key, int & value) const { const_iterator it(table.find(key)),end_it(table.end()); if (it==end_it) return 1; istringstream inputString(it->second); inputString>>value; return 0; } int Table::getValue(string key, double & value) const { const_iterator it(table.find(key)),end_it(table.end()); if (it==end_it) return 1; istringstream inputString(it->second); inputString>>value; return 0; } int Table::getValue(string key, float & value) const { const_iterator it(table.find(key)),end_it(table.end()); if (it==end_it) return 1; istringstream inputString(it->second); inputString>>value; return 0; } int Table::getValue(string key, string & value, int length) const { const_iterator it(table.find(key)),end_it(table.end()); if (it==end_it) return 1; if (length>0) { int len=(it->second).length(); if (lengthsecond,0,length); } else value.assign(it->second); return 0; } value.assign(it->second); return 0; } void Table::putValue(string key, int value) { ostringstream outputString; outputString<line.length()) { unsigned cur = line.find_first_of("="); subline = line.substr(0,cur); line = line.substr(cur+1,line.length()); table.insert(value_type(subline,stripWord(line))); } } else { // Read in only those parameters pertaining to the object // identified by the prefix if (line.find("::")!=string::npos) { unsigned pos = line.find_first_of(":"); subline = line.substr(0,pos); if (prefixes.find(subline)!=string::npos) { // prefixes.resize(prefixes.length()+subline.length()); // prefixes.append(subline); prefixes.append(" "); unsigned cur = line.find_first_of("="); subline = line.substr(pos+2, cur-pos-2); line = line.substr(cur+1, line.length()); table.insert(value_type(subline,stripWord(line))); } } } } else if (!line.empty()) { cerr<<"warning: Table::merge skipped line #"<first<<" = "<second<0)) last--; if (first>last) return( "" ); else return (word.substr(first,last-first+1)); } bool Table::isPunct(char c) { char punct[] = {' ',',',';',':','!','(',')','"','\''}; const int num_of_punct = sizeof(punct)/sizeof(char); for (int i=0;i < num_of_punct;i++) if (c==punct[i]) return (true); return false; } template Scalar getValueFromTable(Table const & tbl, string key) { RVLException e; e<<"Error: getValueFromTable\n"; e<<"unknown type"; throw e; } template<> int getValueFromTable(Table const & tbl, string key) { int t; if (tbl.getValue(key,t)) { RVLException e; e<<"Error: getValueFromTable (int) key = "< double getValueFromTable(Table const & tbl, string key) { double t; if (tbl.getValue(key,t)) { RVLException e; e<<"Error: getValueFromTable (double) key = "< float getValueFromTable(Table const & tbl, string key) { float t; if (tbl.getValue(key,t)) { RVLException e; e<<"Error: getValueFromTable (float) key = "< string getValueFromTable(Table const & tbl, string key) { string t; if (tbl.getValue(key,t)) { RVLException e; e<<"Error: getValueFromTable (string) key = "< bool getValueFromTable(Table const & tbl, string key) { int t; if (tbl.getValue(key,t)) { RVLException e; e<<"Error: getValueFromTable (int) key = "<