Beispiel #1
0
    void handle_start(const std::string &name, const attribute_vector &attributes) 
    {
      if (current_node.get() == nullptr) {
	current_node = std::make_shared<xml_node>();
	document = current_node;
      } else {
	node_stack.push_back(current_node);
	current_node = std::make_shared<xml_node>();
      }
      std::string node_name, node_ns(""), node_ns_uri("");
      if (namespaces.size() > 0) {
	for (namespace_pair ns : namespaces) {
	  if (name.find(ns.second) != std::string::npos) {
	    node_ns = ns.first;
	    node_ns_uri = ns.second;
	    node_name = name.substr(node_ns_uri.length() + 1);
	    break;
	  }
	}
      } else {
	node_name = name;
      }
      current_node->set_name(node_name);
      current_node->set_namespace(node_ns);
      current_node->set_namespace_uri(node_ns_uri);
      for (attribute_pair attribute : attributes) {
	current_node->set_attribute(attribute.first, attribute.second);
      }
    }
Beispiel #2
0
    node_pointer get_document() throw(std::string)
    {
      if (document.get() == nullptr) {
	expat_engine.parse();
      }
      if (document.get() == nullptr) {
	throw std::string(nullptr);
      }
      return document;
    }
Beispiel #3
0
 /**
  * \brief Recompute the bounding box
  */
 void adjust_box(node_pointer const& node)
 {
     unsigned int index = 0;
     for (typename node_map::iterator it = m_nodes.begin();
          it != m_nodes.end(); ++it, index++)
     {
         if (it->second.get() == node.get())
         {
             m_nodes[index] = std::make_pair(node->compute_box(), node);
             return;
         }
     }
 }
Beispiel #4
0
    /**
     * \brief Replace the node in the m_nodes vector and recompute the box
     */
    void replace_node(node_pointer const& leaf, node_pointer& new_leaf)
    {
        unsigned int index = 0;
        for(typename node_map::iterator it = m_nodes.begin(); it != m_nodes.end(); ++it, index++)
        {
            if (it->second.get() == leaf.get())
            {
                m_nodes[index] = std::make_pair(new_leaf->compute_box(), new_leaf);
                new_leaf->update_parent(new_leaf);
                return;
            }
        }

        // TODO: mloskot - define & use GGL exception
        throw std::logic_error("Node not found.");
    }
Beispiel #5
0
    void add(node_pointer p)
    {
        int x0 = (p->x1 + p->x2) / 2, y0 = (p->y1 + p->y2) / 2;

        p->sum += s;
        if (x != x0 || y != y0) {
            add(p->get_p(get_dir(x - x0, y - y0)));
        }
        else {
            p->cnt += s;
        }
    }
Beispiel #6
0
    void handle_end(const std::string &name)
    {
      // If the XML is mal-formed, engine will complain about it
      // in get_document. So we can pretty much just ignore name.
      
      notify(current_node);
      node_pointer last_node = current_node;
      if (node_stack.size() > 0) {
	current_node = node_stack.back();
	node_stack.pop_back();
	current_node->add_child(last_node);
      } // Otherwise that's it, document's done.
    }
Beispiel #7
0
    /**
     * \brief Box projector for node pointed by 'leaf'
     */
    virtual Box get_box(node_pointer const& leaf) const
    {
        for (typename node_map::const_iterator it = m_nodes.begin();
             it != m_nodes.end(); ++it)
        {
            if (it->second.get() == leaf.get())
            {
                return it->first;
            }
        }

        // TODO: mloskot - define & use GGL exception
        throw std::logic_error("Node not found");
    }
Beispiel #8
0
 /**
  * \brief Add a child to this node
  */
 virtual void add_node(Box const& box, node_pointer const& node)
 {
     m_nodes.push_back(std::make_pair(box, node));
     node->update_parent(node);
 }
Beispiel #9
0
 ~node_engine()
 {
   document.reset();
 }
Beispiel #10
0
 void handle_text(const std::string &text)
 {
   current_node->set_text(text);
 }