////////////////////////////////////////////////////////////////
- class element_;
+ template <typename STRTYPE=::std::string>
+ struct element_;
+ template <typename STRTYPE=::std::string>
class node_list
{
+ public:
+ typedef element_<STRTYPE> element_t;
+ typedef attribute_<STRTYPE> attribute_t;
+ typedef text_<STRTYPE> text_t;
+ typedef comment_<STRTYPE> comment_t;
private:
- ::std::vector<attribute> &m_attr_pool;
- ::std::vector<comment> &m_comment_pool;
- ::std::vector<text> &m_text_pool;
- ::std::vector<element> &m_element_pool;
+ ::std::vector<element_t> &m_element_pool;
+ ::std::vector<attribute_t> &m_attr_pool;
+ ::std::vector<text_t> &m_text_pool;
+ ::std::vector<comment_t> &m_comment_pool;
::std::vector<node*> m_node_list;
}
public:
node_list(
- ::std::vector<attribute> &attr_pool,
- ::std::vector<comment> &comment_pool,
- ::std::vector<text> &text_pool,
- ::std::vector<element> &element_pool)
+ ::std::vector<element_t> &element_pool,
+ ::std::vector<attribute_t> &attr_pool,
+ ::std::vector<text_t> &text_pool,
+ ::std::vector<comment_t> &comment_pool)
:
+ m_element_pool(element_pool),
m_attr_pool(attr_pool),
- m_comment_pool(comment_pool),
m_text_pool(text_pool),
- m_element_pool(element_pool){}
+ m_comment_pool(comment_pool)
+ {}
///////////////////////////
- element* get_root_element()
+ element_t* get_root_element()
{
for(size_t i=0; i<m_node_list.size(); i++)
{
///////////////////////////////////////////////////
- void append_text(const text& n){ m_text_pool.push_back(n); m_node_list.push_back(&m_text_pool.back()); }
- void append_comment(const comment& n){ m_comment_pool.push_back(n); m_node_list.push_back(&m_comment_pool.back()); }
- element& append_element(const element& n){ m_element_pool.push_back(n); m_node_list.push_back(&m_element_pool.back()); return m_element_pool.back(); }
+ void append_text(const text_t& n){ m_text_pool.push_back(n); m_node_list.push_back(&m_text_pool.back()); }
+ void append_comment(const comment_t& n){ m_comment_pool.push_back(n); m_node_list.push_back(&m_comment_pool.back()); }
+ element_t& append_element(const element_t& n){ m_element_pool.push_back(n); m_node_list.push_back(&m_element_pool.back()); return m_element_pool.back(); }
};
////////////////
// element
- template <typename STRTYPE=::std::string>
- struct element_ : public node, public node_list
+ template <typename STRTYPE/*=::std::string*/>
+ struct element_ : public node, public node_list<STRTYPE>
{
STRTYPE name;
- element_() : node(TYPE_ELEMENT){}
- element_(const STRTYPE &s) : node(TYPE_ELEMENT), name(s){}
+ element_(
+ ::std::vector<element_t> &element_pool,
+ ::std::vector<attribute_t> &attr_pool,
+ ::std::vector<text_t> &text_pool,
+ ::std::vector<comment_t> &comment_pool) : node(TYPE_ELEMENT),
+ node_list<STRTYPE>(m_element_pool, m_attr_pool, m_text_pool, m_comment_pool){}
+ element_(
+ ::std::vector<element_t> &element_pool,
+ ::std::vector<attribute_t> &attr_pool,
+ ::std::vector<text_t> &text_pool,
+ ::std::vector<comment_t> &comment_pool,
+ const STRTYPE &s) : node(TYPE_ELEMENT), name(s),
+ node_list<STRTYPE>(m_element_pool, m_attr_pool, m_text_pool, m_comment_pool){}
};
typedef element_<> element;
/////////////////////////////////////////////////
- class document : public node_list
+ template <typename STRTYPE=::std::string>
+ class document_ : public node_list<STRTYPE>
{
private:
- ::std::vector<attribute> m_attr_pool;
- ::std::vector<comment> m_comment_pool;
- ::std::vector<text> m_text_pool;
- ::std::vector<element> m_element_pool;
+ ::std::vector<element_<STRTYPE> > m_element_pool;
+ ::std::vector<attribute_<STRTYPE> > m_attr_pool;
+ ::std::vector<text_<STRTYPE> > m_text_pool;
+ ::std::vector<comment_<STRTYPE> > m_comment_pool;
public:
- document() : node_list(m_attr_pool, m_comment_pool, m_text_pool, m_element_pool){}
+ document_() : node_list(m_element_pool, m_attr_pool, m_text_pool, m_comment_pool){}
};
+ typedef document_<> document;
////////////////////////////////////////////////////////////////
+ template <typename STRTYPE=::std::string>
class dom_parser_by_sax_impl
{
protected:
- document &m_doc;
- ::std::stack<node_list*> m_now_nl_stack;
+ document_<STRTYPE> &m_doc;
+ ::std::stack<node_list<STRTYPE> *> m_now_nl_stack;
+
+ typedef element_<STRTYPE> element_t;
+ typedef attribute_<STRTYPE> attribute_t;
+ typedef text_<STRTYPE> text_t;
+ typedef comment_<STRTYPE> comment_t;
+ typedef node_list<STRTYPE> node_list_t;
public:
dom_parser_by_sax_impl(document &doc) : m_doc(doc)
{
- m_now_nl_stack.push((node_list*)this);
+ m_now_nl_stack.push((node_list_t*)this);
}
virtual ~dom_parser_by_sax_impl()
{
}
void comment( const sized_ccharbuf &s ){}
- void text( const sized_ccharbuf &s ){ m_doc.append_text(roast_xml::text(s.to_string())); }
+ void text( const sized_ccharbuf &s ){ m_doc.append_text(text_t(s.to_string())); }
void start_element( const sized_ccharbuf &s )
{
- element e& = m_now_nl_stack.top()->append_element(
- roast_xml::element(s.to_string())
- );
+ element_t &e = m_now_nl_stack.top()->append_element(element_t(s.to_string()));
m_now_nl_stack.push(&e);
}
void end_element(){ m_now_nl_stack.pop(); }
document dom_parse(_It it)
{
document doc;
- dom_parser_by_sax_impl parser(doc);
+ dom_parser_by_sax_impl<> parser(doc);
sax(it, parser);
return doc;
}