diff --git a/src/containers/pimap.h b/src/containers/pimap.h index 57142775..88b70e9a 100644 --- a/src/containers/pimap.h +++ b/src/containers/pimap.h @@ -249,8 +249,8 @@ protected: bool operator <(const MapIndex & s) const {return key < s.key;} bool operator >(const MapIndex & s) const {return key > s.key;} }; - template friend PIByteArray & operator >>(PIByteArray & s, typename PIMap::MapIndex & v); - template friend PIByteArray & operator <<(PIByteArray & s, const typename PIMap::MapIndex & v); + template friend PIByteArray & operator >>(PIByteArray & s, PIDeque::MapIndex> & v); + template friend PIByteArray & operator <<(PIByteArray & s, const PIDeque::MapIndex> & v); ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const { ssize_t mid; diff --git a/src/core/pibytearray.h b/src/core/pibytearray.h index b6aef053..52733d1b 100755 --- a/src/core/pibytearray.h +++ b/src/core/pibytearray.h @@ -122,6 +122,7 @@ inline PICout operator <<(PICout s, const PIByteArray & ba) {s.space(); s.setCon #define PBA_OPERATOR_TO int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); + //! \relatesalso PIByteArray \brief Store operator inline PIByteArray & operator <<(PIByteArray & s, bool v) {s.push_back(v); return s;} //! \relatesalso PIByteArray \brief Store operator @@ -154,24 +155,6 @@ inline PIByteArray & operator <<(PIByteArray & s, const ldouble & v) {PBA_OPERAT inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()); if (v.size_s() > 0) memcpy(s.data(os), v.data(), v.size()); return s;} //! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) {int os = s.size_s(); s.enlarge(v.s); if (v.s > 0) memcpy(s.data(os), v.d, v.s); return s;} -//! \relatesalso PIByteArray \brief Store operator -template -inline PIByteArray & operator <<(PIByteArray & s, const PIPair & v) {s << v.first << v.second; return s;} -//! \relatesalso PIByteArray \brief Store operator -template -inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;} -//! \relatesalso PIByteArray \brief Store operator -template -inline PIByteArray & operator <<(PIByteArray & s, const PIList & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;} -//! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v) {s << v.size_ << v.data_; return s;} -//! \relatesalso PIByteArray \brief Store operator -template -inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;} -#ifdef PIP_BYTEARRAY_STREAM_ANY_TYPE -template -inline PIByteArray & operator <<(PIByteArray & s, const T & v) {PBA_OPERATOR_TO return s;} -#endif #undef PBA_OPERATOR_TO #define PBA_OPERATOR_FROM memcpy(&v, s.data(), sizeof(v)); s.remove(0, sizeof(v)); @@ -208,23 +191,74 @@ inline PIByteArray & operator >>(PIByteArray & s, ldouble & v) {assert(s.size() inline PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); if (sz > 0) memcpy(v.data(), s.data(), v.size()); s.remove(0, v.size()); return s;} //! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {assert(s.size_s() >= v.s); if (v.s > 0) memcpy(v.d, s.data(), v.s); s.remove(0, v.s); return s;} + + +template inline PIByteArray & operator <<(PIByteArray & s, const PIPair & v); +//! \relatesalso PIByteArray \brief Store operator +template inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v); +//! \relatesalso PIByteArray \brief Store operator +template inline PIByteArray & operator <<(PIByteArray & s, const PIList & v); +//! \relatesalso PIByteArray \brief Store operator +template inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v); + //! \relatesalso PIByteArray \brief Store operator +template inline PIByteArray & operator <<(PIByteArray & s, const PIMap & v); + //! \relatesalso PIByteArray \brief Restore operator +template inline PIByteArray & operator >>(PIByteArray & s, PIPair & v); +//! \relatesalso PIByteArray \brief Restore operator +template inline PIByteArray & operator >>(PIByteArray & s, PIVector & v); +//! \relatesalso PIByteArray \brief Restore operator +template inline PIByteArray & operator >>(PIByteArray & s, PIList & v); +//! \relatesalso PIByteArray \brief Restore operator +template inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v); + //! \relatesalso PIByteArray \brief Restore operator +template inline PIByteArray & operator >>(PIByteArray & s, PIMap & v); + + +//! \relatesalso PIByteArray \brief Store operator +inline PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v) {s << v.size_ << v.data_; return s;} template -inline PIByteArray & operator >>(PIByteArray & s, PIPair & v) {s >> v.first >> v.second; return s;} -//! \relatesalso PIByteArray \brief Restore operator +inline PIByteArray & operator <<(PIByteArray & s, const PIPair & v) {s << v.first << v.second; return s;} template -inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} -//! \relatesalso PIByteArray \brief Restore operator +inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;} template -inline PIByteArray & operator >>(PIByteArray & s, PIList & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} -//! \relatesalso PIByteArray \brief Restore operator +inline PIByteArray & operator <<(PIByteArray & s, const PIList & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;} template -inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} +inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;} +template +inline PIByteArray & operator <<(PIByteArray & s, const PIMap & v) { + s << int(v.pim_index.size_s()); + for (uint i = 0; i < v.size(); ++i) + s << v.pim_index[i].index << v.pim_index[i].key; + s << v.pim_content; + return s; +} + //! \relatesalso PIByteArray \brief Restore operator inline PIByteArray & operator >>(PIByteArray & s, PIBitArray & v) {assert(s.size_s() >= 8); s >> v.size_ >> v.data_; return s;} -// //! \relatesalso PIByteArray \brief Restore operator -//template -//inline PIByteArray & operator >>(PIByteArray & s, PIMap & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} +template +inline PIByteArray & operator >>(PIByteArray & s, PIPair & v) {s >> v.first >> v.second; return s;} +template +inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} +template +inline PIByteArray & operator >>(PIByteArray & s, PIList & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} +template +inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} +template +inline PIByteArray & operator >>(PIByteArray & s, PIMap & v) { + assert(s.size_s() >= 4); + int sz; s >> sz; v.pim_index.resize(sz); + for (int i = 0; i < sz; ++i) + s >> v.pim_index[i].index >> v.pim_index[i].key; + s >> v.pim_content; + return s; +} + +#ifdef PIP_BYTEARRAY_STREAM_ANY_TYPE +template +inline PIByteArray & operator <<(PIByteArray & s, const T & v) {PBA_OPERATOR_TO return s;} +#endif + #ifdef PIP_BYTEARRAY_STREAM_ANY_TYPE template inline PIByteArray & operator >>(PIByteArray & s, T & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;} diff --git a/utils/code_model_generator/main.cpp b/utils/code_model_generator/main.cpp index 8412a4e8..b8c4f242 100755 --- a/utils/code_model_generator/main.cpp +++ b/utils/code_model_generator/main.cpp @@ -153,7 +153,7 @@ void makeClassStreamHeader(PIFile & f, const PICodeParser::Entity * e) { } -void writeModel(PICodeParser & parser, const PIString out, bool meta, bool enums, bool streams, bool texts) { +void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool meta, bool enums, bool streams, bool texts) { PIVector ventities; PIString defname = out.replaceAll(".", "_").replaceAll("/", "_").replaceAll(":", "_").replaceAll("-", "_").toUpperCase() + "_H"; @@ -259,7 +259,11 @@ void writeModel(PICodeParser & parser, const PIString out, bool meta, bool enums f.setPath(out + ".h"); f.clear(); f.open(PIIODevice::WriteOnly); - f << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n\n"); + f << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n"); + f << "// Execute command:\n"; + piForeachC (PIString & _a, cli.rawArguments()) + f << "// \"" << _a << "\"\n"; + f << "\n"; f << "#ifndef " << defname << "\n#define " << defname << "\n\n"; f << "#include \"pivariant.h\"\n#include \"picodeinfo.h\""; /* @@ -322,10 +326,10 @@ int main(int argc, char * argv[]) { piCout << Cyan << Bold << "Parsing done"; piCout << Cyan << Bold << "Writing code model ..."; bool all = cli.hasArgument("All"); - writeModel(parser, cli.argumentValue("output"), cli.hasArgument("Metainfo") || all, - cli.hasArgument("Enum") || all, - cli.hasArgument("Stream") || all, - cli.hasArgument("Text") || all); + writeModel(parser, cli, cli.argumentValue("output"), cli.hasArgument("Metainfo") || all, + cli.hasArgument("Enum") || all, + cli.hasArgument("Stream") || all, + cli.hasArgument("Text") || all); piCout << Cyan << Bold << "Writing done"; if (cli.hasArgument("print") || cli.hasArgument("Print")) { bool womain = cli.hasArgument("print");