Merge branch 'master' into micro
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
|||||||
project(pip)
|
project(pip)
|
||||||
set(pip_MAJOR 2)
|
set(pip_MAJOR 2)
|
||||||
set(pip_MINOR 33)
|
set(pip_MINOR 33)
|
||||||
set(pip_REVISION 0)
|
set(pip_REVISION 1)
|
||||||
set(pip_SUFFIX )
|
set(pip_SUFFIX )
|
||||||
set(pip_COMPANY SHS)
|
set(pip_COMPANY SHS)
|
||||||
set(pip_DOMAIN org.SHS)
|
set(pip_DOMAIN org.SHS)
|
||||||
|
|||||||
@@ -359,17 +359,6 @@ inline bool piCompareBinary(const void * f, const void * s, size_t size) {
|
|||||||
return true;
|
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<typename T>
|
|
||||||
inline bool piCompare(const T & a, const T & b, const T & epsilon = std::numeric_limits<T>::epsilon()) {
|
|
||||||
return piAbs(a - b) <= epsilon;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @brief Templated function return round of float falue
|
/*! @brief Templated function return round of float falue
|
||||||
* \details Round is the nearest integer value \n
|
* \details Round is the nearest integer value \n
|
||||||
* There are some macros:
|
* There are some macros:
|
||||||
@@ -486,6 +475,17 @@ inline void piLetobe(void * data, int size) {
|
|||||||
piSwap<uchar>(((uchar*)data)[size - i - 1], ((uchar*)data)[i]);
|
piSwap<uchar>(((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<typename T>
|
||||||
|
inline bool piCompare(const T & a, const T & b, const T & epsilon = std::numeric_limits<T>::epsilon()) {
|
||||||
|
return piAbs(a - b) <= epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Templated function that inverse byte order of value "v"
|
/// @brief Templated function that inverse byte order of value "v"
|
||||||
template<typename T> inline void piLetobe(T * v) {piLetobe(v, sizeof(T));}
|
template<typename T> inline void piLetobe(T * v) {piLetobe(v, sizeof(T));}
|
||||||
|
|
||||||
|
|||||||
@@ -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<PICodeParser::Member> ml;
|
PIVector<PICodeParser::Member> ml;
|
||||||
piForeachC (PICodeParser::Member & m, e->members) {
|
piForeachC (PICodeParser::Member & m, e->members) {
|
||||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
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"))
|
if (m.meta.contains("id"))
|
||||||
cnt = m.meta.value("id").toInt();
|
cnt = m.meta.value("id").toInt();
|
||||||
if (m.dims.isEmpty()) {
|
if (m.dims.isEmpty()) {
|
||||||
f << "\tcs << cs.chunk(" << cnt << ", ";
|
if (simple) {
|
||||||
if (parser.isEnum(m.type))
|
f << "\ts << ";
|
||||||
f << "(int)";
|
if (parser.isEnum(m.type))
|
||||||
f << "v." << m.name << ");\n";
|
f << "(int)";
|
||||||
} else {
|
f << "v." << m.name << ";\n";
|
||||||
PIString ptype = m.type.left(m.type.find('['));
|
} else {
|
||||||
f << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), ";
|
f << "\tcs << cs.chunk(" << cnt << ", ";
|
||||||
for (int i = 0; i < m.dims.size_s(); ++i) {
|
if (parser.isEnum(m.type))
|
||||||
if (i > 0) f << " * ";
|
f << "(int)";
|
||||||
f << m.dims[i];
|
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)
|
if (is_union)
|
||||||
break;
|
break;
|
||||||
@@ -227,12 +240,12 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int
|
|||||||
if (is_union) return;
|
if (is_union) return;
|
||||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||||
if (ce->has_name) continue;
|
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<PICodeParser::Member> ml;
|
PIVector<PICodeParser::Member> ml;
|
||||||
piForeachC (PICodeParser::Member & m, e->members) {
|
piForeachC (PICodeParser::Member & m, e->members) {
|
||||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
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"))
|
if (m.meta.contains("id"))
|
||||||
cnt = m.meta.value("id").toInt();
|
cnt = m.meta.value("id").toInt();
|
||||||
if (m.dims.isEmpty()) {
|
if (m.dims.isEmpty()) {
|
||||||
f << "\t\tcase " << cnt << ": cs.get(";
|
if (simple) {
|
||||||
if (parser.isEnum(m.type))
|
f << "\ts >> ";
|
||||||
f << "(int&)";
|
if (parser.isEnum(m.type))
|
||||||
f << "v." << m.name << "); break;\n";
|
f << "(int&)";
|
||||||
} else {
|
f << "v." << m.name << ";\n";
|
||||||
PIString ptype = m.type.left(m.type.find('['));
|
} else {
|
||||||
f << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n";
|
f << "\t\tcase " << cnt << ": cs.get(";
|
||||||
f << "\t\t\tint cnt = piMini(d.size_s(), ";
|
if (parser.isEnum(m.type))
|
||||||
for (int i = 0; i < m.dims.size_s(); ++i) {
|
f << "(int&)";
|
||||||
if (i > 0) f << " * ";
|
f << "v." << m.name << "); break;\n";
|
||||||
f << m.dims[i];
|
}
|
||||||
|
} 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)
|
if (is_union)
|
||||||
break;
|
break;
|
||||||
@@ -271,7 +296,7 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int &
|
|||||||
if (is_union) return;
|
if (is_union) return;
|
||||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||||
if (ce->has_name) continue;
|
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) {
|
void makeClassStream(PIFile & f, const PICodeParser::Entity * e) {
|
||||||
if (!needClassStream(e)) return;
|
if (!needClassStream(e)) return;
|
||||||
|
bool simple = e->meta.contains("simple-stream");
|
||||||
f << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n";
|
f << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n";
|
||||||
f << "\tPIChunkStream cs;\n";
|
if (!simple)
|
||||||
|
f << "\tPIChunkStream cs;\n";
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
writeClassStreamMembersOut(f, e, cnt);
|
writeClassStreamMembersOut(f, e, cnt, simple);
|
||||||
f << "\ts << cs.data();\n\treturn s;\n}\n";
|
if (!simple)
|
||||||
|
f << "\ts << cs.data();\n";
|
||||||
|
f << "\treturn s;\n}\n";
|
||||||
f << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
f << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
||||||
f << "\tif (s.size_s() < 4) return s;\n";
|
if (!simple) {
|
||||||
f << "\tPIByteArray csba; s >> csba;\n";
|
f << "\tif (s.size_s() < 4) return s;\n";
|
||||||
f << "\tPIChunkStream cs(csba);\n";
|
f << "\tPIByteArray csba; s >> csba;\n";
|
||||||
f << "\twhile (!cs.atEnd()) {\n";
|
f << "\tPIChunkStream cs(csba);\n";
|
||||||
f << "\t\tswitch (cs.read()) {\n";
|
f << "\twhile (!cs.atEnd()) {\n";
|
||||||
|
f << "\t\tswitch (cs.read()) {\n";
|
||||||
|
}
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
writeClassStreamMembersIn(f, e, cnt);
|
writeClassStreamMembersIn(f, e, cnt, simple);
|
||||||
f << "\t\t}\n\t}\n";
|
if (!simple)
|
||||||
|
f << "\t\t}\n\t}\n";
|
||||||
f << "\treturn s;\n}\n";
|
f << "\treturn s;\n}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user