From 557f2a4d0d0170dd4ef98a4660e79175758e73fc Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Thu, 30 Jul 2020 20:08:33 +0300 Subject: [PATCH] replace piForeach* to for(:) another c++11 try ... --- CMakeLists.txt | 4 +- lib/console/piscreen.cpp | 4 +- lib/console/piterminal.cpp | 2 +- lib/main/containers/picontainers.h | 149 ++++------------------------ lib/main/containers/pideque.h | 7 +- lib/main/containers/pimap.h | 4 + lib/main/containers/pivector.h | 6 +- lib/main/core/piinit.cpp | 2 +- lib/main/core/piobject.cpp | 46 +++++---- lib/main/io_devices/pibinarylog.cpp | 2 +- lib/main/io_devices/pipeer.cpp | 4 +- lib/main/io_devices/piserial.cpp | 2 +- lib/main/io_utils/piconnection.cpp | 122 ++++++++++++----------- lib/main/thread/piblockingdequeue.h | 2 +- main.cpp | 17 ++-- utils/code_model_generator/main.cpp | 4 +- utils/deploy_tool/main.cpp | 2 +- utils/system_daemon/main.cpp | 7 +- 18 files changed, 151 insertions(+), 235 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e7e49d1..2fcbe46b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(pip) set(_PIP_MAJOR 1) set(_PIP_MINOR 99) -set(_PIP_REVISION 0) -set(_PIP_SUFFIX _prealpha) +set(_PIP_REVISION 1) +set(_PIP_SUFFIX _prebeta) set(_PIP_COMPANY SHS) set(_PIP_DOMAIN org.SHS) diff --git a/lib/console/piscreen.cpp b/lib/console/piscreen.cpp index 60945d17..786c1b02 100644 --- a/lib/console/piscreen.cpp +++ b/lib/console/piscreen.cpp @@ -480,7 +480,7 @@ void PIScreen::mouse_event(PIKbdListener::MouseEvent me) { PIVector tl = prepareMouse(&me); if (tl.isEmpty()) return; piForeachR (PIScreenTile * t, tl) - if (t->mouseEvent(me)) piBreak; + if (t->mouseEvent(me)) break; } @@ -488,7 +488,7 @@ void PIScreen::wheel_event(PIKbdListener::WheelEvent we) { PIVector tl = prepareMouse(&we); if (tl.isEmpty()) return; piForeachR (PIScreenTile * t, tl) - if (t->wheelEvent(we)) piBreak; + if (t->wheelEvent(we)) break; } diff --git a/lib/console/piterminal.cpp b/lib/console/piterminal.cpp index 2c0da013..ce9623aa 100644 --- a/lib/console/piterminal.cpp +++ b/lib/console/piterminal.cpp @@ -805,7 +805,7 @@ bool PITerminal::initialize() { if (e.startsWith("TERM=")) { PRIVATE->term_type = termType(e.mid(5).trim().toLowerCase()); //piCout << PRIVATE->term_type; - piBreak; + break; } pid_t fr = forkpty(&(PRIVATE->fd), pty, 0, &ws); //piCoutObj << fr << PRIVATE->fd << pty; diff --git a/lib/main/containers/picontainers.h b/lib/main/containers/picontainers.h index 688388de..0487c892 100644 --- a/lib/main/containers/picontainers.h +++ b/lib/main/containers/picontainers.h @@ -97,141 +97,32 @@ */ # define piForeachCR(i,c) -/*!\brief Macro for break from any piForeach* loop - * \details \warning C++ ordinary "break" doesn`t work inside piForeach* - * loops! Always use "piBreak" instead! - */ -# define piBreak - #else -# define piBreak {_for._end = true; break;} + +template +struct _reverse_wrapper { + C & c_; + _reverse_wrapper(C & c): c_(c) {} + _reverse_wrapper(const C & c): c_(const_cast(c)) {} + typename C::reverse_iterator begin() {return c_.rbegin();} + typename C::reverse_iterator end() {return c_.rend(); } + typename C::const_reverse_iterator begin() const {return c_.rbegin();} + typename C::const_reverse_iterator end() const {return c_.rend(); } +}; + +template _reverse_wrapper _reverse_wrap(C & c) {return _reverse_wrapper(c);} +template _reverse_wrapper _reverse_wrap(const C & c) {return _reverse_wrapper(c);} + # define piForTimes(c) for(int _i##c = 0; _i##c < c; ++_i##c) -#ifdef CC_GCC +# define piForeach(i,c) for(i : c) +# define piForeachC(i,c) for(const i : c) +# define piForeachR(i,c) for(i : _reverse_wrap(c)) +# define piForeachRC(i,c) for(const i : _reverse_wrap(c)) -template -class _PIForeach { -public: - _PIForeach(Type & t): _t(t), _break(false), _end(false) {_it = _t.begin();} - typename Type::value_type _var; - typename Type::iterator _it; - Type & _t; - bool _break, _end; - inline bool isEnd() {return _it == _t.end();} - inline void operator ++() {if (_end) _it = _t.end(); else _it++; _break = false;} -}; - -template -class _PIForeachR { -public: - _PIForeachR(Type & t): _t(t), _break(false), _end(false) {_rit = _t.rbegin();} - typename Type::value_type _var; - typename Type::reverse_iterator _rit; - Type & _t; - bool _break, _end; - inline bool isEnd() {return _rit == _t.rend();} - inline void operator ++() {if (_end) _rit = _t.rend(); else _rit++; _break = false;} -}; - -template -class _PIForeachC { -public: - _PIForeachC(const Type & t): _t(t), _break(false), _end(false) {_it = _t.begin();} - typename Type::value_type _var; - typename Type::const_iterator _it; - const Type & _t; - bool _break, _end; - inline bool isEnd() {return _it == _t.end();} - inline void operator ++() {if (_end) _it = _t.end(); else _it++; _break = false;} -}; - -template -class _PIForeachCR { -public: - _PIForeachCR(const Type & t): _t(t), _break(false), _end(false) {_rit = _t.rbegin();} - typename Type::value_type _var; - typename Type::const_reverse_iterator _rit; - const Type & _t; - bool _break, _end; - inline bool isEnd() {return _rit == _t.rend();} - inline void operator ++() {if (_end) _rit = _t.rend(); else _rit++; _break = false;} -}; - -#define piForeach(i,c) for(_PIForeach _for(c); !_for.isEnd(); ++_for) \ - for(i(*_for._it); !_for._break; _for._break = true) -#define piForeachR(i,c) for(_PIForeachR _for(c); !_for.isEnd(); ++_for) \ - for(i(*_for._rit); !_for._break; _for._break = true) -#define piForeachA(i,c) for(_PIForeach _for(c); !_for.isEnd(); ++_for) \ - for(typeof(_for._var) & i(*_for._it); !_for._break; _for._break = true) -#define piForeachAR(i,c) for(_PIForeachR _for(c); !_for.isEnd(); ++_for) \ - for(typeof(_for._var) & i(*_for._rit); !_for._break; _for._break = true) -#define piForeachC(i,c) for(_PIForeachC _for(c); !_for.isEnd(); ++_for) \ - for(const i(*_for._it); !_for._break; _for._break = true) -#define piForeachCR(i,c) for(_PIForeachCR _for(c); !_for.isEnd(); ++_for) \ - for(const i(*_for._rit); !_for._break; _for._break = true) -#define piForeachCA(i,c) for(_PIForeachC _for(c); !_for.isEnd(); ++_for) \ - for(const typeof(_for._var) & i(*_for._it); !_for._break; _for._break = true) -#define piForeachCAR(i,c) for(_PIForeachCR _for(c); !_for.isEnd(); ++_for) \ - for(const typeof(_for._var) & i(*_for._rit); !_for._break; _for._break = true) - -#define piForeachRA piForeachAR -#define piForeachAC piForeachCA -#define piForeachCRA piForeachCAR -#define piForeachARC piForeachCAR -#define piForeachACR piForeachCAR -#define piForeachRCA piForeachCAR -#define piForeachRAC piForeachCAR - -#else - -class _PIForeachBase {public: mutable bool _break, _end; }; - -template -class _PIForeach: public _PIForeachBase { -public: - _PIForeach(Type & t, bool i = false): _t(t), _inv(i) {_break = _end = false; if (_inv) _rit = _t.rbegin(); else _it = _t.begin();} - mutable typename Type::value_type _var; - mutable typename Type::iterator _it; - mutable typename Type::reverse_iterator _rit; - Type & _t; - bool _inv; - bool isEnd() {if (_inv) return _rit == _t.rend(); else return _it == _t.end();} - void operator ++() {if (_inv) {if (_end) _rit = _t.rend(); else _rit++;} else {if (_end) _it = _t.end(); else _it++;} _break = false;} -}; - -template -class _PIForeachC: public _PIForeachBase { -public: - _PIForeachC(const Type & t, bool i = false): _t(t), _inv(i) {_break = _end = false; if (_inv) _rit = _t.rbegin(); else _it = _t.begin();} - mutable typename Type::value_type _var; - mutable typename Type::const_iterator _it; - mutable typename Type::const_reverse_iterator _rit; - const Type & _t; - bool _inv; - bool isEnd() {if (_inv) return _rit == _t.rend(); else return _it == _t.end();} - void operator ++() {if (_inv) {if (_end) _rit = _t.rend(); else _rit++;} else {if (_end) _it = _t.end(); else _it++;} _break = false;} -}; - -template inline _PIForeach _PIForeachNew(T & t, bool i = false) {return _PIForeach(t, i);} -template inline _PIForeach * _PIForeachCast(_PIForeachBase & c, T & ) {return static_cast<_PIForeach * >(&c);} - -template inline _PIForeachC _PIForeachNewC(const T & t, bool i = false) {return _PIForeachC(t, i);} -template inline _PIForeachC * _PIForeachCastC(_PIForeachBase & c, const T & ) {return static_cast<_PIForeachC * >(&c);} - -#define piForeach(i,c) for(_PIForeachBase & _for = _PIForeachNew(c); !_PIForeachCast(_for, c)->isEnd(); ++(*_PIForeachCast(_for, c))) \ - for(i = *(_PIForeachCast(_for, c)->_it); !_for._break; _for._break = true) -#define piForeachR(i,c) for(_PIForeachBase & _for = _PIForeachNew(c, true); !_PIForeachCast(_for, c)->isEnd(); ++(*_PIForeachCast(_for, c))) \ - for(i = *(_PIForeachCast(_for, c)->_rit); !_for._break; _for._break = true) -#define piForeachC(i,c) for(_PIForeachBase & _for = _PIForeachNewC(c); !_PIForeachCastC(_for, c)->isEnd(); ++(*_PIForeachCastC(_for, c))) \ - for(const i = *(_PIForeachCastC(_for, c)->_it); !_for._break; _for._break = true) -#define piForeachCR(i,c) for(_PIForeachBase & _for = _PIForeachNewC(c, false); !_PIForeachCastC(_for, c)->isEnd(); ++(*_PIForeachCastC(_for, c))) \ - for(const i = *(_PIForeachCastC(_for, c)->_rit); !_for._break; _for._break = true) - -#endif - -#define piForeachRC piForeachCR +# define piForeachCR piForeachRC #endif // DOXYGEN diff --git a/lib/main/containers/pideque.h b/lib/main/containers/pideque.h index c5e3c1b8..945a1227 100644 --- a/lib/main/containers/pideque.h +++ b/lib/main/containers/pideque.h @@ -70,7 +70,6 @@ public: } inline PIDeque & operator =(PIDeque && other) { - if (this == &other) return *this; swap(other); return *this; } @@ -324,6 +323,12 @@ public: piSwap(pid_rsize, other.pid_rsize); piSwap(pid_start, other.pid_start); } + inline void swap(PIDeque && other) { + piSwap(pid_data, other.pid_data); + piSwap(pid_size, other.pid_size); + piSwap(pid_rsize, other.pid_rsize); + piSwap(pid_start, other.pid_start); + } typedef int (*CompareFunc)(const T * , const T * ); static int compare_func(const T * t0, const T * t1) {return (*t0) < (*t1) ? -1 : ((*t0) == (*t1) ? 0 : 1);} diff --git a/lib/main/containers/pimap.h b/lib/main/containers/pimap.h index 6939eb53..da18e4a9 100644 --- a/lib/main/containers/pimap.h +++ b/lib/main/containers/pimap.h @@ -226,6 +226,10 @@ public: pim_content.swap(other.pim_content); pim_index.swap(other.pim_index); } + void swap(PIMap && other) { + pim_content.swap(other.pim_content); + pim_index.swap(other.pim_index); + } PIMap & insert(const Key & key, const T & value) { bool f(false); diff --git a/lib/main/containers/pivector.h b/lib/main/containers/pivector.h index 1ea45b15..df2987be 100644 --- a/lib/main/containers/pivector.h +++ b/lib/main/containers/pivector.h @@ -69,7 +69,6 @@ public: } inline PIVector & operator =(PIVector && other) { - if (this == &other) return *this; swap(other); return *this; } @@ -301,6 +300,11 @@ public: piSwap(piv_size, other.piv_size); piSwap(piv_rsize, other.piv_rsize); } + inline void swap(PIVector && other) { + piSwap(piv_data, other.piv_data); + piSwap(piv_size, other.piv_size); + piSwap(piv_rsize, other.piv_rsize); + } typedef int (*CompareFunc)(const T * , const T * ); static int compare_func(const T * t0, const T * t1) {return (*t0) < (*t1) ? -1 : ((*t0) == (*t1) ? 0 : 1);} diff --git a/lib/main/core/piinit.cpp b/lib/main/core/piinit.cpp index 6063a2c5..90eacfa1 100644 --- a/lib/main/core/piinit.cpp +++ b/lib/main/core/piinit.cpp @@ -125,7 +125,7 @@ PIInit::PIInit() { piForeachC (PIString & i, ifpathes) { if (fileExists(i)) { sinfo->ifconfigPath = i; - piBreak; + break; } } # else diff --git a/lib/main/core/piobject.cpp b/lib/main/core/piobject.cpp index 9d420f6f..42af0a01 100644 --- a/lib/main/core/piobject.cpp +++ b/lib/main/core/piobject.cpp @@ -190,39 +190,42 @@ PIStringList PIObject::scopeList() const { PIStringList PIObject::methodsEH() const { PIMutexLocker ml(__meta_mutex()); PIStringList ret; - __MetaData & ehd(__meta_data()[classNameID()]); - piForeachC (__EHPair & eh, ehd.eh_func) - ret << eh.second.fullFormat(); + const __MetaData & ehd(__meta_data()[classNameID()]); + for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) + ret << eh.value().fullFormat(); return ret; } bool PIObject::isMethodEHContains(const PIString & name) const { PIMutexLocker ml(__meta_mutex()); - __MetaData & ehd(__meta_data()[classNameID()]); - piForeachC (__EHPair & eh, ehd.eh_func) - if (eh.second.func_name == name) + const __MetaData & ehd(__meta_data()[classNameID()]); + for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) { + if (eh.value().func_name == name) return true; + } return false; } PIString PIObject::methodEHArguments(const PIString & name) const { PIMutexLocker ml(__meta_mutex()); - __MetaData & ehd(__meta_data()[classNameID()]); - piForeachC (__EHPair & eh, ehd.eh_func) - if (eh.second.func_name == name) - return eh.second.arguments(); + const __MetaData & ehd(__meta_data()[classNameID()]); + for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) { + if (eh.value().func_name == name) + return eh.value().arguments(); + } return PIString(); } PIString PIObject::methodEHFullFormat(const PIString & name) const { PIMutexLocker ml(__meta_mutex()); - __MetaData & ehd(__meta_data()[classNameID()]); - piForeachC (__EHPair & eh, ehd.eh_func) - if (eh.second.func_name == name) - return eh.second.fullFormat(); + const __MetaData & ehd(__meta_data()[classNameID()]); + for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) { + if (eh.value().func_name == name) + return eh.value().fullFormat(); + } return PIString(); } @@ -234,10 +237,11 @@ PIString PIObject::methodEHFromAddr(const void * addr) const { PIVector PIObject::findEH(const PIString & name) const { PIVector<__MetaFunc> ret; - __MetaData & ehd(__meta_data()[classNameID()]); - piForeachC (__EHPair & eh, ehd.eh_func) - if (eh.second.func_name == name) - ret << eh.second; + const __MetaData & ehd(__meta_data()[classNameID()]); + for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) { + if (eh.value().func_name == name) + ret << eh.value(); + } return ret; } @@ -582,11 +586,11 @@ void PIObject::dump(const PIString & line_prefix) const { //printf("dump %d properties ok\n", properties_.size()); PICout(PICoutManipulators::AddNewLine) << line_prefix << " }"; PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {"; - __MetaData & ehd(__meta_data()[classNameID()]); + const __MetaData & ehd(__meta_data()[classNameID()]); PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s(); //printf("dump %d methods\n", ehd.eh_func.size()); - piForeachC (__EHPair & eh, ehd.eh_func) { - PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.second.fullFormat(); + for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) { + PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.value().fullFormat(); } //printf("dump %d methods ok\n", ehd.eh_func.size()); PICout(PICoutManipulators::AddNewLine) << line_prefix << " }"; diff --git a/lib/main/io_devices/pibinarylog.cpp b/lib/main/io_devices/pibinarylog.cpp index 51b33dc6..c1e46d4d 100644 --- a/lib/main/io_devices/pibinarylog.cpp +++ b/lib/main/io_devices/pibinarylog.cpp @@ -96,7 +96,7 @@ bool PIBinaryLog::openDevice() { piForeachC(PIFile::FileInfo &i, es) { if (i.extension() == "binlog" && i.isFile() && i.baseName().startsWith(filePrefix())) { setPath(i.path); - piBreak; + break; } } } diff --git a/lib/main/io_devices/pipeer.cpp b/lib/main/io_devices/pipeer.cpp index 260812f6..85cc0bc3 100644 --- a/lib/main/io_devices/pipeer.cpp +++ b/lib/main/io_devices/pipeer.cpp @@ -491,7 +491,7 @@ bool PIPeer::dataRead(uchar * readed, int size) { if (p.name != from) continue; piForeach (PeerInfo::PeerAddress & a, p.addresses) { if (a.address != addr) continue; - if (a.last_ping >= time) piBreak; + if (a.last_ping >= time) break; ptime = ctime - time; a.last_ping = time; a.wait_ping = false; @@ -677,7 +677,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) { if (peer.name == pi.name) peer.sync = 0; ch = true; } - piBreak; + break; } } if (exist || isRemoved(rpeer)) continue; diff --git a/lib/main/io_devices/piserial.cpp b/lib/main/io_devices/piserial.cpp index b39fad68..4c526a62 100644 --- a/lib/main/io_devices/piserial.cpp +++ b/lib/main/io_devices/piserial.cpp @@ -544,7 +544,7 @@ bool PISerial::openDevice() { piForeachC (DeviceInfo & d, devs) { if (d.id() == pl) { p = d.path; - piBreak; + break; } } if (p.isEmpty()) { diff --git a/lib/main/io_utils/piconnection.cpp b/lib/main/io_utils/piconnection.cpp index ddafa147..785c5ebf 100644 --- a/lib/main/io_utils/piconnection.cpp +++ b/lib/main/io_utils/piconnection.cpp @@ -375,20 +375,20 @@ bool PIConnection::removeDevice(const PIString & full_path) { PIStringList dntd(deviceNames(dev)); piForeachC (PIString & n, dntd) device_names.removeOne(n); - piForeachC (SPair & s, senders) { - if (s.second == 0) continue; - s.second->lock(); - s.second->devices.removeAll(dev); - s.second->unlock(); + for (auto s = senders.constBegin(); s != senders.constEnd(); s++) { + if (s.value() == 0) continue; + s.value()->lock(); + s.value()->devices.removeAll(dev); + s.value()->unlock(); } device_modes.remove(dev); - piForeachC (PEPair & i, extractors) { - if (i.second == 0) continue; - i.second->devices.removeAll(dev); + for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) { + if (i.value() == 0) continue; + i.value()->devices.removeAll(dev); } bounded_extractors.remove(dev); channels_.remove(dev); - for (PIMap >::iterator it = channels_.begin(); it != channels_.end(); ++it) + for (auto it = channels_.begin(); it != channels_.end(); it++) it.value().removeAll(dev); __device_pool__->lock(); if (diags_.value(dev, 0) != 0) @@ -404,11 +404,11 @@ void PIConnection::removeAllDevices() { PIVector bdevs(__device_pool__->boundedDevices(this)); __device_pool__->lock(); piForeach (PIIODevice * d, bdevs) { - piForeachC (SPair & s, senders) { - if (s.second == 0) continue; - s.second->lock(); - s.second->devices.removeAll(d); - s.second->unlock(); + for (auto s = senders.constBegin(); s != senders.constEnd(); s++) { + if (s.value() == 0) continue; + s.value()->lock(); + s.value()->devices.removeAll(d); + s.value()->unlock(); } channels_.remove(d); for (PIMap >::iterator it = channels_.begin(); it != channels_.end(); ++it) @@ -421,9 +421,9 @@ void PIConnection::removeAllDevices() { __device_pool__->unlock(); device_modes.clear(); bounded_extractors.clear(); - piForeachC (PEPair & i, extractors) { - if (i.second == 0) continue; - i.second->devices.clear(); + for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) { + if (i.value() == 0) continue; + i.value()->devices.clear(); } } @@ -563,15 +563,15 @@ bool PIConnection::removeFilter(const PIString & name_) { void PIConnection::removeAllFilters() { __device_pool__->lock(); - piForeachC (PEPair & i, extractors) { - if (i.second == 0) continue; - channels_.remove(i.second->extractor); + for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) { + if (i.value() == 0) continue; + channels_.remove(i.value()->extractor); for (PIMap >::iterator it = channels_.begin(); it != channels_.end(); ++it) - it.value().removeAll(i.second->extractor); - if (diags_.value(i.second->extractor, 0) != 0) - delete diags_.value(i.second->extractor); - diags_.remove(i.second->extractor); - delete i.second; + it.value().removeAll(i.value()->extractor); + if (diags_.value(i.value()->extractor, 0) != 0) + delete diags_.value(i.value()->extractor); + diags_.remove(i.value()->extractor); + delete i.value(); } extractors.clear(); bounded_extractors.clear(); @@ -581,28 +581,31 @@ void PIConnection::removeAllFilters() { PIVector PIConnection::filters() const { PIVector ret; - piForeachC (PEPair & i, extractors) - if (i.second != 0) - if (i.second->extractor != 0) ret << i.second->extractor; + for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) { + if (i.value() != 0) + if (i.value()->extractor != 0) ret << i.value()->extractor; + } return ret; } PIStringList PIConnection::filterNames() const { PIStringList ret; - piForeachC (PEPair & i, extractors) - if (i.second != 0) - if (i.second->extractor != 0) ret << i.first; + for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) { + if (i.value() != 0) + if (i.value()->extractor != 0) ret << i.key(); + } return ret; } PIPacketExtractor * PIConnection::filter(const PIString & name_) const { PIString fname_ = name_.trimmed(); - piForeachC (PEPair & i, extractors) - if (i.second != 0) - if (i.second->extractor != 0 && i.first == fname_) - return i.second->extractor; + for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) { + if (i.value() != 0) + if (i.value()->extractor != 0 && i.key() == fname_) + return i.value()->extractor; + } return 0; } @@ -784,9 +787,10 @@ float PIConnection::senderFrequency(const PIString & name) const { void PIConnection::removeAllSenders() { - piForeachC (SPair & s, senders) - if (s.second != 0) - delete s.second; + for (auto s = senders.constBegin(); s != senders.constEnd(); s++) { + if (s.value() != 0) + delete s.value(); + } senders.clear(); } @@ -802,8 +806,8 @@ void PIConnection::startThreadedRead(const PIString & full_path_name) { void PIConnection::startAllThreadedReads() { - piForeachC (DevicePool::DDPair & d, __device_pool__->devices) - startThreadedRead(d.first); + for (auto d = __device_pool__->devices.constBegin(); d != __device_pool__->devices.constEnd(); d++) + startThreadedRead(d.key()); } @@ -816,10 +820,10 @@ void PIConnection::startSender(const PIString & name) { void PIConnection::startAllSenders() { - piForeachC (SPair & s, senders) { - if (s.second == 0) continue; - if (!s.second->isRunning() && !__device_pool__->fake) - s.second->start(s.second->int_); + for (auto s = senders.constBegin(); s != senders.constEnd(); s++) { + if (s.value() == 0) continue; + if (!s.value()->isRunning() && !__device_pool__->fake) + s.value()->start(s.value()->int_); } } @@ -835,8 +839,8 @@ void PIConnection::stopThreadedRead(const PIString & full_path_name) { void PIConnection::stopAllThreadedReads() { - piForeachC (DevicePool::DDPair & d, __device_pool__->devices) - stopThreadedRead(d.first); + for (auto d = __device_pool__->devices.constBegin(); d != __device_pool__->devices.constEnd(); d++) + stopThreadedRead(d.key()); } @@ -848,10 +852,10 @@ void PIConnection::stopSender(const PIString & name) { void PIConnection::stopAllSenders() { - piForeachC (SPair & s, senders) { - if (s.second == 0) continue; - if (s.second->isRunning()) - s.second->stop(); + for (auto s = senders.constBegin(); s != senders.constEnd(); s++) { + if (s.value() == 0) continue; + if (s.value()->isRunning()) + s.value()->stop(); } } @@ -1012,14 +1016,14 @@ bool PIConnection::DevicePool::removeDevice(PIConnection * parent, const PIStrin void PIConnection::DevicePool::unboundConnection(PIConnection * parent) { PIStringList rem; - piForeachC (DDPair & i, devices) { - if (i.second == 0) { - rem << i.first; + for (auto i = devices.constBegin(); i != devices.constEnd(); i++) { + if (i.value() == 0) { + rem << i.key(); continue; } - i.second->listeners.removeAll(parent); - if (i.second->listeners.isEmpty()) - rem << i.first; + i.value()->listeners.removeAll(parent); + if (i.value()->listeners.isEmpty()) + rem << i.key(); } piForeachC (PIString & i, rem) { DeviceData * dd = devices.value(i); @@ -1105,9 +1109,9 @@ PIConnection::DevicePool::DeviceData::~DeviceData() { void PIConnection::DevicePool::run() { PIVector conns(PIConnection::allConnections()); piForeach (PIConnection * c, conns) { - piForeachC (PIConnection::DPair & d, c->diags_) { - if (d.second == 0) continue; - d.second->tick(0, 1); + for (auto d = c->diags_.constBegin(); d != c->diags_.constEnd(); d++) { + if (d.value() == 0) continue; + d.value()->tick(0, 1); } } } diff --git a/lib/main/thread/piblockingdequeue.h b/lib/main/thread/piblockingdequeue.h index fe8f5a1f..27e23572 100644 --- a/lib/main/thread/piblockingdequeue.h +++ b/lib/main/thread/piblockingdequeue.h @@ -164,7 +164,7 @@ public: T t; mutex.lock(); bool isNotEmpty = !PIDeque::isEmpty(); - t = isNotEmpty ? T(PIDeque::take_front()) : defaultVal; + t = isNotEmpty ? PIDeque::take_front() : defaultVal; mutex.unlock(); if (isNotEmpty) cond_var_rem->notifyOne(); if (isOk) *isOk = isNotEmpty; diff --git a/main.cpp b/main.cpp index 5bc395f7..cbcedb6b 100644 --- a/main.cpp +++ b/main.cpp @@ -34,17 +34,22 @@ int main() { #include "picodeparser.h" int main() { - piDebug = false; + //piDebug = false; double min = -1, max = -1, mean = 0; - for (int i = 0; i < 50; ++i) { + for (int i = 0; i < 1; ++i) { PITimeMeasurer tm; /*PICodeParser cp; cp.parseFile("SH_plugin_base.h");*/ PIStringList sl; - for (int i = 0; i < 5000; ++i) { - //PIString s("1234567890-="); - //sl << s; - sl << PIString("1234567890-="); + sl.reserve(10); + for (int i = 0; i < 10; ++i) { + //PIString s = PIString("1234567890-=").repeated(100); + //sl.push_back(PIString("1234567890-=").repeated(100)); + sl << PIString("abc").repeated(i + 1); + } + for (PIString & s : sl) { + s = s.toUpperCase(); + piCout << s; } double ms = tm.elapsed_m(); if (min < 0) min = ms; diff --git a/utils/code_model_generator/main.cpp b/utils/code_model_generator/main.cpp index 6cb26cbf..7bff7667 100755 --- a/utils/code_model_generator/main.cpp +++ b/utils/code_model_generator/main.cpp @@ -218,7 +218,7 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int f << "));\n"; } if (is_union) - piBreak; + break; } if (is_union) return; piForeachC (PICodeParser::Entity * ce, e->children) { @@ -261,7 +261,7 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & f << "\t\t\tbreak;\n"; } if (is_union) - piBreak; + break; } if (is_union) return; piForeachC (PICodeParser::Entity * ce, e->children) { diff --git a/utils/deploy_tool/main.cpp b/utils/deploy_tool/main.cpp index 88019be2..46badca3 100644 --- a/utils/deploy_tool/main.cpp +++ b/utils/deploy_tool/main.cpp @@ -370,7 +370,7 @@ void procQt() { } } } - piBreak; + break; } } } diff --git a/utils/system_daemon/main.cpp b/utils/system_daemon/main.cpp index b1ed08d4..85900bd1 100755 --- a/utils/system_daemon/main.cpp +++ b/utils/system_daemon/main.cpp @@ -192,11 +192,10 @@ public: addrs_tl->content << TileList::Row(a.address.toString() + " | p = " + PIString::fromNumber(a.ping) + " | a = " + PIString::fromBool(a.isAvailable()), CellFormat()); - typedef PIPair > PeerPair; PIStringList peermap; - piForeachC(PeerPair &p , daemon_._peerMap()) { - PIString s = p.first + " | "; - piForeachCR(PIPeer::PeerInfo * pp, p.second) s += " -> " + pp->name; + for (auto p = daemon_._peerMap().constBegin(); p != daemon_._peerMap().constEnd(); p++) { + PIString s = p.key() + " | "; + piForeachCR(PIPeer::PeerInfo * pp, p.value()) s += " -> " + pp->name; peermap << s; } piForeachC(PIString &s , peermap)