diff --git a/cd_utils/CMakeLists.txt b/cd_utils/CMakeLists.txt index 0356fe3..dc879d5 100644 --- a/cd_utils/CMakeLists.txt +++ b/cd_utils/CMakeLists.txt @@ -25,7 +25,6 @@ endif () target_link_libraries(${PROJECT_NAME} ${PIP_LIBRARY}) add_executable(cdutilsngtest "cdutilstest.cpp") -add_definitions(-DCDPULT) target_link_libraries(cdutilsngtest ${PIP_LIBRARY} ${PROJECT_NAME}) if (NOT DEFINED ENV{QNX_HOST}) @@ -46,24 +45,24 @@ if (NOT DEFINED ENV{QNX_HOST}) # target_link_libraries(${KX_PULT_NAME} ${LIBS} ${PROJECT_NAME}) endif () endif () -# if (LIB) - # if (WIN32) - # set(CMAKE_INSTALL_PREFIX ${MINGW_DIR}) - # install(FILES ${HDRS_UTILS} DESTINATION ${MINGW_INCLUDE}) - # install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB}) - # install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN}) - # else () - # set(CMAKE_INSTALL_PREFIX /usr) - # install(FILES ${HDRS_UTILS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include) - # install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) - # endif () - # message(STATUS "Install to system \"${CMAKE_INSTALL_PREFIX}\"") -# else () - # install(TARGETS ${PROJECT_NAME} DESTINATION bin) - # message(STATUS "Install to local \"bin\"") -# endif () -# if (NOT DEFINED ENV{QNX_HOST}) - # if (KX_PULT) - # install(TARGETS ${KX_PULT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) - # endif () -# endif () + if (LIB) + if (WIN32) + set(CMAKE_INSTALL_PREFIX ${MINGW_DIR}) + install(FILES ${HDRS_UTILS} DESTINATION ${MINGW_INCLUDE}) + install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB}) + install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN}) + else () + set(CMAKE_INSTALL_PREFIX /usr) + install(FILES ${HDRS_UTILS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include) + install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + endif () + message(STATUS "Install to system \"${CMAKE_INSTALL_PREFIX}\"") +else () + install(TARGETS ${PROJECT_NAME} DESTINATION bin) + message(STATUS "Install to local \"bin\"") +endif () +#if (NOT DEFINED ENV{QNX_HOST}) +# if (KX_PULT) +# install(TARGETS ${KX_PULT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +# endif () +#endif () diff --git a/cd_utils/cdutils_core.cpp b/cd_utils/cdutils_core.cpp index 5c6a38d..ab788b9 100644 --- a/cd_utils/cdutils_core.cpp +++ b/cd_utils/cdutils_core.cpp @@ -126,6 +126,16 @@ void Core::k_parse(PIIODevice * d) { } +void Core::k_update(PIIODevice * d) { + KSection uk = k_; + k_parse(d); + if (!uk.isEmpty()) + if (!uk.isSameStructure(k_)) + piCout << "ask for save names"; + +} + + void CDUtils::Core::dataReceived(const PIString & from, const PIByteArray & data) { piCout << from << data; if (data.size_s() < 4) return; diff --git a/cd_utils/cdutils_core.h b/cd_utils/cdutils_core.h index 40af76a..3b9d274 100644 --- a/cd_utils/cdutils_core.h +++ b/cd_utils/cdutils_core.h @@ -37,6 +37,7 @@ public: void k_write(PIIODevice * d); void k_read(PIIODevice * d); void k_parse(PIIODevice * d); + void k_update(PIIODevice * d); private: Core(const char * conf = diff --git a/cd_utils/cdutils_k.cpp b/cd_utils/cdutils_k.cpp index ce4b502..c8abb3b 100644 --- a/cd_utils/cdutils_k.cpp +++ b/cd_utils/cdutils_k.cpp @@ -36,6 +36,11 @@ const KSection KInterface::section(int v) const { } +const KSection & KInterface::root() const { + return core->k_; +} + + void KInterface::send() { core->K_Send(); } @@ -58,3 +63,8 @@ void KInterface::read(PIIODevice * d) { void KInterface::parse(PIIODevice * d) { core->k_parse(d); } + + +void KInterface::update(PIIODevice * d) { + core->k_update(d); +} diff --git a/cd_utils/cdutils_k.h b/cd_utils/cdutils_k.h index bc9e363..0352edb 100644 --- a/cd_utils/cdutils_k.h +++ b/cd_utils/cdutils_k.h @@ -21,6 +21,7 @@ public: const KType operator [](int v) const; KSection & section(int v); const KSection section(int v) const; + const KSection & root() const; EVENT(sended) EVENT(received) @@ -29,6 +30,7 @@ public: void write(PIIODevice * d); void read(PIIODevice * d); void parse(PIIODevice * d); + void update(PIIODevice * d); private: Core * core; diff --git a/cd_utils/cdutils_k_parser.cpp b/cd_utils/cdutils_k_parser.cpp index 7a9240d..df306f2 100644 --- a/cd_utils/cdutils_k_parser.cpp +++ b/cd_utils/cdutils_k_parser.cpp @@ -80,7 +80,7 @@ KSection KParser::parse(PIIODevice * d) { if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) content = ((PIFile*)d)->readAll(); if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString*)d)->string()); PIIOString ios(&content); - int phase = 0; + //int phase = 0; int cind = -1; while ((cind = content.find("enum", cind)) >= 0) { ios.seek(cind); @@ -99,7 +99,7 @@ KSection KParser::parse(PIIODevice * d) { } cs = KSection(); cs.name = line; - piCout << "enum" << cs.name; + //piCout << "enum" << cs.name; int cev = 0; cevalues.clear(); while (!ios.isEnd()) { @@ -119,7 +119,7 @@ KSection KParser::parse(PIIODevice * d) { piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!"; return KSection(); } - piCout << "insert" << alias << iarr; + //piCout << "insert" << alias << iarr; int aval = enum_values.value(alias); KSection is = sections.value(iarr.take_front()), ts; piForeachRC (PIString & a, iarr) { @@ -136,10 +136,9 @@ KSection KParser::parse(PIIODevice * d) { } else { parseEnumLine(line, &cev, &comment); //piCout << line << "=" << cev << "//" << comment; - ck = KType(cev, "", "", comment); - ck.name = line; + ck = KType(cev, line, "", "", comment); cs[cev] = ck; - cevalues[ck.name] = cev; + cevalues[line] = cev; ++cev; } } diff --git a/cd_utils/cdutils_k_types.cpp b/cd_utils/cdutils_k_types.cpp index a13d892..6db7c65 100644 --- a/cd_utils/cdutils_k_types.cpp +++ b/cd_utils/cdutils_k_types.cpp @@ -12,8 +12,9 @@ KType::KType() { } -KType::KType(int i, const PIString & v, const PIString & f, const PIString & c) { +KType::KType(int i, const PIString & n, const PIString & v, const PIString & f, const PIString & c) { index_ = i; + name_ = n; value_s = v; formula_ = f; comment_ = c; @@ -37,7 +38,7 @@ void KSection::write(PIIODevice * d, const PIString & prefix) { KType & ck(i.value()); l.clear(); l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << "\n"; - l << ck.index() << ".v = " << ck.value() << "\n"; + l << ck.index() << ".v = " << ck.value() << " #s " << ck.name() << "\n"; d->write(l.toByteArray()); } } @@ -64,7 +65,7 @@ void KSection::read(const void * ep) { for (int i = 0; i < kl.childCount(); ++i) { const PIConfig::Entry * ke(kl.child(i)); int kid = ke->name().toInt(); - k[kid] = KType(kid, ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment()); + k[kid] = KType(kid, ke->getValue("v").comment(), ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment()); } PIConfig::Entry & sl = e.getValue("s"); for (int i = 0; i < sl.childCount(); ++i) { @@ -75,3 +76,29 @@ void KSection::read(const void * ep) { s[sid] = cs; } } + + +void KSection::update(KSection & v, bool keep_names) { + +} + + +bool KSection::isSameStructure(KSection & v) { + PIMap k_ids; + PIMap::iterator i; + for (i = k.begin(); i != k.end(); ++i) + k_ids[i.value().name()] = i.key(); + for (i = v.k.begin(); i != v.k.end(); ++i) { + if (!k_ids.contains(i.value().name())) continue; + //piCout << i.key() << k[i.key()].name() << i.value().name(); + if (k[k_ids[i.value().name()]].index() != i.key()) + return false; + } + PIMap::iterator j; + for (j = v.s.begin(); j != v.s.end(); ++j) { + if (!s.contains(j.key())) continue; + if (!s[j.key()].isSameStructure(j.value())) + return false; + } + return true; +} diff --git a/cd_utils/cdutils_k_types.h b/cd_utils/cdutils_k_types.h index 2fd7835..4e10d72 100644 --- a/cd_utils/cdutils_k_types.h +++ b/cd_utils/cdutils_k_types.h @@ -5,16 +5,20 @@ #include "pimap.h" class PIIODevice; +class CD_Pult; namespace CDUtils { class KSection; class KType { + friend class KSection; + friend class ::CD_Pult; public: KType(); - KType(int i, const PIString & v, const PIString & f, const PIString & c); + KType(int i, const PIString & n, const PIString & v, const PIString & f, const PIString & c); int index() const {return index_;} + PIString name() const {return name_;} PIString value() const {return value_s;} PIString formula() const {return formula_;} PIString comment() const {return comment_;} @@ -24,10 +28,10 @@ public: operator double() const {return value_d;} - PIString name; private: int index_; + PIString name_; PIString value_s, formula_, comment_; double value_d; int value_i; @@ -39,6 +43,7 @@ private: class KSection { friend class Core; friend class KInterface; + friend class ::CD_Pult; public: KSection() {} @@ -48,6 +53,7 @@ public: KSection & section(int v) {return s[v];} const KSection section(int v) const {return s[v];} + bool isEmpty() const {return k.isEmpty() && s.isEmpty();} PIVector indexes() const {return k.keys();} PIString name; @@ -59,6 +65,8 @@ private: } void write(PIIODevice * d, const PIString & prefix = PIString()); void read(const void * ep); + void update(KSection & v, bool keep_names); + bool isSameStructure(KSection & v); PIMap k; PIMap s; @@ -67,6 +75,6 @@ private: } -inline PICout operator <<(PICout s, const CDUtils::KType & v) {s.space(); s.setControl(0, true); s << "K[" << v.index() << "] = " << v.value(); s.restoreControl(); return s;} +inline PICout operator <<(PICout s, const CDUtils::KType & v) {s.space(); s.setControl(0, true); s << "K[" << v.name() << " (" << v.index() << ")] = " << v.value(); s.restoreControl(); return s;} #endif // CDUTILS_K_TYPES_H diff --git a/cd_utils/cdutilstest.cpp b/cd_utils/cdutilstest.cpp index f42fd58..1c2e8e9 100644 --- a/cd_utils/cdutilstest.cpp +++ b/cd_utils/cdutilstest.cpp @@ -37,12 +37,17 @@ int main(int argc, char *argv[]) { PIIOString iosw(&s); CDUtils::K.write(&iosw); piCout << s;*/ + + PIFile rf("1.txt", PIIODevice::ReadWrite); + CDUtils::K.read(&rf); + PIFile f; f.open("SH_base.h", PIIODevice::ReadOnly); - CDUtils::K.parse(&f); - PIIOString iosw(&s); - PIFile wf("1.txt", PIIODevice::ReadWrite); + CDUtils::K.update(&f); + + PIFile wf("2.txt", PIIODevice::ReadWrite); CDUtils::K.write(&wf); + //PIIOString iosw(&s); piCout << s; //piMSleep(1000); //CDUtils::Core::instance()->test();