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

#include <XMLImporter.h>

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

List of all members.

Public Member Functions

 XMLImporter ()
virtual ~XMLImporter ()

Protected Member Functions

template<typename T >
parse_number (const xmlpp::Element *const node, std::string const &attribute_str) const
 Parse a string and convert it to a number (e.g.
template<typename T >
parse_number (const xmlpp::Element *const node, std::string const &attribute_str, T default_value)
 Parse a string and convert it to a number (e.g.
const xmlpp::Element * get_dom_twig (const xmlpp::Element *const start_node, std::string const &element_name) const
color_t parse_color_string (std::string const &color_string) const
 Parse a HTML RGBA color description, e.g.

Detailed Description

Definition at line 32 of file XMLImporter.h.


Constructor & Destructor Documentation

Definition at line 82 of file XMLImporter.h.

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

Definition at line 83 of file XMLImporter.h.

{};

Member Function Documentation

const xmlpp::Element * XMLImporter::get_dom_twig ( const xmlpp::Element *const  start_node,
std::string const &  element_name 
) const [protected]

Definition at line 38 of file XMLImporter.cc.

                                                                                                                          {
  xmlpp::Node::NodeList node_list = start_node->get_children(element_name);
  if(!node_list.empty()) {
    const xmlpp::Element * element = dynamic_cast<const xmlpp::Element*>(node_list.front());
    return element;
  }
  return NULL;
}
color_t XMLImporter::parse_color_string ( std::string const &  color_string) const [protected]

Parse a HTML RGBA color description, e.g.

'#23FF42A0'.

Returns:
Returns the internally used color code. If the string can't be parsed a value of 0 (black) is returned.

Definition at line 48 of file XMLImporter.cc.

References MERGE_CHANNELS.

                                                                           {
  const unsigned int correct_length = 1 + 4 * 2;
  if(color_string.size() != correct_length) return 0;

  int r = 0;
  int g = 0;
  int b = 0;
  int a = 0;

  std::istringstream iss_r(color_string.substr(1, 2));
  std::istringstream iss_g(color_string.substr(3, 2));
  std::istringstream iss_b(color_string.substr(5, 2));
  std::istringstream iss_a(color_string.substr(7, 2));

  iss_r >> std::hex >> r;
  iss_g >> std::hex >> g;
  iss_b >> std::hex >> b;
  iss_a >> std::hex >> a;

  return MERGE_CHANNELS(r,g,b,a);
}
template<typename T >
T degate::XMLImporter::parse_number ( const xmlpp::Element *const  node,
std::string const &  attribute_str 
) const [inline, protected]

Parse a string and convert it to a number (e.g.

double, long, unsigned int, ...).

Exceptions:
InvalidPointerExceptionis thrown, if you node is a NULL pointer.
XMLAttributeMissingExceptionThe XML attribute is not present.
Returns:
Returns the number in type T.

Definition at line 45 of file XMLImporter.h.

                                                                                          {

    assert(node != NULL);
    if(node == NULL) throw InvalidPointerException("Parameter must be != NULL.");

    if(node->get_attribute(attribute_str) == NULL) {
      throw XMLAttributeMissingException(std::string("attribute is not present: ") + attribute_str);
    }
    else return parse_number<T>(node->get_attribute_value(attribute_str));
  }
template<typename T >
T degate::XMLImporter::parse_number ( const xmlpp::Element *const  node,
std::string const &  attribute_str,
default_value 
) [inline, protected]

Parse a string and convert it to a number (e.g.

double, long, unsigned int, ...).

Exceptions:
InvalidPointerExceptionis thrown, if you node is a NULL pointer.
Returns:
Returns the number in type T. If the XML attribute is not present, the default value is returned.

Definition at line 63 of file XMLImporter.h.

                                                                                                     {

    assert(node != NULL);
    if(node == NULL) throw InvalidPointerException();

    if(node->get_attribute(attribute_str) == NULL) return default_value;
    else return parse_number<T>(node->get_attribute_value(attribute_str));
  }

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