From 2a6ebc9d8db19282a3daf74df85645908958ab74 Mon Sep 17 00:00:00 2001 From: peri4 Date: Mon, 14 Feb 2022 19:12:41 +0300 Subject: [PATCH 1/2] piCompare change position --- libs/main/core/pibase.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libs/main/core/pibase.h b/libs/main/core/pibase.h index 438b2a71..4e1f9da5 100644 --- a/libs/main/core/pibase.h +++ b/libs/main/core/pibase.h @@ -356,17 +356,6 @@ inline bool piCompareBinary(const void * f, const void * s, size_t size) { return true; } -/*! @brief Function for compare two numeric values with epsilon - * \details Example:\n \snippet piincludes.cpp compare -* There are some macros: -* - \c piComparef for "float" -* - \c piCompared for "double" -*/ -template -inline bool piCompare(const T & a, const T & b, const T & epsilon = std::numeric_limits::epsilon()) { - return piAbs(a - b) <= epsilon; -} - /*! @brief Templated function return round of float falue * \details Round is the nearest integer value \n * There are some macros: @@ -483,6 +472,17 @@ inline void piLetobe(void * data, int size) { piSwap(((uchar*)data)[size - i - 1], ((uchar*)data)[i]); } +/*! @brief Function for compare two numeric values with epsilon + * \details Example:\n \snippet piincludes.cpp compare +* There are some macros: +* - \c piComparef for "float" +* - \c piCompared for "double" +*/ +template +inline bool piCompare(const T & a, const T & b, const T & epsilon = std::numeric_limits::epsilon()) { + return piAbs(a - b) <= epsilon; +} + /// @brief Templated function that inverse byte order of value "v" template inline void piLetobe(T * v) {piLetobe(v, sizeof(T));} From 2a877fbb6b7aba2c544104954acba88ee322360a Mon Sep 17 00:00:00 2001 From: peri4 Date: Fri, 11 Mar 2022 14:39:08 +0300 Subject: [PATCH 2/2] pip_cmg supports for "simple-stream" PIMETA tag for structs and classes for simple de/serialization without PIChunkStream --- CMakeLists.txt | 2 +- utils/code_model_generator/main.cpp | 114 ++++++++++++++++++---------- 2 files changed, 74 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eeb11129..1df09d3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(pip) set(pip_MAJOR 2) set(pip_MINOR 33) -set(pip_REVISION 0) +set(pip_REVISION 1) set(pip_SUFFIX ) set(pip_COMPANY SHS) set(pip_DOMAIN org.SHS) diff --git a/utils/code_model_generator/main.cpp b/utils/code_model_generator/main.cpp index 95959c44..cbc92c03 100755 --- a/utils/code_model_generator/main.cpp +++ b/utils/code_model_generator/main.cpp @@ -193,7 +193,7 @@ void makeEnumInfo(PIFile & f, const PICodeParser::Enum * e) { } -void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int & cnt) { +void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int & cnt, bool simple) { PIVector ml; piForeachC (PICodeParser::Member & m, e->members) { if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue; @@ -208,18 +208,31 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int if (m.meta.contains("id")) cnt = m.meta.value("id").toInt(); if (m.dims.isEmpty()) { - f << "\tcs << cs.chunk(" << cnt << ", "; - if (parser.isEnum(m.type)) - f << "(int)"; - f << "v." << m.name << ");\n"; - } else { - PIString ptype = m.type.left(m.type.find('[')); - f << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), "; - for (int i = 0; i < m.dims.size_s(); ++i) { - if (i > 0) f << " * "; - f << m.dims[i]; + if (simple) { + f << "\ts << "; + if (parser.isEnum(m.type)) + f << "(int)"; + f << "v." << m.name << ";\n"; + } else { + f << "\tcs << cs.chunk(" << cnt << ", "; + if (parser.isEnum(m.type)) + f << "(int)"; + f << "v." << m.name << ");\n"; + } + } else { + PIString ptype = m.type.left(m.type.find('[')).trim(); + PIString size = m.dims[0]; + for (int i = 1; i < m.dims.size_s(); ++i) { + size += " * "; + size += m.dims[i]; + } + if (simple) { + f << "\tfor (int i = 0; i < " << size << "; ++i)\n"; + f << "\t\ts << ((const " << ptype << " *)(v." << m.name << "))[i];\n"; + } else { + f << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), "; + f << size << "));\n"; } - f << "));\n"; } if (is_union) break; @@ -227,12 +240,12 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int if (is_union) return; piForeachC (PICodeParser::Entity * ce, e->children) { if (ce->has_name) continue; - writeClassStreamMembersOut(f, ce, cnt); + writeClassStreamMembersOut(f, ce, cnt, simple); } } -void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & cnt) { +void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & cnt, bool simple) { PIVector ml; piForeachC (PICodeParser::Member & m, e->members) { if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue; @@ -247,23 +260,35 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & if (m.meta.contains("id")) cnt = m.meta.value("id").toInt(); if (m.dims.isEmpty()) { - f << "\t\tcase " << cnt << ": cs.get("; - if (parser.isEnum(m.type)) - f << "(int&)"; - f << "v." << m.name << "); break;\n"; - } else { - PIString ptype = m.type.left(m.type.find('[')); - f << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n"; - f << "\t\t\tint cnt = piMini(d.size_s(), "; - for (int i = 0; i < m.dims.size_s(); ++i) { - if (i > 0) f << " * "; - f << m.dims[i]; + if (simple) { + f << "\ts >> "; + if (parser.isEnum(m.type)) + f << "(int&)"; + f << "v." << m.name << ";\n"; + } else { + f << "\t\tcase " << cnt << ": cs.get("; + if (parser.isEnum(m.type)) + f << "(int&)"; + f << "v." << m.name << "); break;\n"; + } + } else { + PIString ptype = m.type.left(m.type.find('[')).trim(); + PIString size = m.dims[0]; + for (int i = 1; i < m.dims.size_s(); ++i) { + size += " * "; + size += m.dims[i]; + } + if (simple) { + f << "\tfor (int i = 0; i < " << size << "; ++i)\n"; + f << "\t\ts >> ((" << ptype << " *)(v." << m.name << "))[i];\n"; + } else { + f << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n"; + f << "\t\t\tint cnt = piMini(d.size_s(), " << size << ");\n"; + f << "\t\t\tfor (int i = 0; i < cnt; ++i)\n"; + f << "\t\t\t\t((" << ptype << " *)(v." << m.name << "))[i] = d[i];\n"; + f << "\t\t\t}\n"; + f << "\t\t\tbreak;\n"; } - f << ");\n"; - f << "\t\t\tfor (int i = 0; i < cnt; ++i)\n"; - f << "\t\t\t\t((" << ptype << " *)(v." << m.name << "))[i] = d[i];\n"; - f << "\t\t\t}\n"; - f << "\t\t\tbreak;\n"; } if (is_union) break; @@ -271,7 +296,7 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & if (is_union) return; piForeachC (PICodeParser::Entity * ce, e->children) { if (ce->has_name) continue; - writeClassStreamMembersIn(f, ce, cnt); + writeClassStreamMembersIn(f, ce, cnt, simple); } } @@ -290,20 +315,27 @@ bool needClassStream(const PICodeParser::Entity * e) { void makeClassStream(PIFile & f, const PICodeParser::Entity * e) { if (!needClassStream(e)) return; + bool simple = e->meta.contains("simple-stream"); f << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n"; - f << "\tPIChunkStream cs;\n"; + if (!simple) + f << "\tPIChunkStream cs;\n"; int cnt = 0; - writeClassStreamMembersOut(f, e, cnt); - f << "\ts << cs.data();\n\treturn s;\n}\n"; + writeClassStreamMembersOut(f, e, cnt, simple); + if (!simple) + f << "\ts << cs.data();\n"; + f << "\treturn s;\n}\n"; f << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n"; - f << "\tif (s.size_s() < 4) return s;\n"; - f << "\tPIByteArray csba; s >> csba;\n"; - f << "\tPIChunkStream cs(csba);\n"; - f << "\twhile (!cs.atEnd()) {\n"; - f << "\t\tswitch (cs.read()) {\n"; + if (!simple) { + f << "\tif (s.size_s() < 4) return s;\n"; + f << "\tPIByteArray csba; s >> csba;\n"; + f << "\tPIChunkStream cs(csba);\n"; + f << "\twhile (!cs.atEnd()) {\n"; + f << "\t\tswitch (cs.read()) {\n"; + } cnt = 0; - writeClassStreamMembersIn(f, e, cnt); - f << "\t\t}\n\t}\n"; + writeClassStreamMembersIn(f, e, cnt, simple); + if (!simple) + f << "\t\t}\n\t}\n"; f << "\treturn s;\n}\n"; }