degate  0.1.2
Public Member Functions | Protected Member Functions
degate::Importer Class Reference

The base class for importers that can parse text files. More...

#include <Importer.h>

Inheritance diagram for degate::Importer:
Inheritance graph
[legend]

List of all members.

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 >
parse_number (std::string const &str) const
 Parse a string that represents a number.

Detailed Description

The base class for importers that can parse text files.

Definition at line 37 of file Importer.h.


Constructor & Destructor Documentation

Create a new text importer object.

Definition at line 76 of file Importer.h.

{}
virtual degate::Importer::~Importer ( ) [inline, virtual]

Destroy a text importer object.

Definition at line 81 of file Importer.h.

{}

Member Function Documentation

ret_t Importer::check_file ( std::string const &  filename) const [protected, virtual]

Check if the file exists and can be read.

Returns:
Returns RET_OK if the file can be read.
Todo:
Change the return type tool bool.

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;
  }
}

Here is the call graph for this function:

bool Importer::parse_bool ( std::string const &  str) const [protected, virtual]

Parse a string that represents a boolean value, that is "true" or "false".

Returns:
Returns a C++ bool, depending on the parsed string.
Exceptions:
std::invalid_argumentThe exception is thrown, if the string can not be parsed.

Definition at line 51 of file Importer.cc.

References debug(), and TM.

                                                     {
  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.");
  }
}

Here is the call graph for this function:

template<typename T >
T degate::Importer::parse_number ( std::string const &  str) const [inline, protected]

Parse a string that represents a number.

Exceptions:
XMLAttributeParseExceptionThis 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;
    }

The documentation for this class was generated from the following files: