|
degate 0.1.1
|
The base class for importers that can parse text files. More...
#include <Importer.h>

Public Member Functions | |
| Importer () | |
| Create a new text importer object. | |
| virtual | ~Importer () |
| Destroy a text importer object. | |
Protected Member Functions | |
| virtual ret_t | check_file (std::string const &filename) const |
| Check if the file exists and can be read. | |
| virtual bool | parse_bool (std::string const &str) const |
| Parse a string that represents a boolean value, that is "true" or "false". | |
| template<typename T > | |
| T | parse_number (std::string const &str) const |
| Parse a string that represents a number. | |
The base class for importers that can parse text files.
Definition at line 37 of file Importer.h.
| degate::Importer::Importer | ( | ) | [inline] |
| virtual degate::Importer::~Importer | ( | ) | [inline, virtual] |
| ret_t Importer::check_file | ( | std::string const & | filename | ) | const [protected, virtual] |
Check if the file exists and can be read.
Definition at line 39 of file Importer.cc.
References debug(), degate::is_file(), degate::RET_ERR, degate::RET_OK, and TM.
{
if(is_file(filename)) {
return RET_OK;
}
else {
debug(TM, "Can't open file %s", filename.c_str());
return RET_ERR;
}
}

| bool Importer::parse_bool | ( | std::string const & | str | ) | const [protected, virtual] |
Parse a string that represents a boolean value, that is "true" or "false".
| std::invalid_argument | The exception is thrown, if the string can not be parsed. |
Definition at line 51 of file Importer.cc.
{
if(str == "true" || str == "enabled") return true;
else if(str == "false" || str == "disabled") return false;
else {
debug(TM, "invalid attribute value '%s'", str.c_str());
throw std::invalid_argument("Can't parse string as a boolean value.");
}
}

| T degate::Importer::parse_number | ( | std::string const & | str | ) | const [inline, protected] |
Parse a string that represents a number.
| XMLAttributeParseException | This exception is thrown, if the string can't be parsed. |
Definition at line 59 of file Importer.h.
{
std::stringstream strm(str);
T v;
strm >> v;
if(!strm) {
boost::format f("Can't parse number in Importer::parse_number(). Value is %1%");
f % str;
throw XMLAttributeParseException(f.str());
}
else return v;
}
1.7.4