2019-07-28 10:31:56 +08:00
|
|
|
|
#pragma once
|
2018-08-19 15:31:26 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2019-05-09 13:57:51 +08:00
|
|
|
|
#include "noncopyable.hpp"
|
2018-08-19 15:31:26 +08:00
|
|
|
|
#include "string.hpp"
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
|
|
struct ACL_TOKEN;
|
|
|
|
|
struct ACL_ITER;
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class token_tree;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* 256 <EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĽڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>˽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
2019-05-09 13:57:51 +08:00
|
|
|
|
class ACL_CPP_API token_node : public noncopyable
|
2018-08-19 15:31:26 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>øýڵ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ļ<EFBFBD>ֵ
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2018-08-20 22:28:27 +08:00
|
|
|
|
const char* get_key(void) const;
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>øýڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {void*}
|
|
|
|
|
*/
|
|
|
|
|
void* get_ctx(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>øýڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {token_tree*}
|
|
|
|
|
*/
|
|
|
|
|
token_tree* get_tree(void) const
|
|
|
|
|
{
|
|
|
|
|
return tree_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> C <EFBFBD>汾<EFBFBD>Ľڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {ACL_TOKEN*}
|
|
|
|
|
*/
|
|
|
|
|
ACL_TOKEN* get_token(void) const
|
|
|
|
|
{
|
|
|
|
|
return me_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2019-07-28 10:31:56 +08:00
|
|
|
|
friend class token_tree; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> token_tree <20><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
token_node(void);
|
|
|
|
|
~token_node(void);
|
|
|
|
|
|
|
|
|
|
void set_node(ACL_TOKEN* token, token_tree* tree);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ACL_TOKEN* me_;
|
|
|
|
|
token_tree* tree_;
|
|
|
|
|
string key_;
|
2018-08-20 22:28:27 +08:00
|
|
|
|
bool dirty_;
|
2018-08-19 15:31:26 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* 256 <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>)<EFBFBD><EFBFBD>
|
|
|
|
|
* ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>䵽 256 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
2019-05-09 13:57:51 +08:00
|
|
|
|
class ACL_CPP_API token_tree : public noncopyable
|
2018-08-19 15:31:26 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
token_tree(void);
|
|
|
|
|
~token_tree(void);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param key {const char*} <EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @param ctx {void*} <EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ key <EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
|
|
|
|
bool insert(const char* key, void* ctx = NULL);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD>
|
|
|
|
|
* @param key {const char*} <EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @return {void*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
|
|
|
|
void* remove(const char* key);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>ֵ<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD>Ľڵ<EFBFBD>
|
|
|
|
|
* @param key {const char*} <EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @return {const token_node*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD>ʾδ<EFBFBD>ҵ<EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
2018-08-20 11:07:20 +08:00
|
|
|
|
const token_node* find(const char* key);
|
2018-08-19 15:31:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <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 text {const 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>
|
|
|
|
|
* @param delimiters {const char*} <EFBFBD><EFBFBD> NULL ʱָ<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 delimiters_tab {const char*} <EFBFBD><EFBFBD> NULL ʱָ<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> create_delimiters_tab <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> free_delimiters_tab <EFBFBD>ͷ<EFBFBD>
|
|
|
|
|
* @return {token_node*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* *text <EFBFBD>Ƿ<EFBFBD>Ϊ '\0' <EFBFBD><EFBFBD>ʾ<EFBFBD>Ƿ<EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD> delimiters <EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> delimiters <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ټ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* delimiters_tab <EFBFBD>Ƿ<EFBFBD><EFBFBD>ǿգ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
*/
|
2018-08-20 11:07:20 +08:00
|
|
|
|
const token_node* search(const char** text, const char* delimiters = NULL,
|
2018-08-19 15:31:26 +08:00
|
|
|
|
const char* delimiters_tab = NULL);
|
|
|
|
|
|
2018-08-19 22:36:18 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param delimiters {const char*} <EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {char*} <EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 22:36:18 +08:00
|
|
|
|
*/
|
|
|
|
|
static char* create_delimiters_tab(const char* delimiters);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD> create_delimiters_tab <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 22:36:18 +08:00
|
|
|
|
* @param delimiters_tab {char*}
|
|
|
|
|
*/
|
|
|
|
|
static void free_delimiters_tab(char* delimiters_tab);
|
|
|
|
|
|
2018-08-19 15:31:26 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> 256 ƥ<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>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {token_node*}
|
|
|
|
|
*/
|
|
|
|
|
const token_node* first_node(void);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> 256 ƥ<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>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {token_node*}
|
|
|
|
|
*/
|
|
|
|
|
const token_node* next_node(void);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> C <EFBFBD>汾<EFBFBD><EFBFBD> 256 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-08-19 15:31:26 +08:00
|
|
|
|
* @return {ACL_TOKEN*}
|
|
|
|
|
*/
|
|
|
|
|
ACL_TOKEN* get_tree(void) const
|
|
|
|
|
{
|
|
|
|
|
return tree_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ACL_TOKEN* tree_;
|
|
|
|
|
ACL_ITER* iter_;
|
|
|
|
|
token_node node_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|