From 2a83e49ae7e9669a51224c76ab57be80e8050706 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 17 Jun 2023 17:17:20 -0700 Subject: [PATCH] redo tree formatting --- src/datafmt.cpp | 232 +++++++++++++++++++++++++++++++------------- test/testpvreq.cpp | 27 ++---- test/testqgroup.cpp | 10 +- test/testtype.cpp | 105 ++++++++++++++++---- 4 files changed, 263 insertions(+), 111 deletions(-) diff --git a/src/datafmt.cpp b/src/datafmt.cpp index 6514cef..da7910e 100644 --- a/src/datafmt.cpp +++ b/src/datafmt.cpp @@ -125,82 +125,181 @@ struct FmtTree { std::ostream& strm; const Value::Fmt& fmt; - void top(const std::string& member, - const FieldDesc *desc, - const FieldStorage* store) - { - strm<() ? "true" : "false"); + return; +#define CASE(ENUM, TYPE) \ + case TypeCode::ENUM : strm<(); return + CASE(Int8, int8_t); + CASE(Int16, int16_t); + CASE(Int32, int32_t); + CASE(Int64, int64_t); + CASE(UInt8, uint8_t); + CASE(UInt16, uint16_t); + CASE(UInt32, uint32_t); + CASE(UInt64, uint64_t); + CASE(Float32, float); + CASE(Float64, double); +#undef CASE + case TypeCode::String: + strm<<"\""<())<<"\""; + return; + case TypeCode::BoolA: + case TypeCode::Int8A: + case TypeCode::Int16A: + case TypeCode::Int32A: + case TypeCode::Int64A: + case TypeCode::UInt8A: + case TypeCode::UInt16A: + case TypeCode::UInt32A: + case TypeCode::UInt64A: + case TypeCode::Float32A: + case TypeCode::Float64A: + case TypeCode::StringA: + { + auto varr = fld.as>(); + strm<code; - if(!desc->id.empty()) - strm<<" \""<id<<"\""; - if(!member.empty() && desc->code!=TypeCode::Struct) - strm<<" "<code) { - case StoreType::Null: - if(desc->code==TypeCode::Struct) { - strm<<" {\n"; - for(auto& pair : desc->miter) { - auto cdesc = desc + pair.second; - Indented I(strm); - top(pair.first, cdesc, store + pair.second); - } - strm<(); + + if(!member.empty()) + strm<<' '<as())<<"\""; } strm<<"\n"; break; - case StoreType::Compound: { - auto& fld = store->as(); - if(fld.valid() && desc->code==TypeCode::Union) { - for(auto& pair : desc->miter) { - if(&desc->members[pair.second] == Value::Helper::desc(fld)) { - strm<<"."<top->desc) fld(store->top->desc, desc->members.data()); + def = Value::Helper::build(fld); // not connection to fld (not parent) + } + + strm<<" {"; + bool first = true; + { + Indented I(strm); + for(auto mem : def.ichildren()) { + auto mname(def.nameOf(mem)); + if(first) + strm<<'\n'; + strm<>()); + strm<<" = {"<=fmt._limit) { + strm<<"...\n"; break; } + show(elem, std::string()); + shown++; } } - Indented I(strm); - top(std::string(), - Value::Helper::desc(fld), - Value::Helper::store_ptr(fld)); - } - break; - case StoreType::Array: { - auto& varr = store->as>(); - if(!fmt._showValue) { - strm<<"\n"; - } else if(varr.original_type()!=ArrayType::Value) { - strm<<" = "<(); - strm<<" [\n"; - for(auto& val : arr) { - Indented I(strm); - top(std::string(), - Value::Helper::desc(val), - Value::Helper::store_ptr(val)); - } - strm<code)<<"\n"; - break; + + if(shown) + strm<