예제 #1
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;
    }
예제 #2
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);
      }
    }
예제 #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;
         }
     }
 }
예제 #4
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");
    }
예제 #5
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.");
    }