Commit ce13e9f9 authored by Frederick Zhang's avatar Frederick Zhang

bxx_data -> bnode_data

parent e6196a35
......@@ -88,9 +88,9 @@ zval * bdict::get_path(const std::string &key, size_t &pt) const {
zval *subnode = zend_hash_str_find(_data, current_key.c_str(), current_key.length());
std::string class_name = zend_container::bnode_object_get_class_name(subnode);
if (class_name == "bdict") {
return zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bdict_data->get_path(key, pt);
return zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bnode_data->get_path(key, pt);
} else if (class_name == "blist") {
return zend_container::blist_fetch_object(Z_OBJ_P(subnode))->blist_data->get_path(key, pt);
return zend_container::blist_fetch_object(Z_OBJ_P(subnode))->bnode_data->get_path(key, pt);
} else {
return bitem::get_zval_bool(false);
}
......@@ -119,9 +119,9 @@ void bdict::set_path(const std::string &key, size_t &pt, zval *value) {
return;
}
} else if (sub_class_name == "bdict") {
zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bdict_data->set_path(key, pt, value);
zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bnode_data->set_path(key, pt, value);
} else if (sub_class_name == "blist") {
zend_container::blist_fetch_object(Z_OBJ_P(subnode))->blist_data->set_path(key, pt, value);
zend_container::blist_fetch_object(Z_OBJ_P(subnode))->bnode_data->set_path(key, pt, value);
}
} else {
if (pt >= key.length()) {
......@@ -135,15 +135,15 @@ void bdict::set_path(const std::string &key, size_t &pt, zval *value) {
pt = backup_pt;
if (bitem::is_ull(next_key)) {
zend_object *zo = zend_container::blist_object_new(zend_container::blist_ce);
zend_container::blist_fetch_object(zo)->blist_data = new blist();
zend_container::blist_fetch_object(zo)->blist_data->set_path(key, pt, value);
zend_container::blist_fetch_object(zo)->bnode_data = new blist();
zend_container::blist_fetch_object(zo)->bnode_data->set_path(key, pt, value);
zval *zv = new zval();
ZVAL_OBJ(zv, zo);
zend_hash_str_add(_data, current_key.c_str(), current_key.length(), zv);
} else {
zend_object *zo = zend_container::bdict_object_new(zend_container::bdict_ce);
zend_container::bdict_fetch_object(zo)->bdict_data = new bdict();
zend_container::bdict_fetch_object(zo)->bdict_data->set_path(key, pt, value);
zend_container::bdict_fetch_object(zo)->bnode_data = new bdict();
zend_container::bdict_fetch_object(zo)->bnode_data->set_path(key, pt, value);
zval *zv = new zval();
ZVAL_OBJ(zv, zo);
zend_hash_str_add(_data, current_key.c_str(), current_key.length(), zv);
......@@ -163,9 +163,9 @@ bool bdict::del_path(const std::string &key, size_t &pt) {
zval *subnode = zend_hash_str_find(_data, current_key.c_str(), current_key.length());
std::string class_name = zend_container::bnode_object_get_class_name(subnode);
if (class_name == "bdict") {
return zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bdict_data->del_path(key, pt);
return zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bnode_data->del_path(key, pt);
} else if (class_name == "blist") {
return zend_container::blist_fetch_object(Z_OBJ_P(subnode))->blist_data->del_path(key, pt);
return zend_container::blist_fetch_object(Z_OBJ_P(subnode))->bnode_data->del_path(key, pt);
} else {
return false;
}
......@@ -187,7 +187,7 @@ zval * bdict::parse(const std::string &ben, size_t &pt) {
zend_object *zo = zend_container::bdict_object_new(zend_container::bdict_ce);
ZVAL_OBJ(zv, zo);
bdict_object *intern = zend_container::bdict_fetch_object(Z_OBJ_P(zv));
intern->bdict_data = new bdict();
intern->bnode_data = new bdict();
++pt;
while (ben[pt] != 'e') {
......@@ -199,16 +199,16 @@ zval * bdict::parse(const std::string &ben, size_t &pt) {
pt += std::stoull(key_len);
if (ben[pt] == 'd') {
zval *bnode = bdict::parse(ben, pt);
zend_hash_str_add(intern->bdict_data->_data, key.c_str(), key.length(), bnode);
zend_hash_str_add(intern->bnode_data->_data, key.c_str(), key.length(), bnode);
} else if (ben[pt] == 'l') {
zval *bnode = blist::parse(ben, pt);
zend_hash_str_add(intern->bdict_data->_data, key.c_str(), key.length(), bnode);
zend_hash_str_add(intern->bnode_data->_data, key.c_str(), key.length(), bnode);
} else if (isdigit(ben[pt])) {
zval *bnode = bstr::parse(ben, pt);
zend_hash_str_add(intern->bdict_data->_data, key.c_str(), key.length(), bnode);
zend_hash_str_add(intern->bnode_data->_data, key.c_str(), key.length(), bnode);
} else if (ben[pt] == 'i') {
zval *bnode = bint::parse(ben, pt);
zend_hash_str_add(intern->bdict_data->_data, key.c_str(), key.length(), bnode);
zend_hash_str_add(intern->bnode_data->_data, key.c_str(), key.length(), bnode);
} else {
return bitem::throw_general_exception("Error parsing bdict");
}
......@@ -231,13 +231,13 @@ std::string bdict::encode() const {
result += std::to_string(str_index.length()) + ":" + str_index;
if (class_name == "bdict") {
result += (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bdict_data->encode();
result += (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bnode_data->encode();
} else if (class_name == "blist") {
result += (zend_container::blist_fetch_object(Z_OBJ_P(value)))->blist_data->encode();
result += (zend_container::blist_fetch_object(Z_OBJ_P(value)))->bnode_data->encode();
} else if (class_name == "bstr") {
result += (zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bstr_data->encode();
result += (zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bnode_data->encode();
} else if (class_name == "bint") {
result += (zend_container::bint_fetch_object(Z_OBJ_P(value)))->bint_data->encode();
result += (zend_container::bint_fetch_object(Z_OBJ_P(value)))->bnode_data->encode();
}
}
return result + "e";
......@@ -258,16 +258,16 @@ zval * bdict::to_array(const bool include_meta) const {
zval *subarray = nullptr;
if (class_name == "bdict") {
bdict_object *bnode = zend_container::bdict_fetch_object(Z_OBJ_P(value));
subarray = bnode->bdict_data->to_array(include_meta);
subarray = bnode->bnode_data->to_array(include_meta);
} else if (class_name == "blist") {
blist_object *bnode = zend_container::blist_fetch_object(Z_OBJ_P(value));
subarray = bnode->blist_data->to_array(include_meta);
subarray = bnode->bnode_data->to_array(include_meta);
} else if (class_name == "bstr") {
bstr_object *bnode = zend_container::bstr_fetch_object(Z_OBJ_P(value));
subarray = bnode->bstr_data->to_array(include_meta);
subarray = bnode->bnode_data->to_array(include_meta);
} else if (class_name == "bint") {
bint_object *bnode = zend_container::bint_fetch_object(Z_OBJ_P(value));
subarray = bnode->bint_data->to_array(include_meta);
subarray = bnode->bnode_data->to_array(include_meta);
}
if (subarray != nullptr) {
zend_hash_add(Z_ARR_P(zv), str_index, subarray);
......@@ -313,16 +313,16 @@ zval * bdict::search(const std::string &needle, const long &mode, const std::str
}
if (class_name == "bdict") {
zval *next_result = (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bdict_data->search(needle, mode, current_path);
zval *next_result = (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bnode_data->search(needle, mode, current_path);
zend_hash_append_strings(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result));
} else if (class_name == "blist") {
zval *next_result = (zend_container::blist_fetch_object(Z_OBJ_P(value)))->blist_data->search(needle, mode, current_path);
zval *next_result = (zend_container::blist_fetch_object(Z_OBJ_P(value)))->bnode_data->search(needle, mode, current_path);
zend_hash_append_strings(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result));
} else if (modev && class_name == "bstr") {
if ((zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bstr_data->_value.find(needle) != std::string::npos)
if ((zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bnode_data->_value.find(needle) != std::string::npos)
add_next_index_stringl(zv, current_path.c_str(), current_path.length());
} else if (modev && bitem::is_ll(needle) && class_name == "bint") {
if ((zend_container::bint_fetch_object(Z_OBJ_P(value)))->bint_data->_value == std::stoll(needle))
if ((zend_container::bint_fetch_object(Z_OBJ_P(value)))->bnode_data->_value == std::stoll(needle))
add_next_index_stringl(zv, current_path.c_str(), current_path.length());
}
}
......
This diff is collapsed.
......@@ -13,7 +13,7 @@
void zend_container::bclass##_free_storage(zend_object *object TSRMLS_DC) \
{ \
bclass##_object *intern = zend_container::bclass##_fetch_object(object); \
delete intern->bclass##_data; \
delete intern->bnode_data; \
zend_object_std_dtor(&intern->std TSRMLS_CC); \
} \
zend_object * zend_container::bclass##_object_new(zend_class_entry *ce TSRMLS_DC) \
......@@ -31,8 +31,8 @@
bclass##_object *old_object = zend_container::bclass##_fetch_object(Z_OBJ_P(object)); \
zend_object *new_zend_object = zend_container::bclass##_object_new(zend_container::bclass##_ce); \
bclass##_object *new_object = zend_container::bclass##_fetch_object(new_zend_object); \
bclass *new_object_data = new bclass(old_object->bclass##_data); \
new_object->bclass##_data = new_object_data; \
bclass *new_object_data = new bclass(old_object->bnode_data); \
new_object->bnode_data = new_object_data; \
return &new_object->std; \
}
......
......@@ -36,7 +36,7 @@ zval * bint::parse(const std::string &ben, size_t &pt) {
zend_object *zo = zend_container::bint_object_new(zend_container::bint_ce);
ZVAL_OBJ(zv, zo);
bint_object *intern = zend_container::bint_fetch_object(Z_OBJ_P(zv));
intern->bint_data = new bint(result);
intern->bnode_data = new bint(result);
return zv;
}
......
......@@ -119,9 +119,9 @@ zval * blist::get_path(const std::string &key, size_t &pt) const {
zval *subnode = zend_hash_index_find(_data, current_key_long);
std::string class_name = zend_container::bnode_object_get_class_name(subnode);
if (class_name == "bdict") {
return zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bdict_data->get_path(key, pt);
return zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bnode_data->get_path(key, pt);
} else if (class_name == "blist") {
return zend_container::blist_fetch_object(Z_OBJ_P(subnode))->blist_data->get_path(key, pt);
return zend_container::blist_fetch_object(Z_OBJ_P(subnode))->bnode_data->get_path(key, pt);
} else {
return bitem::get_zval_bool(false);
}
......@@ -155,9 +155,9 @@ void blist::set_path(const std::string &key, size_t &pt, zval *value) {
return;
}
} else if (sub_class_name == "bdict") {
zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bdict_data->set_path(key, pt, value);
zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bnode_data->set_path(key, pt, value);
} else if (sub_class_name == "blist") {
zend_container::blist_fetch_object(Z_OBJ_P(subnode))->blist_data->set_path(key, pt, value);
zend_container::blist_fetch_object(Z_OBJ_P(subnode))->bnode_data->set_path(key, pt, value);
}
} else {
if (pt >= key.length()) {
......@@ -171,15 +171,15 @@ void blist::set_path(const std::string &key, size_t &pt, zval *value) {
pt = backup_pt;
if (bitem::is_ull(next_key)) {
zend_object *zo = zend_container::blist_object_new(zend_container::blist_ce);
zend_container::blist_fetch_object(zo)->blist_data = new blist();
zend_container::blist_fetch_object(zo)->blist_data->set_path(key, pt, value);
zend_container::blist_fetch_object(zo)->bnode_data = new blist();
zend_container::blist_fetch_object(zo)->bnode_data->set_path(key, pt, value);
zval *zv = new zval();
ZVAL_OBJ(zv, zo);
zend_hash_next_index_insert(_data, zv);
} else {
zend_object *zo = zend_container::bdict_object_new(zend_container::bdict_ce);
zend_container::bdict_fetch_object(zo)->bdict_data = new bdict();
zend_container::bdict_fetch_object(zo)->bdict_data->set_path(key, pt, value);
zend_container::bdict_fetch_object(zo)->bnode_data = new bdict();
zend_container::bdict_fetch_object(zo)->bnode_data->set_path(key, pt, value);
zval *zv = new zval();
ZVAL_OBJ(zv, zo);
zend_hash_next_index_insert(_data, zv);
......@@ -204,9 +204,9 @@ bool blist::del_path(const std::string &key, size_t &pt) {
zval *subnode = zend_hash_index_find(_data, current_key_long);
std::string class_name = zend_container::bnode_object_get_class_name(subnode);
if (class_name == "bdict") {
return zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bdict_data->del_path(key, pt);
return zend_container::bdict_fetch_object(Z_OBJ_P(subnode))->bnode_data->del_path(key, pt);
} else if (class_name == "blist") {
return zend_container::blist_fetch_object(Z_OBJ_P(subnode))->blist_data->del_path(key, pt);
return zend_container::blist_fetch_object(Z_OBJ_P(subnode))->bnode_data->del_path(key, pt);
} else {
return false;
}
......@@ -229,21 +229,21 @@ zval * blist::parse(const std::string &ben, size_t &pt) {
zend_object *zo = zend_container::blist_object_new(zend_container::blist_ce);
ZVAL_OBJ(zv, zo);
blist_object *intern = zend_container::blist_fetch_object(Z_OBJ_P(zv));
intern->blist_data = new blist();
intern->bnode_data = new blist();
while (ben[pt] != 'e') {
if (ben[pt] == 'd') {
zval *bnode = bdict::parse(ben, pt);
zend_hash_next_index_insert(intern->blist_data->_data, bnode);
zend_hash_next_index_insert(intern->bnode_data->_data, bnode);
} else if (ben[pt] == 'l') {
zval *bnode = blist::parse(ben, pt);
zend_hash_next_index_insert(intern->blist_data->_data, bnode);
zend_hash_next_index_insert(intern->bnode_data->_data, bnode);
} else if (isdigit(ben[pt])) {
zval *bnode = bstr::parse(ben, pt);
zend_hash_next_index_insert(intern->blist_data->_data, bnode);
zend_hash_next_index_insert(intern->bnode_data->_data, bnode);
} else if (ben[pt] == 'i') {
zval *bnode = bint::parse(ben, pt);
zend_hash_next_index_insert(intern->blist_data->_data, bnode);
zend_hash_next_index_insert(intern->bnode_data->_data, bnode);
} else {
return bitem::throw_general_exception("Error parsing blist");
}
......@@ -261,13 +261,13 @@ std::string blist::encode() const {
std::string class_name = zend_container::bnode_object_get_class_name(value);
if (class_name == "bdict") {
result += (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bdict_data->encode();
result += (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bnode_data->encode();
} else if (class_name == "blist") {
result += (zend_container::blist_fetch_object(Z_OBJ_P(value)))->blist_data->encode();
result += (zend_container::blist_fetch_object(Z_OBJ_P(value)))->bnode_data->encode();
} else if (class_name == "bstr") {
result += (zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bstr_data->encode();
result += (zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bnode_data->encode();
} else if (class_name == "bint") {
result += (zend_container::bint_fetch_object(Z_OBJ_P(value)))->bint_data->encode();
result += (zend_container::bint_fetch_object(Z_OBJ_P(value)))->bnode_data->encode();
}
}
return result + "e";
......@@ -285,16 +285,16 @@ zval * blist::to_array(const bool include_meta) const {
zval *subarray = nullptr;
if (class_name == "bdict") {
bdict_object *bnode = zend_container::bdict_fetch_object(Z_OBJ_P(value));
subarray = bnode->bdict_data->to_array(include_meta);
subarray = bnode->bnode_data->to_array(include_meta);
} else if (class_name == "blist") {
blist_object *bnode = zend_container::blist_fetch_object(Z_OBJ_P(value));
subarray = bnode->blist_data->to_array(include_meta);
subarray = bnode->bnode_data->to_array(include_meta);
} else if (class_name == "bstr") {
bstr_object *bnode = zend_container::bstr_fetch_object(Z_OBJ_P(value));
subarray = bnode->bstr_data->to_array(include_meta);
subarray = bnode->bnode_data->to_array(include_meta);
} else if (class_name == "bint") {
bint_object *bnode = zend_container::bint_fetch_object(Z_OBJ_P(value));
subarray = bnode->bint_data->to_array(include_meta);
subarray = bnode->bnode_data->to_array(include_meta);
}
if (subarray != nullptr) {
add_next_index_zval(zv, subarray);
......@@ -335,16 +335,16 @@ zval * blist::search(const std::string &needle, const long &mode, const std::str
std::string current_path = (path == "" ? "" : path + "/") + std::to_string(num_index);
if (class_name == "bdict") {
zval *next_result = (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bdict_data->search(needle, mode, current_path);
zval *next_result = (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bnode_data->search(needle, mode, current_path);
zend_hash_append_strings(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result));
} else if (class_name == "blist") {
zval *next_result = (zend_container::blist_fetch_object(Z_OBJ_P(value)))->blist_data->search(needle, mode, current_path);
zval *next_result = (zend_container::blist_fetch_object(Z_OBJ_P(value)))->bnode_data->search(needle, mode, current_path);
zend_hash_append_strings(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result));
} else if (modev && class_name == "bstr") {
if ((zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bstr_data->_value.find(needle) != std::string::npos)
if ((zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bnode_data->_value.find(needle) != std::string::npos)
add_next_index_stringl(zv, current_path.c_str(), current_path.length());
} else if (modev && bitem::is_ll(needle) && class_name == "bint") {
if ((zend_container::bint_fetch_object(Z_OBJ_P(value)))->bint_data->_value == std::stoll(needle))
if ((zend_container::bint_fetch_object(Z_OBJ_P(value)))->bnode_data->_value == std::stoll(needle))
add_next_index_stringl(zv, current_path.c_str(), current_path.length());
}
}
......
......@@ -35,7 +35,7 @@ zval * bstr::parse(const std::string &ben, size_t &pt) {
zend_object *zo = zend_container::bstr_object_new(zend_container::bstr_ce);
ZVAL_OBJ(zv, zo);
bstr_object *intern = zend_container::bstr_fetch_object(Z_OBJ_P(zv));
intern->bstr_data = new bstr(ben.substr(pt, len));
intern->bnode_data = new bstr(ben.substr(pt, len));
pt += len;
return zv;
}
......
......@@ -13,7 +13,7 @@ extern "C" {
#define ZEND_CONTAINER_PRE(bclass) \
typedef struct { \
bclass *bclass##_data; \
bclass *bnode_data; \
zend_object std; \
} bclass##_object;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment