code format

This commit is contained in:
2022-12-14 14:13:33 +03:00
parent 37480c9d1f
commit 2622737a52
39 changed files with 1295 additions and 1265 deletions

View File

@@ -1,4 +1,5 @@
#include "cdutils_c.h"
#include "cdutils_core.h"
using namespace CDUtils;
@@ -6,8 +7,7 @@ using namespace CDUtils;
CInterface C;
CInterface::CInterface(): Interface(CDType::cdC) {
}
CInterface::CInterface(): Interface(CDType::cdC) {}
void CInterface::sendCommand(const CDType & c) {
@@ -28,10 +28,10 @@ void CInterface::autoConnect(PIObject * o, const PIString & prefix) {
PIObject::__MetaData & md(PIObject::__meta_data()[cid]);
for (auto it = md.eh_func.begin(); it != md.eh_func.end(); ++it) {
eh_map[it.value().func_name] = (Handler)it.value().addr;
//piCout << "func" << it.value().func_name;
// piCout << "func" << it.value().func_name;
}
PIVector<CDType * > cl = C.root().children();
piForeachC (CDType * c, cl) {
PIVector<CDType *> cl = C.root().children();
piForeachC(CDType * c, cl) {
PIString cp = prefix + c->pathString().join("_");
if (cp.isEmpty()) continue;
if (!eh_map.contains(cp)) continue;

View File

@@ -1,45 +1,44 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_C_H
#define CDUTILS_C_H
#include "cdutils_interface.h"
#include "cdutils_core.h"
#include "cdutils_interface.h"
namespace CDUtils {
class CD_CORE_EXPORT CInterface: public Interface
{
class CD_CORE_EXPORT CInterface: public Interface {
PIOBJECT_SUBCLASS(CInterface, Interface);
public:
CInterface();
void sendCommand(const CDType & c);
void connect(const CDType & c, PIObject * o, Handler eh);
void autoConnect(PIObject * o, const PIString & prefix = PIStringAscii("c_"));
};
}
} // namespace CDUtils
extern CD_CORE_EXPORT CDUtils::CInterface C;

View File

@@ -1,14 +1,14 @@
#include "cdutils_core.h"
#include "cdutils_parser.h"
#include "piconfig.h"
#include "pifile.h"
#include "piiobytearray.h"
#include "piiostring.h"
#include "pifile.h"
using namespace CDUtils;
const char CDCore::app_config[] =
"include = cd_ip.conf\n\
const char CDCore::app_config[] = "include = cd_ip.conf\n\
port_rec = 2\n\
port_send = 1\n\
[connection]\n\
@@ -17,8 +17,7 @@ const char CDCore::app_config[] =
connectionmodel = AAAM2Xja7VXLTttAFD12QpsikKjUSixYlLbKEpIUtVIlVEfqhk2FWuiGRRolUYtoHgrmpYiv6IItf8AveMMH9E/YsG6Ph3sde5hGoQoblLGuPHfunTPjc49nADxDA110+LTYC7FrPCAPeAO+vZu+aX7c/8PGd45WCJC0OGcfT6FDnmfSTPtwhZFt3HjgDs/Qtu5jPbZHtI/x50XfIzMQbdwEolbg9INP4ku++myPaUtCHYRaT2j1ldIh3VP60/Qff8vSfXLu9BP6JX9K/0TVH6jqVe22P1X/fao/oddWu/paDs1vBf9Jv/EZ91clbyHqv7BL6sscDOd4v4WTqs6jzaHGJ8QJerxlpJSpdZ7IWFJvDW7I2JxZqIM62k6A57RZmMQGmlyrxdV+WGBnmR01mXPI267hBKwp4FeBeo9VPtssxyb7rzHg1B7T9nCMU45U8BZlWuVWtIcD/CRGOqtsbW09851tXsHN0UTlLIAdASjSXnLyLn+H7L2+xbGYvC63Ezqg543egkLmn8qnRF6USbM4Qp9godkhzI777Ne5bCIt/5UtGz2o/yGby0nKpjqmbOa1ynkjmyzIrzvIZUeBPjvlUmbh32EFJbGyJZhR8YcvlS+3TpjhqeWSyvUkpbI9plSWtcKLcsK05beOJVEnhaEFfHEH+RwpeMcpn1JKGqWMNOL+G6wZyahlpdVOtufKfbDS+guLke9O\n\
";
const char CDCore::pult_config[] =
"include = cd_ip.conf\n\
const char CDCore::pult_config[] = "include = cd_ip.conf\n\
port_rec = 1\n\
port_send = 2\n\
[connection]\n\
@@ -55,8 +54,6 @@ __Core_Initializer__::~__Core_Initializer__() {
}
CDCore::CDCore() {
setName("CDCore");
x_timer.setName("__S__.CDCore.x_timer");
@@ -67,10 +64,10 @@ CDCore::CDCore() {
connection.configureFromString(&s);
connection.start();*/
need_rebuild_x = x_pult_side = false;
k_.cd_type_ = CDType::cdK;
x_.cd_type_ = CDType::cdX;
c_.cd_type_ = CDType::cdC;
m_.cd_type_ = CDType::cdM;
k_.cd_type_ = CDType::cdK;
x_.cd_type_ = CDType::cdX;
c_.cd_type_ = CDType::cdC;
m_.cd_type_ = CDType::cdM;
initRoot(&k_);
initRoot(&x_);
initRoot(&c_);
@@ -89,7 +86,7 @@ CDCore::CDCore() {
k_.section(11)[3] = KType(3, "1", "1", "88");
k_.section(11)[4] = KType(4, "0", "0", "88");
k_.section(11)[6] = KType(6, "0", "0", "88");*/
//piCout << s;
// piCout << s;
}
@@ -110,14 +107,13 @@ void CDCore::cd_write(CDSection * cd, PIIODevice * d) {
void CDCore::cd_read(CDSection * cd, PIIODevice * d) {
PIConfig conf(d, PIIODevice::ReadOnly);
cd->read(&(conf.rootEntry()));
if (cd->cd_type_ == CDType::cdX)
x_selected = cd->collectX();
if (cd->cd_type_ == CDType::cdX) x_selected = cd->collectX();
initRoot(cd);
raiseChangedGlobal(cd->cd_type_);
/*PIVector<PIIODevice * > ds = connection.allDevices();
piForeach(PIIODevice * d, ds) {
if (d)
piCoutObj << d->constructFullPath() << d->isOpened();
if (d)
piCoutObj << d->constructFullPath() << d->isOpened();
}*/
}
@@ -134,12 +130,12 @@ void CDCore::cd_update(CDSection * cd, PIIODevice * d, UpdateModeFlags mode) {
cd_parse(cd, d);
/*bool kn = true;
if (!ucd.isEmpty())
if (!ucd.isSameStructure(k_)) {
piCout << "ask for save names";
K_KeepNamesRequest(&kn);
}*/
if (!ucd.isSameStructure(k_)) {
piCout << "ask for save names";
K_KeepNamesRequest(&kn);
}*/
ucd.update(*cd, mode);
//piCout << k_.count() << ucd.count();
// piCout << k_.count() << ucd.count();
*cd = ucd;
initRoot(cd);
raiseChangedGlobal(cd->cd_type_);
@@ -157,7 +153,7 @@ void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) {
PIByteArray ba, sba;
PIIOByteArray iob(&ba, PIIODevice::ReadWrite);
cd_write(cd, &iob);
//piCoutObj << PIString(ba);
// piCoutObj << PIString(ba);
sba = makeHeader(pt, 0);
sba << ba;
if (direct)
@@ -208,7 +204,7 @@ void CDCore::initPult() {
void CDCore::init(const PIString & configuration, bool pult) {
PIString c = configuration;
//piCoutObj << "init" << c;
// piCoutObj << "init" << c;
connection.stop();
connection.removeAllDevices();
connection.configureFromString(&c);
@@ -230,9 +226,8 @@ void CDCore::release() {
void CDCore::startX(double freq) {
//piCout << "start x" << x_timer.isRunning() << freq;
if (!x_timer.isRunning())
x_timer.start(1000. / piMaxd(freq, 0.01));
// piCout << "start x" << x_timer.isRunning() << freq;
if (!x_timer.isRunning()) x_timer.start(1000. / piMaxd(freq, 0.01));
}
@@ -242,7 +237,7 @@ void CDCore::stopX() {
void CDCore::sendCommand(const CDType & c) {
//piCoutObj << "C_sendCommand" << c;
// piCoutObj << "C_sendCommand" << c;
PIByteArray sba = makeHeader(CD_Command, 0);
sba << c.path();
sendDirect(sba);
@@ -252,7 +247,7 @@ void CDCore::sendCommand(const CDType & c) {
void CDCore::registerCHandler(const CDType & c, PIObject * o, Handler h) {
PIString sp = pathToString(c.path());
if (sp.isEmpty() || !h) return;
//piCout << "register" << sp;
// piCout << "register" << sp;
c_handlers[sp] = OHPair(o, h);
}
@@ -298,20 +293,20 @@ CDCore * CDCore::instance() {
bool CDCore::destroy() {
if (!__Core_Initializer__::__instance__) return false;
// piCout << "delete Core ...";
// piCout << "delete Core ...";
delete __Core_Initializer__::__instance__;
// piCout << "delete Core ok";
// piCout << "delete Core ok";
__Core_Initializer__::__instance__ = 0;
__Core_Initializer__::count_ = 0;
__Core_Initializer__::count_ = 0;
return true;
}
void CDUtils::CDCore::K_DirectChange(PIDeque<int> path, PIString value) {
// piCoutObj << "K_DirectChange";
// piCoutObj << "K_DirectChange";
PacketKDirectChange p;
p.path = path;
p.value = value;
p.path = path;
p.value = value;
PIByteArray sba = makeHeader(CD_KDirectChange, 0);
sba << p;
sendDirect(sba);
@@ -325,29 +320,37 @@ void CDCore::sendThread() {
bool ok = datatr.send(send_data);
switch (h.type) {
case CD_KSend:
if (ok) K_Sended();
else K_SendFail();
if (ok)
K_Sended();
else
K_SendFail();
break;
case CD_KQuery:
if (!ok) K_ReceiveFail();
break;
case CD_XSend:
if (ok) X_Sended();
else X_SendFail();
if (ok)
X_Sended();
else
X_SendFail();
break;
case CD_XQuery:
if (!ok) X_ReceiveFail();
break;
case CD_CSend:
if (ok) C_Sended();
else C_SendFail();
if (ok)
C_Sended();
else
C_SendFail();
break;
case CD_CQuery:
if (!ok) C_ReceiveFail();
break;
case CD_MSend:
if (ok) M_Sended();
else M_SendFail();
if (ok)
M_Sended();
else
M_SendFail();
break;
case CD_MQuery:
if (!ok) M_ReceiveFail();
@@ -358,25 +361,25 @@ void CDCore::sendThread() {
void CDCore::xTimerTick() {
//piCout << "x tick" << x_pult_side;
// piCout << "x tick" << x_pult_side;
PIByteArray ba;
x_mutex.lock();
if (x_pult_side) {
ba = makeHeader(CD_XRequest, 0);
if (need_rebuild_x) {
x_selected = x_.collectX();
//piCout << "collectX" << x_selected.size();
x_selected = x_.collectX();
// piCout << "collectX" << x_selected.size();
need_rebuild_x = false;
}
ba << x_selected;
//piCout << "x pult send" << x_selected.size();
// piCout << "x pult send" << x_selected.size();
} else {
ba = makeHeader(CD_XValues, 0);
ba << x_selected;
piForeachC (PIDeque<int> & p, x_selected) {
piForeachC(PIDeque<int> & p, x_selected) {
x_[p].writeX(ba);
}
//piCout << "x app" << x_selected.size();
// piCout << "x app" << x_selected.size();
}
x_mutex.unlock();
sendDirect(ba);
@@ -385,7 +388,7 @@ void CDCore::xTimerTick() {
void CDCore::piCoutFinished(int id, PIString * buffer) {
if (!buffer || !(id == 1)) return;
PIString sp = buffer->takeRange("[", "]");
PIString sp = buffer->takeRange("[", "]");
PIDeque<int> p = CDCore::stringToPath(sp);
sendMessage(m_[p], Log, *buffer);
delete buffer;
@@ -393,7 +396,7 @@ void CDCore::piCoutFinished(int id, PIString * buffer) {
void CDCore::initRoot(CDSection * r) {
r->name = "__root__";
r->name = "__root__";
r->alias = "root";
r->makePath();
r->calculate();
@@ -402,9 +405,10 @@ void CDCore::initRoot(CDSection * r) {
PIByteArray CDCore::makeHeader(CDPacketType type, int session_id) const {
PacketHeader h;
h.type = type;
h.type = type;
h.session_id = session_id;
PIByteArray ret; ret << h;
PIByteArray ret;
ret << h;
return ret;
}
@@ -428,13 +432,11 @@ void CDCore::sendThreaded(PIByteArray & ba) {
void CDCore::procReceivedPacket(PIByteArray & ba) {
PacketHeader h;
ba >> h;
switch(h.type) {
switch (h.type) {
case CD_Ping:
//piCoutObj << "ping";
break;
case CD_KQuery:
send(CDType::cdK);
// piCoutObj << "ping";
break;
case CD_KQuery: send(CDType::cdK); break;
case CD_KSend: {
PIByteArray k;
ba >> k;
@@ -444,15 +446,13 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
cd_read(&k_, &ios);
K_Received();
piCoutObj << "K received";
} break;
} break;
case CD_KDirectChange: {
PacketKDirectChange p;
ba >> p;
k_[p.path].setValue(p.value);
} break;
case CD_XQuery:
send(CDType::cdX);
break;
} break;
case CD_XQuery: send(CDType::cdX); break;
case CD_XSend: {
PIByteArray x;
ba >> x;
@@ -463,34 +463,32 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
x_selected = x_.collectX();
X_Received();
piCoutObj << "X received";
} break;
} break;
case CD_XRequest: {
if (x_pult_side) break;
//break;
// break;
x_mutex.lock();
x_selected.clear();
ba >> x_selected;
//piCout << "X req" << x_selected.size();
// piCout << "X req" << x_selected.size();
x_.setSelectedX(false);
piForeachC (PIDeque<int> & p, x_selected) {
piForeachC(PIDeque<int> & p, x_selected) {
x_[p].x_enabled = true;
}
x_mutex.unlock();
} break;
} break;
case CD_XValues: {
if (!x_pult_side) break;
PIVector<PIDeque<int> > x_vals;
PIVector<PIDeque<int>> x_vals;
ba >> x_vals;
x_mutex.lock();
piForeachC (PIDeque<int> & p, x_vals) {
piForeachC(PIDeque<int> & p, x_vals) {
x_[p].readX(ba);
}
x_mutex.unlock();
X_ReceivedX(x_vals);
} break;
case CD_CQuery:
send(CDType::cdC);
break;
} break;
case CD_CQuery: send(CDType::cdC); break;
case CD_CSend: {
piCoutObj << "C received";
PIByteArray c;
@@ -500,20 +498,18 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
PIIOString ios(&s);
cd_read(&c_, &ios);
C_Received();
} break;
} break;
case CD_Command: {
piCoutObj << "C command";
PIDeque<int> p;
ba >> p;
if (p.isEmpty()) return;
PIString sp = pathToString(p);
OHPair h = c_handlers.value(sp, OHPair(0, 0));
//piCoutObj << "found" << sp << h.first;
OHPair h = c_handlers.value(sp, OHPair(0, 0));
// piCoutObj << "found" << sp << h.first;
if (h.first && h.second) h.second(h.first);
} break;
case CD_MQuery:
send(CDType::cdM);
break;
} break;
case CD_MQuery: send(CDType::cdM); break;
case CD_MSend: {
piCoutObj << "M received";
PIByteArray c;
@@ -523,7 +519,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
PIIOString ios(&s);
cd_read(&m_, &ios);
M_Received();
} break;
} break;
case CD_Message: {
PIDeque<int> p;
ba >> p;
@@ -532,10 +528,10 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
int t = 0;
PIString msg;
ba >> t >> msg;
//piCoutObj << "found" << sp << h.first;
//piCoutObj << "M message invoke";
// piCoutObj << "found" << sp << h.first;
// piCoutObj << "M message invoke";
M_Message(p, t, msg);
} break;
} break;
default: break;
}
}
@@ -565,19 +561,19 @@ PIString CDCore::pathToString(const PIDeque<int> & p) {
PIDeque<int> CDCore::stringToPath(const PIString & p) {
PIDeque<int> ret;
PIStringList sl = p.split(".");
piForeachC (PIString & s, sl)
piForeachC(PIString & s, sl)
ret << s.toInt();
return ret;
}
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
//piCoutObj << "dataReceived" << from << data.size();
// piCoutObj << "dataReceived" << from << data.size();
PIIODevice * d = connection.deviceByName("cd");
if (d && d == connection.deviceByFullPath(from)) {
if (data.size() >= sizeof(4)) {
PIByteArray ba = data;
uchar header = ba.take_front();
uchar header = ba.take_front();
if (header == header_transfer) {
datatr.received(ba);
}
@@ -592,7 +588,7 @@ void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & da
void CDCore::dtSendRequest(PIByteArray & data) {
data.push_front(header_transfer);
connection.writeByName("cd", data);
//piCoutObj << "send" << data.size() << ret;
// piCoutObj << "send" << data.size() << ret;
}
@@ -601,4 +597,3 @@ void CDCore::dtReceiveFinished(bool ok) {
PIByteArray ba = datatr.data();
procReceivedPacket(ba);
}

View File

@@ -1,37 +1,37 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_CORE_H
#define CDUTILS_CORE_H
#include "cdutils_types.h"
#include "cd_core_export.h"
#include "cdutils_protocol.h"
#include "cdutils_types.h"
#include "piconnection.h"
#include "pidatatransfer.h"
#include "cd_core_export.h"
namespace CDUtils {
class CDCore;
typedef void (*Handler)(void*);
typedef void (*Handler)(void *);
class CD_CORE_EXPORT __Core_Initializer__ {
public:
@@ -42,13 +42,13 @@ public:
};
class CD_CORE_EXPORT CDCore: public PIObject
{
class CD_CORE_EXPORT CDCore: public PIObject {
PIOBJECT(CDUtils::CDCore);
friend class __Core_Initializer__;
friend class CDSection;
friend class Interface;
friend class XInterface;
public:
static CDCore * instance();
static bool destroy();
@@ -65,7 +65,7 @@ public:
EVENT(X_Received);
EVENT(X_ReceiveFail);
EVENT(X_ChangedGlobal);
EVENT1(X_ReceivedX, PIVector<PIDeque<int> >, pathes);
EVENT1(X_ReceivedX, PIVector<PIDeque<int>>, pathes);
EVENT(C_Sended);
EVENT(C_SendFail);
@@ -80,12 +80,12 @@ public:
EVENT(M_ChangedGlobal);
EVENT3(M_Message, PIDeque<int>, path, int, type, PIString, msg);
void cd_write (CDSection * cd, PIIODevice * d);
void cd_read (CDSection * cd, PIIODevice * d);
void cd_parse (CDSection * cd, PIIODevice * d);
void cd_update (CDSection * cd, PIIODevice * d, UpdateModeFlags mode);
void cd_write(CDSection * cd, PIIODevice * d);
void cd_read(CDSection * cd, PIIODevice * d);
void cd_parse(CDSection * cd, PIIODevice * d);
void cd_update(CDSection * cd, PIIODevice * d, UpdateModeFlags mode);
void cd_calculate(CDSection * cd);
void cd_send (CDSection * cd, CDPacketType pt, bool direct = false);
void cd_send(CDSection * cd, CDPacketType pt, bool direct = false);
void send(CDType::cdT cdt);
void request(CDType::cdT cdt);
void initApp();
@@ -97,7 +97,7 @@ public:
void stopX();
void sendCommand(const CDType & c);
void registerCHandler(const CDType & c, PIObject * o, Handler h);
bool inProgress() {return sendt.isRunning();}
bool inProgress() { return sendt.isRunning(); }
void sendMessage(const CDType & m, MessageType mt, const PIString & msg);
CDSection * root(CDType::cdT cdt);
@@ -105,8 +105,8 @@ public:
static PIString pathToString(const PIDeque<int> & p);
static PIDeque<int> stringToPath(const PIString & p);
static PIString pultConfig() {return PIString(pult_config);}
static PIString appConfig() {return PIString(app_config);}
static PIString pultConfig() { return PIString(pult_config); }
static PIString appConfig() { return PIString(app_config); }
private:
CDCore();
@@ -116,7 +116,7 @@ private:
EVENT_HANDLER1(void, dtReceiveFinished, bool, ok);
EVENT_HANDLER(void, sendThread);
EVENT_HANDLER(void, xTimerTick);
EVENT_HANDLER2(void, piCoutFinished, int, id, PIString*, buffer);
EVENT_HANDLER2(void, piCoutFinished, int, id, PIString *, buffer);
void initRoot(CDSection * r);
PIByteArray makeHeader(CDPacketType type, int session_id = 0) const;
void sendDirect(PIByteArray & ba);
@@ -124,7 +124,7 @@ private:
void procReceivedPacket(PIByteArray & ba);
void raiseChangedGlobal(CDType::cdT cdt);
typedef PIPair<PIObject * , Handler> OHPair;
typedef PIPair<PIObject *, Handler> OHPair;
static const char app_config[], pult_config[];
PIConnection connection;
@@ -134,15 +134,14 @@ private:
PITimer x_timer;
CDSection k_, x_, c_, m_;
PIMutex x_mutex;
PIVector<PIDeque<int> > x_selected;
PIVector<PIDeque<int>> x_selected;
PIMap<PIString, OHPair> c_handlers;
bool need_rebuild_x, x_pult_side;
};
static __Core_Initializer__ __Core_initializer__;
}
} // namespace CDUtils
#endif // CDUTILS_CORE_H

View File

@@ -1,4 +1,5 @@
#include "cdutils_interface.h"
#include "cdutils_core.h"
#include "piconfig.h"
#include "pifile.h"
@@ -7,11 +8,11 @@ using namespace CDUtils;
Interface::Interface(CDType::cdT type_) {
core = CDCore::instance();
s = core->root(type_);
type = type_;
//piCoutObj << (void*)this << core;
file_ = core->typeLetter(type_) + PIStringAscii(".dat");
core = CDCore::instance();
s = core->root(type_);
type = type_;
// piCoutObj << (void*)this << core;
file_ = core->typeLetter(type_) + PIStringAscii(".dat");
file_size = 0;
switch (type) {
case CDType::cdK:
@@ -52,41 +53,41 @@ bool Interface::test(int v) {
}
CDType & Interface::operator [](const PIString & name_) {
CDType & Interface::operator[](const PIString & name_) {
return (*s)[name_];
}
const CDType Interface::operator [](const PIString & name_) const {
const CDType Interface::operator[](const PIString & name_) const {
return (*s)[name_];
}
CDType & Interface::operator [](const PIDeque<int> & path_) {
CDType & Interface::operator[](const PIDeque<int> & path_) {
return (*s)[path_];
}
const CDType Interface::operator [](const PIDeque<int> & path_) const {
const CDType Interface::operator[](const PIDeque<int> & path_) const {
return (*s)[path_];
}
CDType & Interface::operator [](int v) {
//piCout << (void*)this << "[]" << core;
CDType & Interface::operator[](int v) {
// piCout << (void*)this << "[]" << core;
return (*s)[v];
}
const CDType Interface::operator [](int v) const {
//piCout << (void*)this << "[]" << core;
const CDType Interface::operator[](int v) const {
// piCout << (void*)this << "[]" << core;
return (*s)[v];
}
CDSection & Interface::section(int v) {
// CDSection & ret = s->section(v);
// piCout << "[get section]" << v << ret.name;
// CDSection & ret = s->section(v);
// piCout << "[get section]" << v << ret.name;
return s->section(v);
}
@@ -96,9 +97,9 @@ const CDSection Interface::section(int v) const {
}
CDSection & Interface::section(const PIDeque<int> &path) {
CDSection & Interface::section(const PIDeque<int> & path) {
PIDeque<int> spath = path;
CDSection * rs = s;
CDSection * rs = s;
while (!spath.isEmpty()) {
rs = &(rs->section(spath.take_front()));
}

View File

@@ -1,28 +1,28 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_INTERFACE_H
#define CDUTILS_INTERFACE_H
#include "cd_core_export.h"
#include "cdutils_types.h"
#include "piobject.h"
#include "cd_core_export.h"
namespace CDUtils {
@@ -30,19 +30,19 @@ namespace CDUtils {
class CDCore;
class CD_CORE_EXPORT Interface: public PIObject
{
class CD_CORE_EXPORT Interface: public PIObject {
PIOBJECT(CDUtils::Interface);
public:
Interface(CDType::cdT type_);
bool test(int v);
CDType & operator [](int v);
const CDType operator [](int v) const;
CDType & operator [](const PIString & name_);
const CDType operator [](const PIString & name_) const;
CDType & operator [](const PIDeque<int> & path_);
const CDType operator [](const PIDeque<int> & path_) const;
CDType & operator[](int v);
const CDType operator[](int v) const;
CDType & operator[](const PIString & name_);
const CDType operator[](const PIString & name_) const;
CDType & operator[](const PIDeque<int> & path_);
const CDType operator[](const PIDeque<int> & path_) const;
CDSection & section(int v);
const CDSection section(int v) const;
CDSection & section(const PIDeque<int> & path);
@@ -50,9 +50,9 @@ public:
const CDSection & root() const;
int count(bool recursive = true) const;
const PIString file() const {return file_;}
int fileSize() const {return file_size;}
CDType::cdT cdType() const {return type;}
const PIString file() const { return file_; }
int fileSize() const { return file_size; }
CDType::cdT cdType() const { return type; }
bool exists(PIDeque<int> path) const;
void setFileName(const PIString & _file);
@@ -86,11 +86,10 @@ protected:
CDType::cdT type;
PIString file_;
int file_size;
};
}
} // namespace CDUtils
#endif // CDUTILS_INTERFACE_H

View File

@@ -1,4 +1,5 @@
#include "cdutils_k.h"
#include "cdutils_core.h"
using namespace CDUtils;
@@ -6,8 +7,7 @@ using namespace CDUtils;
KInterface K;
KInterface::KInterface(): Interface(CDType::cdK) {
}
KInterface::KInterface(): Interface(CDType::cdK) {}
void KInterface::directChange(const CDType & k) {

View File

@@ -1,46 +1,45 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_K_H
#define CDUTILS_K_H
#include "cdutils_interface.h"
#include "cd_core_export.h"
#include "cdutils_interface.h"
namespace CDUtils {
class CD_CORE_EXPORT KInterface: public Interface
{
class CD_CORE_EXPORT KInterface: public Interface {
PIOBJECT_SUBCLASS(KInterface, Interface);
public:
KInterface();
EVENT1(keepNamesRequest, bool*, kn);
EVENT1(keepNamesRequest, bool *, kn);
void directChange(const CDType & k);
void directChange(const CDType & k, double v);
};
}
} // namespace CDUtils
extern CD_CORE_EXPORT CDUtils::KInterface K;

View File

@@ -1,4 +1,5 @@
#include "cdutils_m.h"
#include "cdutils_core.h"
using namespace CDUtils;

View File

@@ -1,44 +1,44 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_M_H
#define CDUTILS_M_H
#include "cdutils_interface.h"
#include "cd_core_export.h"
#include "cdutils_interface.h"
namespace CDUtils {
class CD_CORE_EXPORT MInterface: public Interface
{
class CD_CORE_EXPORT MInterface: public Interface {
PIOBJECT_SUBCLASS(MInterface, Interface);
public:
MInterface();
PICout operator [](int v) {return createPICout((*s)[v]);}
PICout operator [](int v) const {return createPICout((*s)[v]);}
PICout operator [](const PIString & name_) {return createPICout((*s)[name_]);}
PICout operator [](const PIString & name_) const {return createPICout((*s)[name_]);}
PICout operator [](const PIDeque<int> & path_) {return createPICout((*s)[path_]);}
PICout operator [](const PIDeque<int> & path_) const {return createPICout((*s)[path_]);}
PICout operator[](int v) { return createPICout((*s)[v]); }
PICout operator[](int v) const { return createPICout((*s)[v]); }
PICout operator[](const PIString & name_) { return createPICout((*s)[name_]); }
PICout operator[](const PIString & name_) const { return createPICout((*s)[name_]); }
PICout operator[](const PIDeque<int> & path_) { return createPICout((*s)[path_]); }
PICout operator[](const PIDeque<int> & path_) const { return createPICout((*s)[path_]); }
void messageBox(const CDType & m, const PIString & msg);
@@ -46,10 +46,9 @@ public:
private:
PICout createPICout(const CDType & m) const;
};
}
} // namespace CDUtils
extern CD_CORE_EXPORT CDUtils::MInterface M;

View File

@@ -1,8 +1,9 @@
#include "cdutils_parser.h"
#include "cdutils_types.h"
#include "piiostring.h"
#include "piiobytearray.h"
#include "pifile.h"
#include "piiobytearray.h"
#include "piiostring.h"
using namespace CDUtils;
@@ -63,14 +64,14 @@ PIVector<int> enumValues(const PIString & e, const PIMap<PIString, CDSection> &
PIVector<int> ret;
enames.clear();
if (sections.contains(e)) {
ret = sections.at(e).indexes();
ret = sections.at(e).indexes();
enames = sections.at(e).index_names();
} else {
int v = e.toInt();
if (v < 2) return ret;
for (int i = 0; i < v; ++i) {
ret << i;
enames << "";//PIString::fromNumber(i);
enames << ""; // PIString::fromNumber(i);
}
}
return ret;
@@ -81,7 +82,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
CDType::cdT et = (CDType::cdT)cdsection_type;
if (!d) return CDSection(et);
if (!d->canRead()) return CDSection(et);
//piCout << "[CDSection] parse start";
// piCout << "[CDSection] parse start";
CDSection cs(et);
CDType ck;
PIMap<PIString, CDSection> sections;
@@ -89,14 +90,14 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
PIString content, line, alias, type, comment;
PIStringList iarr;
if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) {
PIByteArray c = ((PIFile*)d)->readAll();
PIByteArray c = ((PIFile *)d)->readAll();
c << uchar(0);
content = PIString::fromUTF8((const char *)c.data());
}
if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString*)d)->string());
if (PIStringAscii(d->className()) == PIStringAscii("PIIOByteArray")) content = PIString(*(((PIIOByteArray*)d)->byteArray()));
if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString *)d)->string());
if (PIStringAscii(d->className()) == PIStringAscii("PIIOByteArray")) content = PIString(*(((PIIOByteArray *)d)->byteArray()));
PIIOString ios(&content);
//int phase = 0;
// int phase = 0;
int cind = -1;
while ((cind = content.find("enum", cind)) >= 0) {
ios.seek(cind);
@@ -114,11 +115,11 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
cind += 4;
continue;
}
cs = CDSection(et);
cs = CDSection(et);
cs.name = line;
//piCout << "enum" << cs.name;
// piCout << "enum" << cs.name;
int cev = 0;
// cevalues.clear();
// cevalues.clear();
while (!ios.isEnd()) {
line = ios.readLine().trim();
comment.clear();
@@ -128,7 +129,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
if (comment.find("=") >= 0) {
parseInsert(comment, alias, iarr);
if (!iarr.isEmpty()) {
// piCout << "#" << enum_values;
// piCout << "#" << enum_values;
if (!enum_values.contains(alias)) {
piCout << "Parse error: can`t find section alias \"" << alias << "\"!";
return CDSection(et);
@@ -137,16 +138,16 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!";
return CDSection(et);
}
//piCout << "insert" << alias << iarr;
int aval = enum_values.value(alias);
// piCout << "insert" << alias << iarr;
int aval = enum_values.value(alias);
CDSection is = sections.value(iarr.take_front()), ts;
int ibpos = is.name.size_s();
piForeachRC (PIString & a, iarr) {
int ibpos = is.name.size_s();
piForeachRC(PIString & a, iarr) {
PIStringList enames;
PIVector<int> evals = enumValues(a, sections, enames);
//piCout << a << evals;
// piCout << a << evals;
for (int i = 0; i < evals.size_s(); ++i) {
ts.section(evals[i]) = is;
ts.section(evals[i]) = is;
ts.section(evals[i]).alias = enames[i];
}
ts.name = is.name;
@@ -154,13 +155,13 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
is = ts;
ts = CDSection(et);
}
is.alias = alias;
is.alias = alias;
cs.section(aval) = is;
}
}
} else {
parseEnumLine(line, &cev, &type, &comment);
//piCout << line << "=" << cev << "//" << type << comment;
// piCout << line << "=" << cev << "//" << type << comment;
ck = CDType(cev, line, type, "", "", comment, et);
if (type == "e") {
if (comment.startsWith("${")) {
@@ -169,22 +170,22 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
comment.cutLeft(en.size_s() + 2).trim();
ck.setEnumValues(sections.value(en).enumValues());
ck.setComment(comment);
//piCout << "enum" << en << ck.enumValues();
// piCout << "enum" << en << ck.enumValues();
}
}
cs[cev] = ck;
//cevalues[line] = cev;
cs[cev] = ck;
// cevalues[line] = cev;
enum_values[line] = cev;
++cev;
}
}
//piCout << cs.name << cs.k;
// piCout << cs.name << cs.k;
sections[cs.name] = cs;
// piCout << "#" << cevalues;
// enum_values << cevalues;
// piCout << "#" << cevalues;
// enum_values << cevalues;
cind += 4;
}
// piCout << "[CDSection] parse end";
// piCout << "[CDSection] parse end";
switch (et) {
case CDType::cdK: return sections.value("KDescription");
case CDType::cdX: return sections.value("XDescription");

View File

@@ -1,20 +1,20 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_PARSER_H
@@ -34,6 +34,6 @@ CD_CORE_EXPORT CDSection parse(PIIODevice * d, int cdsection_type);
}
}
} // namespace CDUtils
#endif // CDUTILS_PARSER_H

View File

@@ -1,74 +1,86 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_PROTOCOL_H
#define CDUTILS_PROTOCOL_H
#include "pistring.h"
#include "cd_core_export.h"
#include "pistring.h"
namespace CDUtils {
enum CDPacketType {
CD_Ping,
CD_Pong,
enum CDPacketType {
CD_Ping,
CD_Pong,
CD_KQuery,
CD_KSend,
CD_KDirectChange,
CD_KQuery,
CD_KSend,
CD_KDirectChange,
CD_XQuery,
CD_XSend,
CD_XRequest,
CD_XValues,
CD_XQuery,
CD_XSend,
CD_XRequest,
CD_XValues,
CD_CQuery,
CD_CSend,
CD_Command,
CD_CQuery,
CD_CSend,
CD_Command,
CD_MQuery,
CD_MSend,
CD_Message,
};
CD_MQuery,
CD_MSend,
CD_Message,
};
# pragma pack(push,1)
#pragma pack(push, 1)
struct CD_CORE_EXPORT PacketHeader {
int type; // CDPacketType
int session_id;
};
struct CD_CORE_EXPORT PacketHeader {
int type; // CDPacketType
int session_id;
};
struct CD_CORE_EXPORT PacketKDirectChange {
PIDeque<int> path;
PIString value;
};
struct CD_CORE_EXPORT PacketKDirectChange {
PIDeque<int> path;
PIString value;
};
# pragma pack(pop)
#pragma pack(pop)
#ifdef PIP_BINARY_STREAM
BINARY_STREAM_WRITE(PacketKDirectChange) {s << v.path << v.value; return s;}
BINARY_STREAM_READ (PacketKDirectChange) {s >> v.path >> v.value; return s;}
BINARY_STREAM_WRITE(PacketKDirectChange) {
s << v.path << v.value;
return s;
}
BINARY_STREAM_READ(PacketKDirectChange) {
s >> v.path >> v.value;
return s;
}
#else
inline PIByteArray & operator <<(PIByteArray & s, const PacketKDirectChange & v) {s << v.path << v.value; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PacketKDirectChange & v) {s >> v.path >> v.value; return s;}
inline PIByteArray & operator<<(PIByteArray & s, const PacketKDirectChange & v) {
s << v.path << v.value;
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, PacketKDirectChange & v) {
s >> v.path >> v.value;
return s;
}
#endif
}
} // namespace CDUtils
#endif // CDUTILS_PROTOCOL_H

View File

@@ -1,8 +1,9 @@
#include "cdutils_types.h"
#include "piconfig.h"
#include "pifile.h"
#include "pievaluator.h"
#include "cdutils_core.h"
#include "piconfig.h"
#include "pievaluator.h"
#include "pifile.h"
using namespace CDUtils;
@@ -10,46 +11,45 @@ using namespace CDUtils;
const int cd_x_history_max_size = 4000;
CDType::CDType() {
index_ = -1;
index_ = -1;
value_d = 0.;
value_i = 0;
value_b = calculated = x_enabled = false;
cd_type_ = cdNull;
parent = 0;
avg_size = 1;
cd_type_ = cdNull;
parent = 0;
avg_size = 1;
mode_ = rmode_ = X_Current;
}
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.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;
index_ = i;
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;
calculated = x_enabled = false;
parent = 0;
avg_size = 1;
parent = 0;
avg_size = 1;
mode_ = rmode_ = X_Current;
if (type_ == "e") {
enum_values = parseEnumComment(comment_);
// piCout << enum_values.size() << enum_values;
// piCout << enum_values.size() << enum_values;
}
// piCout << type_.size() << type_.toUTF8();
// piCout << formula_.size() << formula_.toUTF8();
// piCout << comment_.size() << comment_.toUTF8();
// piCout << "[CDType] create" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
// piCout << type_.size() << type_.toUTF8();
// piCout << formula_.size() << formula_.toUTF8();
// piCout << comment_.size() << comment_.toUTF8();
// piCout << "[CDType] create" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ <<
//":" << (cd_type_ == cdK);
}
CDType & CDType::operator =(double x) {
CDType & CDType::operator=(double x) {
value_d = x;
value_i = x;
value_b = x > 0.;
@@ -96,7 +96,7 @@ PIVariant CDType::variantValue() const {
e.selectValue(toInt());
return PIVariant(e);
break;
}
}
default: break;
}
return PIVariant(value());
@@ -105,9 +105,9 @@ PIVariant CDType::variantValue() const {
void CDType::setValue(const PIString & value_) {
formula_ = value_;
value_d = formula_.toDouble();
value_i = formula_.toInt();
value_b = formula_.toBool();
value_d = formula_.toDouble();
value_i = formula_.toInt();
value_b = formula_.toBool();
}
@@ -117,10 +117,10 @@ void CDType::setVariantValue(const PIVariant & value_) {
void CDType::setFormula(const PIString & f) {
formula_ = f;
formula_ = f;
calculated = false;
//PIEvaluator e;
//calculate(&e);
// PIEvaluator e;
// calculate(&e);
}
@@ -130,30 +130,32 @@ PIStringList CDType::pathString() const {
if (!ps) return ret;
for (int i = 0; i < path_.size_s() - 1; ++i) {
ps = &(ps->section(path_[i]));
if (!ps->alias.isEmpty()) ret << ps->alias;
else ret << PIString::fromNumber(path_[i]);
if (!ps->alias.isEmpty())
ret << ps->alias;
else
ret << PIString::fromNumber(path_[i]);
}
if (!name_.isEmpty()) ret << name_;
else ret << PIString::fromNumber(index_);
if (!name_.isEmpty())
ret << name_;
else
ret << PIString::fromNumber(index_);
return ret;
}
void CDType::readX(PIByteArray & ba) {
if (ba.size() < 5) return;
uchar t(0); ba >> t;
uchar t(0);
ba >> t;
rmode_ = (XMode)t;
switch (rmode_) {
case X_Current:
ba >> value_d;
break;
case X_Current: ba >> value_d; break;
case X_All_Avg: {
PIVector<double> ah;
ba >> ah;
history << ah;
if (!history.isEmpty())
value_d = history.back();
} break;
if (!history.isEmpty()) value_d = history.back();
} break;
default: break;
}
value_i = value_d;
@@ -164,9 +166,7 @@ void CDType::readX(PIByteArray & ba) {
void CDType::writeX(PIByteArray & ba) {
ba << uchar(mode_);
switch (mode_) {
case X_Current:
ba << value_d;
break;
case X_Current: ba << value_d; break;
case X_All_Avg:
ba << history;
history.clear();
@@ -176,14 +176,14 @@ void CDType::writeX(PIByteArray & ba) {
}
bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
bool CDType::calculate(PIEvaluator * e, PIVector<const CDType *> stack) {
if (stack.contains(this)) {
error_ = "Circular dependencies: ";
for (const CDType * k : stack) {
for (const CDType * k: stack) {
error_ += k->name() + " -> ";
}
error_ += name();
//piCout << error_;
// piCout << error_;
return false;
}
stack << this;
@@ -191,7 +191,7 @@ bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
calculated = true;
error_.clear();
if (!parent) return true;
//piCout << "calc" << name_ << (parent ? parent->alias : "root");
// piCout << "calc" << name_ << (parent ? parent->alias : "root");
value_s = formula_.trimmed();
for (;;) {
int ki = value_s.find("K[");
@@ -199,14 +199,14 @@ bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
int ke = value_s.find("]", ki + 2);
if (ke < 0) break;
PIString kp = value_s.mid(ki + 2, ke - ki - 2);
//piCout << kp;
// piCout << kp;
CDType & k((*parent)[kp]);
k.calculate(e, stack);
value_s.replace(ki, ke - ki + 1, PIString::fromNumber(k.value_d));
}
value_d = formula_.toDouble();
value_i = formula_.toInt();
value_b = formula_.toBool();
value_d = formula_.toDouble();
value_i = formula_.toInt();
value_b = formula_.toBool();
double ev = 0.;
if (!e->check(value_s) && value_d == 0. && value_i == 0 && !value_b) {
PIString f = formula_.trimmed().toLowerCase();
@@ -214,12 +214,11 @@ bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
error_ = e->error();
return false;
}
} else
if (e->isCorrect())
ev = e->evaluate().real();
//piCout << value_s << value_i << value_d << ev;
//if ((value_d == 0.) || (piAbsd(value_d) < piAbsd(ev))) value_d = ev;
//if ((value_i == 0) || (piAbsd(value_i) < piAbsd(ev))) value_i = int(ev);
} else if (e->isCorrect())
ev = e->evaluate().real();
// piCout << value_s << value_i << value_d << ev;
// if ((value_d == 0.) || (piAbsd(value_d) < piAbsd(ev))) value_d = ev;
// if ((value_i == 0) || (piAbsd(value_i) < piAbsd(ev))) value_i = int(ev);
if ((value_d == 0.) || (ev != 0.)) value_d = ev;
if ((value_i == 0) || (ev != 0.)) value_i = int(ev);
value_b = value_b || (ev > 0.);
@@ -245,8 +244,8 @@ PIVariantTypes::Enum CDType::parseEnumComment(PIString c) {
if (c.isEmpty()) return ret;
if (type_ == "e") {
PIStringList sl = c.inBrackets('{', '}').split(",");
int cval = 0;
for (PIString & s : sl) {
int cval = 0;
for (PIString & s: sl) {
s.trim();
if (s.isEmpty()) continue;
if (s[0].isDigit()) {
@@ -260,13 +259,13 @@ PIVariantTypes::Enum CDType::parseEnumComment(PIString c) {
++cval;
}
}
//piCout << c << "=" << ret;
// piCout << c << "=" << ret;
return ret;
}
CDSection::CDSection(CDType::cdT type_) {
cd_type_ = type_;
cd_type_ = type_;
null.cd_type_ = type_;
}
@@ -331,8 +330,8 @@ void CDSection::calculate() {
CDType & CDSection::getByName(const PIString & name_) {
PIStringList np = name_.split(".");
if (np.isEmpty()) return null;
//piCout << np;
CDSection * cs = this, * ns = 0;
// piCout << np;
CDSection *cs = this, *ns = 0;
if (np.front().isEmpty()) {
if (np.size_s() < 2) return null;
cs = CDCore::instance()->root(cd_type_);
@@ -341,37 +340,40 @@ CDType & CDSection::getByName(const PIString & name_) {
for (int i = 0; i < np.size_s() - 1; ++i) {
if (np[i].isEmpty()) return null;
bool isd = np[i][0].isDigit() || (np[i][0] == '-');
int dv = 0;
int dv = 0;
if (isd) dv = np[i].toInt();
ns = 0;
ns = 0;
auto it = cs->s.makeIterator();
while (it.next()) {
bool f = false;
if (isd) f = (dv == it.key());
else f = (np[i] == it.value().alias);
//piCout << "s..." << it.key() << it.value().alias << f;
if (isd)
f = (dv == it.key());
else
f = (np[i] == it.value().alias);
// piCout << "s..." << it.key() << it.value().alias << f;
if (f) {
ns = &(it.value());
break;
}
}
//piCout << ns;
// piCout << ns;
if (!ns) return null;
cs = ns;
}
if (np.back().isEmpty()) return null;
bool isd = np.back()[0].isDigit() || (np.back()[0] == '-');
int dv = 0;
int dv = 0;
if (isd) dv = np.back().toInt();
//piCout << np.back() << isd << dv;
// piCout << np.back() << isd << dv;
auto it = cs->cd.makeIterator();
while (it.next()) {
bool f = false;
if (isd) f = (dv == it.key());
else f = (np.back() == it.value().name());
//piCout << "k..." << it.key() << it.value().name() << f;
if (f)
return cs->cd[it.key()];
if (isd)
f = (dv == it.key());
else
f = (np.back() == it.value().name());
// piCout << "k..." << it.key() << it.value().name() << f;
if (f) return cs->cd[it.key()];
}
return null;
}
@@ -390,12 +392,18 @@ CDType & CDSection::getByPath(const PIDeque<int> & path_) {
void CDSection::write(PIIODevice * d, const PIString & prefix) {
if (!d) return;
if (cd.isEmpty() && s.isEmpty()) return;
// piCout << "[CDSection] write start";
// piCout << "[CDSection] write start";
PIString l;
PIStringList cdtl;
cdtl << "null" << "k" << "x" << "c" << "m";
if (prefix.isEmpty()) l = "[" + cdtl[cd_type_] + "]";
else l = "[" + prefix + "." + cdtl[cd_type_] + "]";
cdtl << "null"
<< "k"
<< "x"
<< "c"
<< "m";
if (prefix.isEmpty())
l = "[" + cdtl[cd_type_] + "]";
else
l = "[" + prefix + "." + cdtl[cd_type_] + "]";
l += "\n";
d->write(l.toUTF8());
l = "name = " + name + " \n";
@@ -415,7 +423,7 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
d->write(l.toUTF8());
if (!ck.enumValues().enum_list.isEmpty()) {
l = PIString::fromNumber(ck.index()) + ".ev = {";
for (const PIVariantTypes::Enumerator & e : ck.enumValues().enum_list) {
for (const PIVariantTypes::Enumerator & e: ck.enumValues().enum_list) {
l += PIString::fromNumber(e.value) + " - " + e.name + ", ";
}
l.cutRight(2);
@@ -426,7 +434,8 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
case CDType::cdX:
l = PIString::fromNumber(ck.index()) + ".name = " + ck.name() + " #s " + ck.comment() + " \n";
d->write(l.toUTF8());
l = PIString::fromNumber(ck.index()) + ".mode = " + PIString::fromNumber((int)ck.xmode()) + " #e (0 - cur, 1 - all_avg) " + "\n";
l = PIString::fromNumber(ck.index()) + ".mode = " + PIString::fromNumber((int)ck.xmode()) + " #e (0 - cur, 1 - all_avg) " +
"\n";
d->write(l.toUTF8());
l = PIString::fromNumber(ck.index()) + ".avg = " + PIString::fromNumber(ck.avg()) + " #n " + "\n";
d->write(l.toUTF8());
@@ -441,8 +450,10 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
}
}
if (!s.isEmpty()) {
if (prefix.isEmpty()) l = "s";
else l = prefix + ".s";
if (prefix.isEmpty())
l = "s";
else
l = prefix + ".s";
auto j = s.makeIterator();
while (j.next()) {
j.value().write(d, l + "." + PIString::fromNumber(j.key()));
@@ -452,45 +463,54 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
l = "[]\n";
d->write(l.toUTF8());
}
// piCout << "[CDSection] write end";
// piCout << "[CDSection] write end";
}
void CDSection::read(const void * ep) {
// piCout << "[CDSection] read start";
// piCout << "[CDSection] read start";
PIStringList cdtl;
cdtl << "null" << "k" << "x" << "c" << "m";
cdtl << "null"
<< "k"
<< "x"
<< "c"
<< "m";
cd.clear();
s.clear();
PIConfig::Entry & e(*(PIConfig::Entry*)ep);
name = e.getValue(cdtl[cd_type_] + ".name").value();
alias = e.getValue(cdtl[cd_type_] + ".alias").value();
PIConfig::Entry & e(*(PIConfig::Entry *)ep);
name = e.getValue(cdtl[cd_type_] + ".name").value();
alias = e.getValue(cdtl[cd_type_] + ".alias").value();
PIConfig::Entry & cdl = e.getValue(cdtl[cd_type_]);
for (int i = 0; i < cdl.childCount(); ++i) {
const PIConfig::Entry * e(cdl.child(i));
bool ok = false;
int id = e->name().toInt(-1, &ok);
// piCout << "[read]" << ke->name() << ke->value() << ok;
int id = e->name().toInt(-1, &ok);
// piCout << "[read]" << ke->name() << ke->value() << ok;
if (ok) {
CDType c;
PIString ev;
switch (cd_type_) {
case CDType::cdNull: break;
case CDType::cdK:
c = CDType(id, e->getValue("v").comment(), e->getValue("v").type(), e->getValue("v").value(), e->getValue("f").value(), e->getValue("f").comment(), cd_type_);
c = CDType(id,
e->getValue("v").comment(),
e->getValue("v").type(),
e->getValue("v").value(),
e->getValue("f").value(),
e->getValue("f").comment(),
cd_type_);
ev = e->getValue("ev", "").value();
if (!ev.isEmpty())
c.enum_values = c.parseEnumComment(ev);
if (!ev.isEmpty()) c.enum_values = c.parseEnumComment(ev);
break;
case CDType::cdX:
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_);
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString(), e->getValue("name").comment(), cd_type_);
c.setXMode((CDType::XMode)e->getValue("mode", int(CDType::X_Current)).value().toInt());
c.setAvg((CDType::XMode)e->getValue("avg", 1).value().toInt());
c.x_enabled = e->getValue("sel", false).value().toBool();
break;
case CDType::cdC:
case CDType::cdM:
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_);
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString(), e->getValue("name").comment(), cd_type_);
break;
}
cd[id] = c;
@@ -504,7 +524,7 @@ void CDSection::read(const void * ep) {
rs.cd_type_ = cd_type_;
rs.read(se);
}
// piCout << "[CDSection] read end";
// piCout << "[CDSection] read end";
}
@@ -513,8 +533,8 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
piCout << "[CDSection] update error: SaveByIndex | SaveByName mode is denied!";
return;
}
//piCout << "[CDSection] update start";
//piCout << "before" << k.size() << v.k.size();
// piCout << "[CDSection] update start";
// piCout << "before" << k.size() << v.k.size();
PIMap<int, PIString> prev_cd_f_bi;
PIMap<PIString, PIString> prev_cd_f_bn;
@@ -530,9 +550,9 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
}
if (!mode[Merge]) cd.clear();
for (auto i = v.cd.begin(); i != v.cd.end(); ++i) {
int id = i.key();
int id = i.key();
PIString n = i.value().name();
cd[id] = i.value();
cd[id] = i.value();
if (mode[SaveByIndex]) {
if (prev_cd_f_bi.contains(id)) {
cd[id].setFormula(prev_cd_f_bi[id]);
@@ -559,9 +579,9 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
}
if (!mode[Merge]) s.clear();
for (auto j = v.s.begin(); j != v.s.end(); ++j) {
int id = j.key();
int id = j.key();
PIString n = j.value().alias;
s[id] = j.value();
s[id] = j.value();
if (mode[SaveByIndex]) {
if (prev_s_bi.contains(id)) s[id] = prev_s_bi[id];
}
@@ -580,7 +600,7 @@ bool CDSection::isSameStructure(CDSection & v) {
}
for (auto i = v.cd.begin(); i != v.cd.end(); ++i) {
if (!cd_ids.contains(i.value().name())) continue;
//piCout << i.key() << k[i.key()].name() << i.value().name();
// piCout << i.key() << k[i.key()].name() << i.value().name();
if (cd[cd_ids[i.value().name()]].index() != i.key()) return false;
}
for (auto j = v.s.begin(); j != v.s.end(); ++j) {
@@ -593,7 +613,7 @@ bool CDSection::isSameStructure(CDSection & v) {
void CDSection::prepareCalculate() {
for (auto i = cd.begin(); i != cd.end(); ++i) {
i.value().parent = this;
i.value().parent = this;
i.value().calculated = false;
}
for (auto j = s.begin(); j != s.end(); ++j) {
@@ -622,8 +642,8 @@ void CDSection::setSelectedX(bool yes) {
}
PIVector<PIDeque<int> > CDSection::collectX() const {
PIVector<PIDeque<int> > ret;
PIVector<PIDeque<int>> CDSection::collectX() const {
PIVector<PIDeque<int>> ret;
for (auto i = cd.begin(); i != cd.end(); ++i) {
if (i.value().x_enabled) {
ret << i.value().path();
@@ -642,7 +662,7 @@ void CDSection::makePath(PIDeque<int> p) {
tp = p;
tp << i.key();
i.value().path_ = tp;
//piCout << "path for" << i.value().name() << tp;
// piCout << "path for" << i.value().name() << tp;
}
for (auto j = s.begin(); j != s.end(); ++j) {
tp = p;
@@ -652,10 +672,10 @@ void CDSection::makePath(PIDeque<int> p) {
}
PIVector<CDType * > CDSection::children(bool recursive) const {
PIVector<CDType * > ret;
PIVector<CDType *> CDSection::children(bool recursive) const {
PIVector<CDType *> ret;
for (auto i = cd.begin(); i != cd.end(); ++i) {
ret << const_cast<CDType * >(&(i.value()));
ret << const_cast<CDType *>(&(i.value()));
}
if (!recursive) return ret;
for (auto j = s.begin(); j != s.end(); ++j) {
@@ -672,5 +692,3 @@ PIVariantTypes::Enum CDSection::enumValues() const {
}
return ret;
}

View File

@@ -1,29 +1,29 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_TYPES_H
#define CDUTILS_TYPES_H
#include "pistring.h"
#include "pimap.h"
#include "pivariant.h"
#include "cd_core_export.h"
#include "pimap.h"
#include "pistring.h"
#include "pivariant.h"
class PIIODevice;
class PIEvaluator;
@@ -53,49 +53,59 @@ class CD_CORE_EXPORT CDType {
friend class CDCore;
friend class Interface;
friend class XInterface;
public:
enum cdT {cdNull, cdK, cdX, cdC, cdM};
enum XMode {X_Current, X_All_Avg};
enum cdT {
cdNull,
cdK,
cdX,
cdC,
cdM
};
enum XMode {
X_Current,
X_All_Avg
};
CDType();
CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t);
CDType & operator =(double x);
int index() const {return index_;}
PIString name() const {return name_;}
CDType & operator=(double x);
int index() const { return index_; }
PIString name() const { return name_; }
PIString type() const;
PIString value() const;
PIVariant variantValue() const;
PIString formula() const {return formula_;}
PIString comment() const {return comment_;}
double toDouble() const {return value_d;}
int toInt() const {return value_i;}
bool toBool() const {return value_b;}
cdT cd_type() const {return cd_type_;}
PIString formula() const { return formula_; }
PIString comment() const { return comment_; }
double toDouble() const { return value_d; }
int toInt() const { return value_i; }
bool toBool() const { return value_b; }
cdT cd_type() const { return cd_type_; }
void setValue(const PIString & value_);
void setVariantValue(const PIVariant & value_);
void setFormula(const PIString & formula);
void setComment(const PIString & comment) {comment_ = comment;}
operator double() const {return value_d;}
const PIVariantTypes::Enum & enumValues() const {return enum_values;}
void setEnumValues(const PIVariantTypes::Enum & ev) {enum_values = ev;}
const PIString & errorString() const {return error_;}
PIDeque<int> path() const {return path_;}
void setComment(const PIString & comment) { comment_ = comment; }
operator double() const { return value_d; }
const PIVariantTypes::Enum & enumValues() const { return enum_values; }
void setEnumValues(const PIVariantTypes::Enum & ev) { enum_values = ev; }
const PIString & errorString() const { return error_; }
PIDeque<int> path() const { return path_; }
PIStringList pathString() const;
void setXMode(XMode mode) {mode_ = mode;}
void setAvg(int avg) {avg_size = avg;}
XMode xmode() const {return mode_;}
XMode xmode_rec() const {return rmode_;}
int avg() const {return avg_size;}
bool isSelectedX() const {return x_enabled;}
void setXMode(XMode mode) { mode_ = mode; }
void setAvg(int avg) { avg_size = avg; }
XMode xmode() const { return mode_; }
XMode xmode_rec() const { return rmode_; }
int avg() const { return avg_size; }
bool isSelectedX() const { return x_enabled; }
void readX(PIByteArray & ba);
void writeX(PIByteArray & ba);
PIVector<double> history;
protected:
bool calculate(PIEvaluator * e, PIVector<const CDType * > stack = PIVector<const CDType * >());
bool calculate(PIEvaluator * e, PIVector<const CDType *> stack = PIVector<const CDType *>());
PIVariantTypes::Enum parseEnumComment(PIString c);
cdT cd_type_;
int index_;
@@ -120,27 +130,27 @@ class CD_CORE_EXPORT CDSection {
friend class ::CD_Pult;
friend class ::CDItem;
friend class ::CDItemModel;
public:
public:
CDSection(CDType::cdT type_ = CDType::cdNull);
bool test(int v) {return cd.value(v).toBool();}
// CDType & operator [](int v) {if (!k.contains(v)) k[v].index_ = v; return k[v];}
CDType & operator [](int v) {return cd[v];}
CDType & operator [](const PIString & name_) {return getByName(name_);}
CDType & operator [](const PIDeque<int> & path_) {return getByPath(path_);}
bool test(int v) { return cd.value(v).toBool(); }
// CDType & operator [](int v) {if (!k.contains(v)) k[v].index_ = v; return k[v];}
CDType & operator[](int v) { return cd[v]; }
CDType & operator[](const PIString & name_) { return getByName(name_); }
CDType & operator[](const PIDeque<int> & path_) { return getByPath(path_); }
CDSection & section(int v);
const CDSection section(int v) const;
bool isEmpty() const {return cd.isEmpty() && s.isEmpty();}
bool isEmpty() const { return cd.isEmpty() && s.isEmpty(); }
bool exists(PIDeque<int> path) const;
int count(bool recursive = true) const;
int sectionsCount() const;
PIVector<int> indexes() const {return cd.keys();}
PIVector<int> indexes() const { return cd.keys(); }
PIStringList index_names() const;
void calculate();
void makePath(PIDeque<int> p = PIDeque<int>());
PIVector<CDType * > children(bool recursive = true) const;
PIVector<CDType *> children(bool recursive = true) const;
PIVariantTypes::Enum enumValues() const;
PIString name;
@@ -149,7 +159,7 @@ public:
protected:
CDSection(PIMap<int, CDType> k_, PIMap<int, CDSection> s_) {
cd = k_;
s = s_;
s = s_;
}
CDType & getByName(const PIString & name_);
CDType & getByPath(const PIDeque<int> & path_);
@@ -160,7 +170,7 @@ protected:
void prepareCalculate();
void calculateRecursive(PIEvaluator * e);
void setSelectedX(bool yes);
PIVector<PIDeque<int> > collectX() const;
PIVector<PIDeque<int>> collectX() const;
PIMap<int, CDType> cd;
mutable PIMap<int, CDSection> s;
@@ -168,18 +178,18 @@ protected:
CDType::cdT cd_type_;
};
}
} // namespace CDUtils
inline PICout operator <<(PICout s, const CDUtils::CDType & v) {
inline PICout operator<<(PICout s, const CDUtils::CDType & v) {
s.space();
s.saveAndSetControls(0);
switch (v.cd_type()) {
case CDUtils::CDType::cdK : s << "K["; break;
case CDUtils::CDType::cdX : s << "X["; break;
case CDUtils::CDType::cdC : s << "C["; break;
case CDUtils::CDType::cdM : s << "M["; break;
default : s << "Null["; break;
case CDUtils::CDType::cdK: s << "K["; break;
case CDUtils::CDType::cdX: s << "X["; break;
case CDUtils::CDType::cdC: s << "C["; break;
case CDUtils::CDType::cdM: s << "M["; break;
default: s << "Null["; break;
}
s << v.name() << "(" << v.index() << ")] = " << v.value();
s.restoreControls();

View File

@@ -1,4 +1,5 @@
#include "cdutils_x.h"
#include "cdutils_core.h"
using namespace CDUtils;
@@ -18,19 +19,19 @@ void XInterface::setEnabled(const CDType & x, bool en) {
core->x_mutex.unlock();
return;
}
t.x_enabled = en;
//piCout << t << "x_enabled" << en;
t.x_enabled = en;
// piCout << t << "x_enabled" << en;
core->need_rebuild_x = true;
core->x_mutex.unlock();
}
PIVector<PIDeque<int> > XInterface::enabledList() const {
PIVector<PIDeque<int>> XInterface::enabledList() const {
return CDCore::instance()->x_selected;
}
void XInterface::setEnabledList(const PIVector<PIDeque<int> > & l) {
void XInterface::setEnabledList(const PIVector<PIDeque<int>> & l) {
CDCore::instance()->x_selected = l;
}

View File

@@ -1,56 +1,55 @@
/*
CD Utils - Control-Debug utilites
CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CDUTILS_X_H
#define CDUTILS_X_H
#include "cdutils_interface.h"
#include "cd_core_export.h"
#include "cdutils_interface.h"
namespace CDUtils {
class CD_CORE_EXPORT XInterface: public Interface
{
class CD_CORE_EXPORT XInterface: public Interface {
PIOBJECT_SUBCLASS(XInterface, Interface);
public:
XInterface();
EVENT1(keepNamesRequest, bool*, xn);
EVENT1(receivedX, PIVector<PIDeque<int> >, pathes);
EVENT1(keepNamesRequest, bool *, xn);
EVENT1(receivedX, PIVector<PIDeque<int>>, pathes);
void enable(const CDType & x) {setEnabled(x, true);}
void disable(const CDType & x) {setEnabled(x, false);}
void enable(const CDType & x) { setEnabled(x, true); }
void disable(const CDType & x) { setEnabled(x, false); }
void setEnabled(const CDType & x, bool en);
void setDisabled(const CDType & x, bool dis) {setEnabled(x, !dis);}
PIVector<PIDeque<int> > enabledList() const;
void setEnabledList(const PIVector<PIDeque<int> > & l);
void setDisabled(const CDType & x, bool dis) { setEnabled(x, !dis); }
PIVector<PIDeque<int>> enabledList() const;
void setEnabledList(const PIVector<PIDeque<int>> & l);
void lock();
void unlock();
void start(double freq = 20.);
void stop();
};
}
} // namespace CDUtils
extern CD_CORE_EXPORT CDUtils::XInterface X;

View File

@@ -1,17 +1,17 @@
#include "cdutils_k.h"
#include "cdutils_x.h"
#include "cdutils_c.h"
#include "cdutils_m.h"
#include "cdutils_core.h"
#include "cdtest.h"
#include "pip.h"
#include "cdutils_c.h"
#include "cdutils_core.h"
#include "cdutils_k.h"
#include "cdutils_m.h"
#include "cdutils_x.h"
#include "k_description.h"
#include "pip.h"
using namespace CDUtils;
class Core : public PIObject
{
class Core: public PIObject {
PIOBJECT(Core);
public:
Core() {
CDCore::instance()->initApp();
@@ -33,25 +33,25 @@ public:
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();
// 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() {
X.lock();
X[KD::Frequency] = 100;
X[KD::Frequency] = 100;
X.section(KD::Spectrometer)[KD::Temperature_default] = sin(t);
t += 0.01;
X.unlock();
@@ -60,7 +60,7 @@ public:
piCout << K[Second];*/
}
EVENT_HANDLER(void, ksend) {piCout << "sended k";}
EVENT_HANDLER(void, ksend) { piCout << "sended k"; }
EVENT_HANDLER(void, crecv) {
piCout << "received c";
C.connect(C.section(KD::Logs).section(KD::Spec).section(KD::Formats)[KD::Binary], this, HANDLER(cmd));
@@ -71,14 +71,14 @@ public:
if (!timer.isRunning()) timer.start(10);
X.start();
}
EVENT_HANDLER(void, timerDone) {test();}
EVENT_HANDLER(void, cmd) {piCout << "command cmd";}
EVENT_HANDLER(void, timerDone) { test(); }
EVENT_HANDLER(void, cmd) { piCout << "command cmd"; }
EVENT_HANDLER(void, c_Pause) {
piCout << "command pause";
M[KD::Main] << "rec command" << C[KD::Pause];
M.messageBox(M.root()[KD::Core], "init successfull");
}
EVENT_HANDLER(void, c_Spectrometer_Connection) {piCout << "command spec_conn";}
EVENT_HANDLER(void, c_Spectrometer_Connection) { piCout << "command spec_conn"; }
private:
PIFile rf;
@@ -87,11 +87,10 @@ private:
};
int main(int argc, char *argv[]) {
int main(int argc, char * argv[]) {
X.start();
piSleep(1);
//CDCore::instance()->destroy();
// CDCore::instance()->destroy();
piCout << "DELETED";
return 0;
}