virtual ~ParameterHandler ();
/**
- * Read input from a stream until stream returns <tt>eof</tt> condition
- * or error.
+ * Read input from a stream until the stream returns the <tt>eof</tt> condition
+ * or error. The second argument can be used to denote the name of the file
+ * (if that's what the input stream represents) we are reading from; this
+ * is only used when creating output for error messages.
*
* Return whether the read was successful.
*/
- virtual bool read_input (std::istream &input);
+ virtual bool read_input (std::istream &input,
+ const std::string &filename = "input file");
/**
* Read input from a file the name of which is given. The PathSearch
std::string get_current_full_path (const std::string &name) const;
/**
- * Scan one line of input. <tt>lineno</tt> is the number of the line
+ * Scan one line of input. <tt>input_filename</tt> and <tt>lineno</tt>
+ * are the name of the input file and the current number of the line
* presently scanned (for the logs if there are messages). Return
* <tt>false</tt> if line contained stuff that could not be understood,
* the uppermost subsection was to be left by an <tt>END</tt> or
* caller's variable is not changed.
*/
bool scan_line (std::string line,
+ const std::string &input_filename,
const unsigned int lineno);
friend class MultipleParameterLoop;
-bool ParameterHandler::read_input (std::istream &input)
+bool ParameterHandler::read_input (std::istream &input,
+ const std::string &filename)
{
AssertThrow (input, ExcIO());
{
++lineno;
getline (input, line);
- status &= scan_line (line, lineno);
+ status &= scan_line (line, filename, lineno);
}
return status;
std::ifstream input (openname.c_str());
AssertThrow(input, ExcIO());
- return read_input (input);
+ return read_input (input, filename);
}
catch (const PathSearch::ExcFileNotFound &)
{
// create an istringstream representation and pass it off
// to the other functions doing this work
std::istringstream in (s);
- return read_input (in);
+ return read_input (in, "input string");
}
bool
-ParameterHandler::scan_line (std::string line,
- const unsigned int lineno)
+ParameterHandler::scan_line (std::string line,
+ const std::string &input_filename,
+ const unsigned int lineno)
{
// if there is a comment, delete it
if (line.find('#') != std::string::npos)
// check whether subsection exists
if (!entries->get_child_optional (get_current_full_path(subsection)))
{
- std::cerr << "Line " << lineno
- << ": There is no such subsection to be entered: "
+ std::cerr << "Line <" << lineno
+ << "> of file <" << input_filename
+ << ">: There is no such subsection to be entered: "
<< demangle(get_current_full_path(subsection)) << std::endl;
for (unsigned int i=0; i<subsection_path.size(); ++i)
std::cerr << std::setw(i*2+4) << " "
{
if (subsection_path.size() == 0)
{
- std::cerr << "Line " << lineno
- << ": There is no subsection to leave here!" << std::endl;
+ std::cerr << "Line <" << lineno
+ << "> of file <" << input_filename
+ << ">: There is no subsection to leave here!" << std::endl;
return false;
}
else
= entries->get<unsigned int> (get_current_full_path(entry_name) + path_separator + "pattern");
if (!patterns[pattern_index]->match(entry_value))
{
- std::cerr << "Line " << lineno << ":" << std::endl
+ std::cerr << "Line <" << lineno
+ << "> of file <" << input_filename
+ << ">:" << std::endl
<< " The entry value" << std::endl
<< " " << entry_value << std::endl
<< " for the entry named" << std::endl
}
else
{
- std::cerr << "Line " << lineno
- << ": No such entry was declared:" << std::endl
+ std::cerr << "Line <" << lineno
+ << "> of file <" << input_filename
+ << ">: No such entry was declared:" << std::endl
<< " " << entry_name << std::endl
<< " <Present subsection:" << std::endl;
for (unsigned int i=0; i<subsection_path.size(); ++i)
}
// this line matched nothing known
- std::cerr << "Line " << lineno
- << ": This line matched nothing known ('set' or 'subsection' missing!?):" << std::endl
+ std::cerr << "Line <" << lineno
+ << "> of file <" << input_filename
+ << ">: This line matched nothing known ('set' or 'subsection' missing!?):" << std::endl
<< " " << line << std::endl;
return false;
}