mirror of
https://github.com/oatpp/oatpp.git
synced 2025-03-31 18:30:22 +08:00
better data::mapping::Tree
This commit is contained in:
parent
fab45375dc
commit
702f465c40
@ -695,6 +695,100 @@ const Tree::Attributes& Tree::attributes() const {
|
||||
return m_attributes;
|
||||
}
|
||||
|
||||
type::String Tree::toString() const {
|
||||
|
||||
stream::BufferOutputStream ss(128);
|
||||
|
||||
switch (m_type) {
|
||||
|
||||
case Type::UNDEFINED: {
|
||||
ss << "undefined";
|
||||
break;
|
||||
}
|
||||
case Type::NULL_VALUE: {
|
||||
ss << "null";
|
||||
break;
|
||||
}
|
||||
|
||||
case Type::INTEGER: {
|
||||
ss << getInteger();
|
||||
break;
|
||||
}
|
||||
case Type::FLOAT: {
|
||||
ss << getFloat();
|
||||
break;
|
||||
}
|
||||
|
||||
case Type::BOOL: {
|
||||
ss << getPrimitive<bool>();
|
||||
break;
|
||||
}
|
||||
case Type::INT_8: {
|
||||
ss << getPrimitive<v_int8>();
|
||||
break;
|
||||
}
|
||||
case Type::UINT_8: {
|
||||
ss << getPrimitive<v_uint8>();
|
||||
break;
|
||||
}
|
||||
case Type::INT_16: {
|
||||
ss << getPrimitive<v_int16>();
|
||||
break;
|
||||
}
|
||||
case Type::UINT_16: {
|
||||
ss << getPrimitive<v_uint16>();
|
||||
break;
|
||||
}
|
||||
case Type::INT_32: {
|
||||
ss << getPrimitive<v_int32 >();
|
||||
break;
|
||||
}
|
||||
case Type::UINT_32: {
|
||||
ss << getPrimitive<v_uint32>();
|
||||
break;
|
||||
}
|
||||
case Type::INT_64: {
|
||||
ss << getPrimitive<v_int64>();
|
||||
break;
|
||||
}
|
||||
case Type::UINT_64: {
|
||||
ss << getPrimitive<v_uint64>();
|
||||
break;
|
||||
}
|
||||
case Type::FLOAT_32: {
|
||||
ss << getPrimitive<v_float32>();
|
||||
break;
|
||||
}
|
||||
case Type::FLOAT_64: {
|
||||
ss << getPrimitive<v_float64>();
|
||||
break;
|
||||
}
|
||||
case Type::STRING: {
|
||||
ss << getString();
|
||||
break;
|
||||
}
|
||||
|
||||
case Type::VECTOR: {
|
||||
ss << "<vector>";
|
||||
break;
|
||||
}
|
||||
case Type::MAP: {
|
||||
ss << "<map>";
|
||||
break;
|
||||
}
|
||||
case Type::PAIRS: {
|
||||
ss << "<pairs>";
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ss.toString();
|
||||
|
||||
}
|
||||
|
||||
type::String Tree::debugPrint(v_uint32 indent0, v_uint32 indentDelta, bool firstLineIndent) const {
|
||||
|
||||
stream::BufferOutputStream ss;
|
||||
|
@ -255,6 +255,8 @@ public:
|
||||
Attributes& attributes();
|
||||
const Attributes& attributes() const;
|
||||
|
||||
type::String toString() const;
|
||||
|
||||
type::String debugPrint(v_uint32 indent0 = 0, v_uint32 indentDelta = 2, bool firstLineIndent = true) const;
|
||||
|
||||
};
|
||||
|
@ -106,7 +106,7 @@ std::shared_ptr<Pattern> Pattern::parse(const oatpp::String& data){
|
||||
return parse(reinterpret_cast<p_char8>(data->data()), static_cast<v_buff_size>(data->size()));
|
||||
}
|
||||
|
||||
v_char8 Pattern::findSysChar(oatpp::utils::parser::Caret& caret) {
|
||||
v_char8 Pattern::findSysChar(oatpp::utils::parser::Caret& caret) const {
|
||||
auto data = caret.getData();
|
||||
for (v_buff_size i = caret.getPosition(); i < caret.getDataSize(); i++) {
|
||||
v_char8 a = static_cast<v_char8>(data[i]);
|
||||
@ -119,7 +119,7 @@ v_char8 Pattern::findSysChar(oatpp::utils::parser::Caret& caret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
|
||||
bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) const {
|
||||
|
||||
oatpp::utils::parser::Caret caret(reinterpret_cast<const char*>(url.getData()), url.getSize());
|
||||
|
||||
@ -181,7 +181,22 @@ bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
|
||||
|
||||
}
|
||||
|
||||
oatpp::String Pattern::toString() {
|
||||
oatpp::String Pattern::reconstruct(const data::mapping::Tree& params, const oatpp::String& tail) const {
|
||||
oatpp::data::stream::BufferOutputStream stream;
|
||||
for (const std::shared_ptr<Part>& part : *m_parts) {
|
||||
if(part->function == Part::FUNCTION_CONST) {
|
||||
stream.writeSimple("/", 1);
|
||||
stream.writeSimple(part->text);
|
||||
} else if(part->function == Part::FUNCTION_VAR) {
|
||||
stream.writeSimple(params[part->text].toString());
|
||||
} else if(part->function == Part::FUNCTION_ANY_END) {
|
||||
stream.writeSimple(tail);
|
||||
}
|
||||
}
|
||||
return stream.toString();
|
||||
}
|
||||
|
||||
oatpp::String Pattern::toString() const {
|
||||
oatpp::data::stream::BufferOutputStream stream;
|
||||
for (const std::shared_ptr<Part>& part : *m_parts) {
|
||||
if(part->function == Part::FUNCTION_CONST) {
|
||||
|
@ -26,8 +26,8 @@
|
||||
#define oatpp_web_url_mapping_Pattern_hpp
|
||||
|
||||
#include "oatpp/data/share/MemoryLabel.hpp"
|
||||
|
||||
#include "oatpp/utils/parser/Caret.hpp"
|
||||
#include "oatpp/data/mapping/Tree.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
@ -99,7 +99,7 @@ private:
|
||||
private:
|
||||
std::shared_ptr<std::list<std::shared_ptr<Part>>> m_parts{std::make_shared<std::list<std::shared_ptr<Part>>>()};
|
||||
private:
|
||||
v_char8 findSysChar(oatpp::utils::parser::Caret& caret);
|
||||
v_char8 findSysChar(oatpp::utils::parser::Caret& caret) const;
|
||||
public:
|
||||
|
||||
static std::shared_ptr<Pattern> createShared(){
|
||||
@ -110,9 +110,10 @@ public:
|
||||
static std::shared_ptr<Pattern> parse(const char* data);
|
||||
static std::shared_ptr<Pattern> parse(const oatpp::String& data);
|
||||
|
||||
bool match(const StringKeyLabel& url, MatchMap& matchMap);
|
||||
|
||||
oatpp::String toString();
|
||||
bool match(const StringKeyLabel& url, MatchMap& matchMap) const;
|
||||
|
||||
oatpp::String reconstruct(const data::mapping::Tree& params, const oatpp::String& tail) const;
|
||||
oatpp::String toString() const;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user