acl/lib_acl_cpp/include/acl_cpp/stdlib/xml1.hpp

344 lines
5.6 KiB
C++
Raw Normal View History

#pragma once
#include "acl_cpp/acl_cpp_define.hpp"
#include <vector>
#include <list>
#include "acl_cpp/stdlib/string.hpp"
#include "acl_cpp/stdlib/pipe_stream.hpp"
#include "acl_cpp/stdlib/xml.hpp"
struct ACL_XML;
struct ACL_XML_NODE;
struct ACL_XML_ATTR;
/**
* <EFBFBD><EFBFBD> ACL <EFBFBD><EFBFBD><EFBFBD><EFBFBD> XML <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> C++ <EFBFBD>û<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>ʹ<EFBFBD>ø<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>ҷdz<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> ACL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* XML <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD>ǵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ACL <EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> XML <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD>ο<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD><EFBFBD><EFBFBD>΢Ӱ<EFBFBD><EFBFBD>һЩ<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>΢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
namespace acl {
class xml1;
class xml1_node;
class ACL_CPP_API xml1_attr : public xml_attr
{
public:
/**
* @override
*/
const char* get_name(void) const;
/**
* @override
*/
const char* get_value(void) const;
protected:
friend class xml1_node;
xml1_attr(xml_node* node, ACL_XML_ATTR* attr);
~xml1_attr(void) {}
private:
ACL_XML_ATTR* attr_;
};
class ACL_CPP_API xml1_node : public xml_node
{
public:
/**
* @override
*/
const char* tag_name(void) const;
/**
* @override
*/
const char* id(void) const;
/**
* @override
*/
const char* text(void) const;
/**
* @override
*/
const char* attr_value(const char* name) const;
/**
* @override
*/
const xml_attr* first_attr(void) const;
/**
* @override
*/
const xml_attr* next_attr(void) const;
/**
* @override
*/
xml_node& add_attr(const char* name, const char* value);
/**
* @override
*/
xml_node& set_text(const char* str, bool append = false);
/**
* @override
*/
xml_node& set_text(istream& in, size_t off = 0, size_t len = 0);
/**
* @override
*/
xml_node& add_child(xml_node* child, bool return_child = false);
/**
* @override
*/
int detach(void);
/**
* @override
*/
xml_node& set_parent(xml_node* node);
/**
* @override
*/
xml_node& get_parent(void) const;
/**
* @override
*/
xml_node* first_child(void);
/**
* @override
*/
xml_node* next_child(void);
/**
* @override
*/
int depth(void) const;
2015-12-12 23:00:03 +08:00
/**
* @override
*/
bool is_root(void) const;
/**
* @override
*/
int children_count(void) const;
public:
/**
* ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD> ACL <EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> XML <EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {ACL_XML_NODE*} <EFBFBD><EFBFBD><EFBFBD>ؽڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>ýڵ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
*/
ACL_XML_NODE* get_xml_node(void) const;
protected:
friend class xml1;
friend class dbuf_guard;
/**
* xml <EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD>
* @param xml_ptr {xml*} xml <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬷ǿ<EFBFBD>
* @param node {ACL_XML_NODE*} C <EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> xml <EFBFBD>ڵ<EFBFBD>ָ<EFBFBD><EFBFBD>
*/
xml1_node(xml* xml_ptr, ACL_XML_NODE* node);
/**
* Ҫ<EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
~xml1_node(void);
private:
ACL_XML_NODE *node_;
ACL_ITER* child_iter_;
ACL_ITER* attr_iter_;
xml_node* parent_;
xml1_node* parent_internal_;
};
class string;
class ACL_CPP_API xml1 : public xml
{
public:
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param data {const char*} xml <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* xml <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><EFBFBD>ֵ<EFBFBD> xml <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ָ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xml <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> update
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD> update <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD> xml<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> data <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> update
2016-04-30 11:49:41 +08:00
* @param dbuf_nblock {size_t} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dbuf_capacity {size_t} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
2016-04-30 11:49:41 +08:00
xml1(const char* data = NULL, size_t dbuf_nblock = 2,
size_t dbuf_capacity = 100);
~xml1(void);
/**
* @override
*/
xml& ignore_slash(bool on);
/**
* @override
*/
xml& xml_decode(bool on);
/**
* @override
*/
xml& xml_encode(bool on);
/**
* @override
*/
xml& xml_multi_root(bool on);
/**
* @override
*/
void update(const char* data);
/**
* @override
*/
bool complete(const char* root_tag);
/**
* @override
*/
void reset(void);
/**
* @override
*/
const string& getText(void);
/**
* @override
*/
const std::vector<xml_node*>&
getElementsByTagName(const char* tag) const;
/**
* @override
*/
xml_node* getFirstElementByTag(const char* tag) const;
/**
* @override
*/
const std::vector<xml_node*>& getElementsByTags(const char* tags) const;
/**
* @override
*/
xml_node* getFirstElementByTags(const char* tags) const;
/**
* @override
*/
const std::vector<xml_node*>&
getElementsByName(const char* value) const;
/**
* @override
*/
const std::vector<xml_node*>& getElementsByAttr(
const char* name, const char* value) const;
/**
* @override
*/
xml_node* getElementById(const char* id) const;
/**
* @override
*/
xml_node& create_node(const char* tag, const char* text = NULL);
/**
* @override
*/
xml_node& create_node(const char* tag, istream& in,
size_t off = 0, size_t len = 0);
/**
* @override
*/
xml_node& get_root(void);
/**
* @override
*/
xml_node* first_node(void);
/**
* @override
*/
xml_node* next_node(void);
/**
* @override
*/
void build_xml(string& out) const;
/**
* @override
*/
const char* to_string(size_t* len = NULL) const;
/**
* @override
*/
size_t space(void) const;
/**
* @override
*/
void space_clear(void);
/**
* @override
*/
size_t node_count(void) const;
/**
* @override
*/
size_t attr_count(void) const;
public:
/**
* ȡ<EFBFBD><EFBFBD> acl <EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> ACL_XML <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {ACL_XML*} <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĸö<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷŸö<EFBFBD><EFBFBD><EFBFBD>
*/
ACL_XML* get_xml(void) const
{
return xml_;
}
private:
ACL_XML *xml_;
ACL_ITER* iter_;
xml1_node* root_;
};
} // namespace acl