From 8052406e54a7d9ba7cf1d05bdd3f1a3ade80eeb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Wed, 10 Aug 2016 11:13:43 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@113 a8b55f48-bf90-11e4-a774-851b48703e85 --- cd_utils/cdtest.h | 4 ++-- cd_utils/cdutils_core.cpp | 8 ++++--- cd_utils/cdutils_types.cpp | 44 +++++++++++++++++++++++++++++--------- cd_utils/cdutils_types.h | 2 +- cd_utils/cdutilstest.cpp | 25 +++++++++++++++++++++- 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/cd_utils/cdtest.h b/cd_utils/cdtest.h index 6a3e4b0..c2e45d6 100644 --- a/cd_utils/cdtest.h +++ b/cd_utils/cdtest.h @@ -3,8 +3,8 @@ enum KDescription { - First, //f - Second, //b + First, //f Первый + Second, //b Второй }; #endif // CDTEST_H diff --git a/cd_utils/cdutils_core.cpp b/cd_utils/cdutils_core.cpp index b25f6b8..6c1922f 100644 --- a/cd_utils/cdutils_core.cpp +++ b/cd_utils/cdutils_core.cpp @@ -151,12 +151,14 @@ void CDCore::K_Send() { PIString s; PIIOString ios(&s); k_write(&ios); - ios.close(); +// ios.close(); + piCout << s; //PIByteArray ba = PIByteArray::fromString(s); PIFile pf("k.txt", PIIODevice::ReadWrite); - pf.write(s.toUTF8()); + pf.resize(0); + pf.write(s.dataAscii(), s.lengthAscii()); //k_write(&pf); - piCout << pf.readLine(); + //piCout << pf.readLine(); } diff --git a/cd_utils/cdutils_types.cpp b/cd_utils/cdutils_types.cpp index e7e2c29..a13b754 100644 --- a/cd_utils/cdutils_types.cpp +++ b/cd_utils/cdutils_types.cpp @@ -1,5 +1,6 @@ #include "cdutils_types.h" #include "piconfig.h" +#include "pifile.h" using namespace CDUtils; @@ -15,15 +16,20 @@ CDType::CDType() { CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t) { index_ = i; - name_ = n; - type_ = t; - value_s = v; - formula_ = f; - comment_ = c; + name_ = n.trimmed(); + type_ = t.trimmed(); + value_s = v.trimmed(); + formula_ = f.trimmed(); + comment_ = c.trimmed(); value_d = v.toDouble(); value_i = v.toInt(); value_b = v.toBool(); cd_type_ = cd_t; +// piCout << type_.size() << type_.toUTF8(); +// piCout << formula_.size() << formula_.toUTF8(); +// piCout << comment_.size() << comment_.toUTF8(); + piCout << "[CDType]" << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK); + piCout << "[CDType]" << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment() << ":" << (cd_type_ == cdK); } @@ -55,13 +61,27 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) { if (prefix.isEmpty()) l = "[k]"; else l = "[" + prefix + ".k]"; l += "\n"; +// piCout << l; +// piCout << l.dataUTF8(); +// piCout << l.dataConsole(); +// piCout << l.dataAscii(); d->write(l.toUTF8()); PIMap::iterator i; for (i = k.begin(); i != k.end(); ++i) { CDType & ck(i.value()); + //l.clear(); + l = PIString::fromNumber(ck.index()) + ".f = " + ck.formula() + " #s " + ck.comment() + " \n"; +// piCout << l << ck.comment().size(); +// piCout << l.dataUTF8(); +// piCout << l.dataConsole(); +// piCout << l.dataAscii(); + d->write(l.toUTF8()); l.clear(); - l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << "\n"; - l << ck.index() << ".v = " << ck.value() << " #" << ck.type() << " " << ck.name() << "\n"; + l << ck.index() << ".v = " << ck.value() << " #" << ck.type() << " " << ck.name() << " \n"; +// piCout << l; +// piCout << l.dataUTF8(); +// piCout << l.dataConsole(); +// piCout << l.dataAscii(); d->write(l.toUTF8()); } } @@ -75,6 +95,10 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) { } if (prefix.isEmpty()) { l = "[]\n"; +// piCout << l; +// piCout << l.dataUTF8(); +// piCout << l.dataConsole(); +// piCout << l.dataAscii(); d->write(l.toUTF8()); } } @@ -88,9 +112,9 @@ void CDSection::read(const void * ep) { for (int i = 0; i < kl.childCount(); ++i) { const PIConfig::Entry * ke(kl.child(i)); int kid = ke->name().toInt(); - PIString n = ke->getValue("v").comment(); - PIString t = n.takeLeft(1); - k[kid] = CDType(kid, n.trim(), t, ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment(), CDType::cdK); +// PIString n = ke->getValue("v").comment(); +// PIString t = n.takeLeft(1); + k[kid] = CDType(kid, ke->getValue("v").comment(), ke->getValue("v").type(), ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment(), CDType::cdK); } PIConfig::Entry & sl = e.getValue("s"); for (int i = 0; i < sl.childCount(); ++i) { diff --git a/cd_utils/cdutils_types.h b/cd_utils/cdutils_types.h index f6cd2bc..6081e13 100644 --- a/cd_utils/cdutils_types.h +++ b/cd_utils/cdutils_types.h @@ -23,7 +23,7 @@ public: PIString type() const {return type_;} PIString value() const {return value_s;} PIString formula() const {return formula_;} - PIString comment() const {return comment_;} + PIString comment() const {piCout << "[CDType]" << name_ << comment_.size(); return comment_;} double toDouble() const {return value_d;} int toInt() const {return value_i;} bool toBool() const {return value_b;} diff --git a/cd_utils/cdutilstest.cpp b/cd_utils/cdutilstest.cpp index 8416c02..405117e 100644 --- a/cd_utils/cdutilstest.cpp +++ b/cd_utils/cdutilstest.cpp @@ -19,6 +19,28 @@ class Core : public PIObject void load() { rf.open("k.dat", PIIODevice::ReadWrite); K.read(&rf); + rf.close(); + } + + void save() { + rf.open("k_out.txt", PIIODevice::ReadWrite); + rf.resize(0); + K.write(&rf); + rf.close(); +// rf.open("k_out.txt", PIIODevice::ReadWrite); +// K.read(&rf); +// rf.close(); +// rf.open("k_out2.txt", PIIODevice::ReadWrite); +// rf.resize(0); +// K.write(&rf); +// rf.close(); +// rf.open("k_out2.txt", PIIODevice::ReadWrite); +// K.read(&rf); +// rf.close(); +// rf.open("k_out3.txt", PIIODevice::ReadWrite); +// rf.resize(0); +// K.write(&rf); +// rf.close(); } void test() { @@ -92,10 +114,11 @@ int main(int argc, char *argv[]) { screen.enableExitCapture('q'); //screen.start(); piCout << "start"; - + PIFile::setDefaultCharset("UTF-8"); Core core; core.load(); core.test(); + core.save(); K.send();