From 6ebfa4e4032bbef026c409313bb6dcb4ffb63642 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 9 Mar 2020 11:25:30 -0700 Subject: [PATCH] separate Value printing code --- src/Makefile | 1 + src/data.cpp | 99 ------------------------------------------- src/datafmt.cpp | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 99 deletions(-) create mode 100644 src/datafmt.cpp diff --git a/src/Makefile b/src/Makefile index ce97876..4743cdb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -61,6 +61,7 @@ LIB_SRCS += util.cpp LIB_SRCS += bitmask.cpp LIB_SRCS += type.cpp LIB_SRCS += data.cpp +LIB_SRCS += datafmt.cpp LIB_SRCS += pvrequest.cpp LIB_SRCS += dataencode.cpp LIB_SRCS += nt.cpp diff --git a/src/data.cpp b/src/data.cpp index a7cbeb0..2997cb8 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -787,105 +787,6 @@ Value Value::_iter_deref(const IterInfo& info) const return ret; } -static -void show_Value(std::ostream& strm, - const std::string& member, - const Value& val, - unsigned level=0); - -static -void show_Value(std::ostream& strm, - const std::string& member, - const FieldDesc *desc, - const FieldStorage* store, - unsigned level=0) -{ - indent(strm, level); - if(!desc) { - strm<<"null\n"; - return; - } - - 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; - show_Value(strm, pair.first, cdesc, store + pair.second, level+1); - } - indent(strm, level); - strm<<"}"; - if(!member.empty()) - strm<<" "<as())<<"\"\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<<"."<as>(); - if(varr.original_type()!=ArrayType::Value) { - strm<<" = "<(); - strm<<" [\n"; - for(auto& val : arr) { - show_Value(strm, std::string(), val, level+1); - } - indent(strm, level); - strm<<"]\n"; - } - } - break; - default: - strm<<"!!Invalid StoreType!! "<code)<<"\n"; - break; - } -} - -static -void show_Value(std::ostream& strm, - const std::string& member, - const Value& val, - unsigned level) -{ - show_Value(strm, member, - Value::Helper::desc(val), - Value::Helper::store_ptr(val), - level); -} - -std::ostream& operator<<(std::ostream& strm, const Value& val) -{ - show_Value(strm, std::string(), val); - return strm; -} - namespace impl { void FieldStorage::init(const FieldDesc *desc) diff --git a/src/datafmt.cpp b/src/datafmt.cpp new file mode 100644 index 0000000..b33973b --- /dev/null +++ b/src/datafmt.cpp @@ -0,0 +1,110 @@ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvxs is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ + +#include "dataimpl.h" + +namespace pvxs { + +static +void show_Value(std::ostream& strm, + const std::string& member, + const Value& val, + unsigned level=0); + +static +void show_Value(std::ostream& strm, + const std::string& member, + const FieldDesc *desc, + const FieldStorage* store, + unsigned level=0) +{ + indent(strm, level); + if(!desc) { + strm<<"null\n"; + return; + } + + 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; + show_Value(strm, pair.first, cdesc, store + pair.second, level+1); + } + indent(strm, level); + strm<<"}"; + if(!member.empty()) + strm<<" "<as())<<"\"\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<<"."<as>(); + if(varr.original_type()!=ArrayType::Value) { + strm<<" = "<(); + strm<<" [\n"; + for(auto& val : arr) { + show_Value(strm, std::string(), val, level+1); + } + indent(strm, level); + strm<<"]\n"; + } + } + break; + default: + strm<<"!!Invalid StoreType!! "<code)<<"\n"; + break; + } +} + +static +void show_Value(std::ostream& strm, + const std::string& member, + const Value& val, + unsigned level) +{ + show_Value(strm, member, + Value::Helper::desc(val), + Value::Helper::store_ptr(val), + level); +} + +std::ostream& operator<<(std::ostream& strm, const Value& val) +{ + show_Value(strm, std::string(), val); + return strm; +} + +}