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

313 lines
5.5 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/xml.hpp"
struct ACL_XML2;
struct ACL_XML2_NODE;
struct ACL_XML2_ATTR;
namespace acl {
class xml2;
class xml2_node;
class ACL_CPP_API xml2_attr : public xml_attr
{
public:
/**
* @override
* @return {const char*}
*/
const char* get_name() const;
/**
* @override
* @return {const char*}
*/
const char* get_value() const;
protected:
friend class xml2_node;
xml2_attr(xml_node* node, ACL_XML2_ATTR* attr);
~xml2_attr(void) {}
private:
ACL_XML2_ATTR* attr_;
};
class ACL_CPP_API xml2_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);
/**
* @override
*/
xml_node& add_child(xml_node* child, bool return_child = false);
/**
* @override
*/
int detach(void);
/**
* @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
* @return {bool}
*/
bool is_root(void) const;
/**
* @override
*/
int children_count(void) const;
public:
void set_xml2_node(ACL_XML2_NODE* node);
ACL_XML2_NODE* get_xml_node(void) const;
xml_node& set_parent(xml_node* node);
protected:
friend class xml2;
xml2_node(xml* xml_ptr, ACL_XML2_NODE* node);
~xml2_node(void);
private:
ACL_XML2_NODE *node_;
ACL_ITER* child_iter_;
ACL_ITER* attr_iter_;
xml_node* parent_;
xml2_node* parent_internal_;
};
class fstream;
class ACL_CPP_API xml2 : public xml
{
public:
/**
* <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>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param addr {char*} <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>
* @param size {size_t} addr <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>
* @param data {const char*} <EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
xml2(char* addr, size_t size, const char* data = NULL);
/**
* <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><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param filepath {const char*} <EFBFBD>ڴ<EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} <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>С
* @param data {const char*} <EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param block {size_t} <EFBFBD>ڴ<EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD>С
* @param keep_open {bool} <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>
*/
xml2(const char* filepath, size_t size, const char* data = NULL,
size_t block = 8192, bool keep_open = true);
/**
* <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><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param fp {fstream&} <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><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD> fp <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xml <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷź<EFBFBD><EFBFBD>ſ<EFBFBD><EFBFBD>Թر<EFBFBD>
* @param size {size_t} <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>С
* @param data {const char*} <EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param block {size_t} <EFBFBD>ڴ<EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD>С
*/
xml2(fstream& fp, size_t size, const char* data = NULL,
size_t block = 8192);
/**
* <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><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param fd {ACL_FILE_HANDLE} <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><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD> fp <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xml <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷź<EFBFBD><EFBFBD>ſ<EFBFBD><EFBFBD>Թر<EFBFBD>
* @param size {size_t} <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>С
* @param data {const char*} <EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param block {size_t} <EFBFBD>ڴ<EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD>С
*/
#if defined(_WIN32) || defined(_WIN64)
xml2(void* fd, size_t size, const char* data = NULL,
size_t block = 8192);
#else
xml2(int fd, size_t size, const char* data = NULL,
size_t block = 8192);
#endif
~xml2(void);
/**
* @override
*/
xml& ignore_slash(bool on);
/**
* @override
*/
xml& xml_decode(bool on);
/**
* @override
*/
void update(const char* data);
/**
* @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& 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;
public:
ACL_XML2* get_xml2(void) const
{
return xml_;
}
private:
ACL_XML2* xml_;
ACL_ITER* iter_;
xml2_node* root_;
};
} // namespace acl