replace piForeach* to for(:)

another c++11 try ...
This commit is contained in:
2020-07-30 20:08:33 +03:00
parent 2ffc457566
commit 557f2a4d0d
18 changed files with 151 additions and 235 deletions

View File

@@ -3,8 +3,8 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
project(pip) project(pip)
set(_PIP_MAJOR 1) set(_PIP_MAJOR 1)
set(_PIP_MINOR 99) set(_PIP_MINOR 99)
set(_PIP_REVISION 0) set(_PIP_REVISION 1)
set(_PIP_SUFFIX _prealpha) set(_PIP_SUFFIX _prebeta)
set(_PIP_COMPANY SHS) set(_PIP_COMPANY SHS)
set(_PIP_DOMAIN org.SHS) set(_PIP_DOMAIN org.SHS)

View File

@@ -480,7 +480,7 @@ void PIScreen::mouse_event(PIKbdListener::MouseEvent me) {
PIVector<PIScreenTile * > tl = prepareMouse(&me); PIVector<PIScreenTile * > tl = prepareMouse(&me);
if (tl.isEmpty()) return; if (tl.isEmpty()) return;
piForeachR (PIScreenTile * t, tl) 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<PIScreenTile * > tl = prepareMouse(&we); PIVector<PIScreenTile * > tl = prepareMouse(&we);
if (tl.isEmpty()) return; if (tl.isEmpty()) return;
piForeachR (PIScreenTile * t, tl) piForeachR (PIScreenTile * t, tl)
if (t->wheelEvent(we)) piBreak; if (t->wheelEvent(we)) break;
} }

View File

@@ -805,7 +805,7 @@ bool PITerminal::initialize() {
if (e.startsWith("TERM=")) { if (e.startsWith("TERM=")) {
PRIVATE->term_type = termType(e.mid(5).trim().toLowerCase()); PRIVATE->term_type = termType(e.mid(5).trim().toLowerCase());
//piCout << PRIVATE->term_type; //piCout << PRIVATE->term_type;
piBreak; break;
} }
pid_t fr = forkpty(&(PRIVATE->fd), pty, 0, &ws); pid_t fr = forkpty(&(PRIVATE->fd), pty, 0, &ws);
//piCoutObj << fr << PRIVATE->fd << pty; //piCoutObj << fr << PRIVATE->fd << pty;

View File

@@ -97,141 +97,32 @@
*/ */
# define piForeachCR(i,c) # 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 #else
# define piBreak {_for._end = true; break;}
template <typename C>
struct _reverse_wrapper {
C & c_;
_reverse_wrapper(C & c): c_(c) {}
_reverse_wrapper(const C & c): c_(const_cast<C&>(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 <typename C> _reverse_wrapper<C> _reverse_wrap(C & c) {return _reverse_wrapper<C>(c);}
template <typename C> _reverse_wrapper<C> _reverse_wrap(const C & c) {return _reverse_wrapper<C>(c);}
# define piForTimes(c) for(int _i##c = 0; _i##c < c; ++_i##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<typename Type> # define piForeachCR piForeachRC
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<typename Type>
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<typename Type>
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<typename Type>
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<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
for(i(*_for._it); !_for._break; _for._break = true)
#define piForeachR(i,c) for(_PIForeachR<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
for(i(*_for._rit); !_for._break; _for._break = true)
#define piForeachA(i,c) for(_PIForeach<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
for(typeof(_for._var) & i(*_for._it); !_for._break; _for._break = true)
#define piForeachAR(i,c) for(_PIForeachR<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
for(typeof(_for._var) & i(*_for._rit); !_for._break; _for._break = true)
#define piForeachC(i,c) for(_PIForeachC<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
for(const i(*_for._it); !_for._break; _for._break = true)
#define piForeachCR(i,c) for(_PIForeachCR<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
for(const i(*_for._rit); !_for._break; _for._break = true)
#define piForeachCA(i,c) for(_PIForeachC<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
for(const typeof(_for._var) & i(*_for._it); !_for._break; _for._break = true)
#define piForeachCAR(i,c) for(_PIForeachCR<typeof(c)> _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<typename Type>
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<typename Type>
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 <typename T> inline _PIForeach<T> _PIForeachNew(T & t, bool i = false) {return _PIForeach<T>(t, i);}
template <typename T> inline _PIForeach<T> * _PIForeachCast(_PIForeachBase & c, T & ) {return static_cast<_PIForeach<T> * >(&c);}
template <typename T> inline _PIForeachC<T> _PIForeachNewC(const T & t, bool i = false) {return _PIForeachC<T>(t, i);}
template <typename T> inline _PIForeachC<T> * _PIForeachCastC(_PIForeachBase & c, const T & ) {return static_cast<_PIForeachC<T> * >(&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
#endif // DOXYGEN #endif // DOXYGEN

View File

@@ -70,7 +70,6 @@ public:
} }
inline PIDeque<T> & operator =(PIDeque<T> && other) { inline PIDeque<T> & operator =(PIDeque<T> && other) {
if (this == &other) return *this;
swap(other); swap(other);
return *this; return *this;
} }
@@ -324,6 +323,12 @@ public:
piSwap<size_t>(pid_rsize, other.pid_rsize); piSwap<size_t>(pid_rsize, other.pid_rsize);
piSwap<ssize_t>(pid_start, other.pid_start); piSwap<ssize_t>(pid_start, other.pid_start);
} }
inline void swap(PIDeque<T> && other) {
piSwap<T*>(pid_data, other.pid_data);
piSwap<size_t>(pid_size, other.pid_size);
piSwap<size_t>(pid_rsize, other.pid_rsize);
piSwap<ssize_t>(pid_start, other.pid_start);
}
typedef int (*CompareFunc)(const T * , const T * ); 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);} static int compare_func(const T * t0, const T * t1) {return (*t0) < (*t1) ? -1 : ((*t0) == (*t1) ? 0 : 1);}

View File

@@ -226,6 +226,10 @@ public:
pim_content.swap(other.pim_content); pim_content.swap(other.pim_content);
pim_index.swap(other.pim_index); pim_index.swap(other.pim_index);
} }
void swap(PIMap<Key, T> && other) {
pim_content.swap(other.pim_content);
pim_index.swap(other.pim_index);
}
PIMap<Key, T> & insert(const Key & key, const T & value) { PIMap<Key, T> & insert(const Key & key, const T & value) {
bool f(false); bool f(false);

View File

@@ -69,7 +69,6 @@ public:
} }
inline PIVector<T> & operator =(PIVector<T> && other) { inline PIVector<T> & operator =(PIVector<T> && other) {
if (this == &other) return *this;
swap(other); swap(other);
return *this; return *this;
} }
@@ -301,6 +300,11 @@ public:
piSwap<size_t>(piv_size, other.piv_size); piSwap<size_t>(piv_size, other.piv_size);
piSwap<size_t>(piv_rsize, other.piv_rsize); piSwap<size_t>(piv_rsize, other.piv_rsize);
} }
inline void swap(PIVector<T> && other) {
piSwap<T*>(piv_data, other.piv_data);
piSwap<size_t>(piv_size, other.piv_size);
piSwap<size_t>(piv_rsize, other.piv_rsize);
}
typedef int (*CompareFunc)(const T * , const T * ); 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);} static int compare_func(const T * t0, const T * t1) {return (*t0) < (*t1) ? -1 : ((*t0) == (*t1) ? 0 : 1);}

View File

@@ -125,7 +125,7 @@ PIInit::PIInit() {
piForeachC (PIString & i, ifpathes) { piForeachC (PIString & i, ifpathes) {
if (fileExists(i)) { if (fileExists(i)) {
sinfo->ifconfigPath = i; sinfo->ifconfigPath = i;
piBreak; break;
} }
} }
# else # else

View File

@@ -190,39 +190,42 @@ PIStringList PIObject::scopeList() const {
PIStringList PIObject::methodsEH() const { PIStringList PIObject::methodsEH() const {
PIMutexLocker ml(__meta_mutex()); PIMutexLocker ml(__meta_mutex());
PIStringList ret; PIStringList ret;
__MetaData & ehd(__meta_data()[classNameID()]); const __MetaData & ehd(__meta_data()[classNameID()]);
piForeachC (__EHPair & eh, ehd.eh_func) for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++)
ret << eh.second.fullFormat(); ret << eh.value().fullFormat();
return ret; return ret;
} }
bool PIObject::isMethodEHContains(const PIString & name) const { bool PIObject::isMethodEHContains(const PIString & name) const {
PIMutexLocker ml(__meta_mutex()); PIMutexLocker ml(__meta_mutex());
__MetaData & ehd(__meta_data()[classNameID()]); const __MetaData & ehd(__meta_data()[classNameID()]);
piForeachC (__EHPair & eh, ehd.eh_func) for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
if (eh.second.func_name == name) if (eh.value().func_name == name)
return true; return true;
}
return false; return false;
} }
PIString PIObject::methodEHArguments(const PIString & name) const { PIString PIObject::methodEHArguments(const PIString & name) const {
PIMutexLocker ml(__meta_mutex()); PIMutexLocker ml(__meta_mutex());
__MetaData & ehd(__meta_data()[classNameID()]); const __MetaData & ehd(__meta_data()[classNameID()]);
piForeachC (__EHPair & eh, ehd.eh_func) for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
if (eh.second.func_name == name) if (eh.value().func_name == name)
return eh.second.arguments(); return eh.value().arguments();
}
return PIString(); return PIString();
} }
PIString PIObject::methodEHFullFormat(const PIString & name) const { PIString PIObject::methodEHFullFormat(const PIString & name) const {
PIMutexLocker ml(__meta_mutex()); PIMutexLocker ml(__meta_mutex());
__MetaData & ehd(__meta_data()[classNameID()]); const __MetaData & ehd(__meta_data()[classNameID()]);
piForeachC (__EHPair & eh, ehd.eh_func) for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
if (eh.second.func_name == name) if (eh.value().func_name == name)
return eh.second.fullFormat(); return eh.value().fullFormat();
}
return PIString(); return PIString();
} }
@@ -234,10 +237,11 @@ PIString PIObject::methodEHFromAddr(const void * addr) const {
PIVector<PIObject::__MetaFunc> PIObject::findEH(const PIString & name) const { PIVector<PIObject::__MetaFunc> PIObject::findEH(const PIString & name) const {
PIVector<__MetaFunc> ret; PIVector<__MetaFunc> ret;
__MetaData & ehd(__meta_data()[classNameID()]); const __MetaData & ehd(__meta_data()[classNameID()]);
piForeachC (__EHPair & eh, ehd.eh_func) for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
if (eh.second.func_name == name) if (eh.value().func_name == name)
ret << eh.second; ret << eh.value();
}
return ret; return ret;
} }
@@ -582,11 +586,11 @@ void PIObject::dump(const PIString & line_prefix) const {
//printf("dump %d properties ok\n", properties_.size()); //printf("dump %d properties ok\n", properties_.size());
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }"; PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {"; 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(); PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
//printf("dump %d methods\n", ehd.eh_func.size()); //printf("dump %d methods\n", ehd.eh_func.size());
piForeachC (__EHPair & eh, ehd.eh_func) { for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.second.fullFormat(); PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.value().fullFormat();
} }
//printf("dump %d methods ok\n", ehd.eh_func.size()); //printf("dump %d methods ok\n", ehd.eh_func.size());
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }"; PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";

View File

@@ -96,7 +96,7 @@ bool PIBinaryLog::openDevice() {
piForeachC(PIFile::FileInfo &i, es) { piForeachC(PIFile::FileInfo &i, es) {
if (i.extension() == "binlog" && i.isFile() && i.baseName().startsWith(filePrefix())) { if (i.extension() == "binlog" && i.isFile() && i.baseName().startsWith(filePrefix())) {
setPath(i.path); setPath(i.path);
piBreak; break;
} }
} }
} }

View File

@@ -491,7 +491,7 @@ bool PIPeer::dataRead(uchar * readed, int size) {
if (p.name != from) continue; if (p.name != from) continue;
piForeach (PeerInfo::PeerAddress & a, p.addresses) { piForeach (PeerInfo::PeerAddress & a, p.addresses) {
if (a.address != addr) continue; if (a.address != addr) continue;
if (a.last_ping >= time) piBreak; if (a.last_ping >= time) break;
ptime = ctime - time; ptime = ctime - time;
a.last_ping = time; a.last_ping = time;
a.wait_ping = false; a.wait_ping = false;
@@ -677,7 +677,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
if (peer.name == pi.name) peer.sync = 0; if (peer.name == pi.name) peer.sync = 0;
ch = true; ch = true;
} }
piBreak; break;
} }
} }
if (exist || isRemoved(rpeer)) continue; if (exist || isRemoved(rpeer)) continue;

View File

@@ -544,7 +544,7 @@ bool PISerial::openDevice() {
piForeachC (DeviceInfo & d, devs) { piForeachC (DeviceInfo & d, devs) {
if (d.id() == pl) { if (d.id() == pl) {
p = d.path; p = d.path;
piBreak; break;
} }
} }
if (p.isEmpty()) { if (p.isEmpty()) {

View File

@@ -375,20 +375,20 @@ bool PIConnection::removeDevice(const PIString & full_path) {
PIStringList dntd(deviceNames(dev)); PIStringList dntd(deviceNames(dev));
piForeachC (PIString & n, dntd) piForeachC (PIString & n, dntd)
device_names.removeOne(n); device_names.removeOne(n);
piForeachC (SPair & s, senders) { for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
if (s.second == 0) continue; if (s.value() == 0) continue;
s.second->lock(); s.value()->lock();
s.second->devices.removeAll(dev); s.value()->devices.removeAll(dev);
s.second->unlock(); s.value()->unlock();
} }
device_modes.remove(dev); device_modes.remove(dev);
piForeachC (PEPair & i, extractors) { for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
if (i.second == 0) continue; if (i.value() == 0) continue;
i.second->devices.removeAll(dev); i.value()->devices.removeAll(dev);
} }
bounded_extractors.remove(dev); bounded_extractors.remove(dev);
channels_.remove(dev); channels_.remove(dev);
for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it) for (auto it = channels_.begin(); it != channels_.end(); it++)
it.value().removeAll(dev); it.value().removeAll(dev);
__device_pool__->lock(); __device_pool__->lock();
if (diags_.value(dev, 0) != 0) if (diags_.value(dev, 0) != 0)
@@ -404,11 +404,11 @@ void PIConnection::removeAllDevices() {
PIVector<PIIODevice * > bdevs(__device_pool__->boundedDevices(this)); PIVector<PIIODevice * > bdevs(__device_pool__->boundedDevices(this));
__device_pool__->lock(); __device_pool__->lock();
piForeach (PIIODevice * d, bdevs) { piForeach (PIIODevice * d, bdevs) {
piForeachC (SPair & s, senders) { for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
if (s.second == 0) continue; if (s.value() == 0) continue;
s.second->lock(); s.value()->lock();
s.second->devices.removeAll(d); s.value()->devices.removeAll(d);
s.second->unlock(); s.value()->unlock();
} }
channels_.remove(d); channels_.remove(d);
for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it) for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it)
@@ -421,9 +421,9 @@ void PIConnection::removeAllDevices() {
__device_pool__->unlock(); __device_pool__->unlock();
device_modes.clear(); device_modes.clear();
bounded_extractors.clear(); bounded_extractors.clear();
piForeachC (PEPair & i, extractors) { for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
if (i.second == 0) continue; if (i.value() == 0) continue;
i.second->devices.clear(); i.value()->devices.clear();
} }
} }
@@ -563,15 +563,15 @@ bool PIConnection::removeFilter(const PIString & name_) {
void PIConnection::removeAllFilters() { void PIConnection::removeAllFilters() {
__device_pool__->lock(); __device_pool__->lock();
piForeachC (PEPair & i, extractors) { for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
if (i.second == 0) continue; if (i.value() == 0) continue;
channels_.remove(i.second->extractor); channels_.remove(i.value()->extractor);
for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it) for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it)
it.value().removeAll(i.second->extractor); it.value().removeAll(i.value()->extractor);
if (diags_.value(i.second->extractor, 0) != 0) if (diags_.value(i.value()->extractor, 0) != 0)
delete diags_.value(i.second->extractor); delete diags_.value(i.value()->extractor);
diags_.remove(i.second->extractor); diags_.remove(i.value()->extractor);
delete i.second; delete i.value();
} }
extractors.clear(); extractors.clear();
bounded_extractors.clear(); bounded_extractors.clear();
@@ -581,28 +581,31 @@ void PIConnection::removeAllFilters() {
PIVector<PIPacketExtractor * > PIConnection::filters() const { PIVector<PIPacketExtractor * > PIConnection::filters() const {
PIVector<PIPacketExtractor * > ret; PIVector<PIPacketExtractor * > ret;
piForeachC (PEPair & i, extractors) for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
if (i.second != 0) if (i.value() != 0)
if (i.second->extractor != 0) ret << i.second->extractor; if (i.value()->extractor != 0) ret << i.value()->extractor;
}
return ret; return ret;
} }
PIStringList PIConnection::filterNames() const { PIStringList PIConnection::filterNames() const {
PIStringList ret; PIStringList ret;
piForeachC (PEPair & i, extractors) for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
if (i.second != 0) if (i.value() != 0)
if (i.second->extractor != 0) ret << i.first; if (i.value()->extractor != 0) ret << i.key();
}
return ret; return ret;
} }
PIPacketExtractor * PIConnection::filter(const PIString & name_) const { PIPacketExtractor * PIConnection::filter(const PIString & name_) const {
PIString fname_ = name_.trimmed(); PIString fname_ = name_.trimmed();
piForeachC (PEPair & i, extractors) for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
if (i.second != 0) if (i.value() != 0)
if (i.second->extractor != 0 && i.first == fname_) if (i.value()->extractor != 0 && i.key() == fname_)
return i.second->extractor; return i.value()->extractor;
}
return 0; return 0;
} }
@@ -784,9 +787,10 @@ float PIConnection::senderFrequency(const PIString & name) const {
void PIConnection::removeAllSenders() { void PIConnection::removeAllSenders() {
piForeachC (SPair & s, senders) for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
if (s.second != 0) if (s.value() != 0)
delete s.second; delete s.value();
}
senders.clear(); senders.clear();
} }
@@ -802,8 +806,8 @@ void PIConnection::startThreadedRead(const PIString & full_path_name) {
void PIConnection::startAllThreadedReads() { void PIConnection::startAllThreadedReads() {
piForeachC (DevicePool::DDPair & d, __device_pool__->devices) for (auto d = __device_pool__->devices.constBegin(); d != __device_pool__->devices.constEnd(); d++)
startThreadedRead(d.first); startThreadedRead(d.key());
} }
@@ -816,10 +820,10 @@ void PIConnection::startSender(const PIString & name) {
void PIConnection::startAllSenders() { void PIConnection::startAllSenders() {
piForeachC (SPair & s, senders) { for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
if (s.second == 0) continue; if (s.value() == 0) continue;
if (!s.second->isRunning() && !__device_pool__->fake) if (!s.value()->isRunning() && !__device_pool__->fake)
s.second->start(s.second->int_); s.value()->start(s.value()->int_);
} }
} }
@@ -835,8 +839,8 @@ void PIConnection::stopThreadedRead(const PIString & full_path_name) {
void PIConnection::stopAllThreadedReads() { void PIConnection::stopAllThreadedReads() {
piForeachC (DevicePool::DDPair & d, __device_pool__->devices) for (auto d = __device_pool__->devices.constBegin(); d != __device_pool__->devices.constEnd(); d++)
stopThreadedRead(d.first); stopThreadedRead(d.key());
} }
@@ -848,10 +852,10 @@ void PIConnection::stopSender(const PIString & name) {
void PIConnection::stopAllSenders() { void PIConnection::stopAllSenders() {
piForeachC (SPair & s, senders) { for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
if (s.second == 0) continue; if (s.value() == 0) continue;
if (s.second->isRunning()) if (s.value()->isRunning())
s.second->stop(); s.value()->stop();
} }
} }
@@ -1012,14 +1016,14 @@ bool PIConnection::DevicePool::removeDevice(PIConnection * parent, const PIStrin
void PIConnection::DevicePool::unboundConnection(PIConnection * parent) { void PIConnection::DevicePool::unboundConnection(PIConnection * parent) {
PIStringList rem; PIStringList rem;
piForeachC (DDPair & i, devices) { for (auto i = devices.constBegin(); i != devices.constEnd(); i++) {
if (i.second == 0) { if (i.value() == 0) {
rem << i.first; rem << i.key();
continue; continue;
} }
i.second->listeners.removeAll(parent); i.value()->listeners.removeAll(parent);
if (i.second->listeners.isEmpty()) if (i.value()->listeners.isEmpty())
rem << i.first; rem << i.key();
} }
piForeachC (PIString & i, rem) { piForeachC (PIString & i, rem) {
DeviceData * dd = devices.value(i); DeviceData * dd = devices.value(i);
@@ -1105,9 +1109,9 @@ PIConnection::DevicePool::DeviceData::~DeviceData() {
void PIConnection::DevicePool::run() { void PIConnection::DevicePool::run() {
PIVector<PIConnection * > conns(PIConnection::allConnections()); PIVector<PIConnection * > conns(PIConnection::allConnections());
piForeach (PIConnection * c, conns) { piForeach (PIConnection * c, conns) {
piForeachC (PIConnection::DPair & d, c->diags_) { for (auto d = c->diags_.constBegin(); d != c->diags_.constEnd(); d++) {
if (d.second == 0) continue; if (d.value() == 0) continue;
d.second->tick(0, 1); d.value()->tick(0, 1);
} }
} }
} }

View File

@@ -164,7 +164,7 @@ public:
T t; T t;
mutex.lock(); mutex.lock();
bool isNotEmpty = !PIDeque<T>::isEmpty(); bool isNotEmpty = !PIDeque<T>::isEmpty();
t = isNotEmpty ? T(PIDeque<T>::take_front()) : defaultVal; t = isNotEmpty ? PIDeque<T>::take_front() : defaultVal;
mutex.unlock(); mutex.unlock();
if (isNotEmpty) cond_var_rem->notifyOne(); if (isNotEmpty) cond_var_rem->notifyOne();
if (isOk) *isOk = isNotEmpty; if (isOk) *isOk = isNotEmpty;

View File

@@ -34,17 +34,22 @@ int main() {
#include "picodeparser.h" #include "picodeparser.h"
int main() { int main() {
piDebug = false; //piDebug = false;
double min = -1, max = -1, mean = 0; double min = -1, max = -1, mean = 0;
for (int i = 0; i < 50; ++i) { for (int i = 0; i < 1; ++i) {
PITimeMeasurer tm; PITimeMeasurer tm;
/*PICodeParser cp; /*PICodeParser cp;
cp.parseFile("SH_plugin_base.h");*/ cp.parseFile("SH_plugin_base.h");*/
PIStringList sl; PIStringList sl;
for (int i = 0; i < 5000; ++i) { sl.reserve(10);
//PIString s("1234567890-="); for (int i = 0; i < 10; ++i) {
//sl << s; //PIString s = PIString("1234567890-=").repeated(100);
sl << PIString("1234567890-="); //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(); double ms = tm.elapsed_m();
if (min < 0) min = ms; if (min < 0) min = ms;

View File

@@ -218,7 +218,7 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int
f << "));\n"; f << "));\n";
} }
if (is_union) if (is_union)
piBreak; break;
} }
if (is_union) return; if (is_union) return;
piForeachC (PICodeParser::Entity * ce, e->children) { piForeachC (PICodeParser::Entity * ce, e->children) {
@@ -261,7 +261,7 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int &
f << "\t\t\tbreak;\n"; f << "\t\t\tbreak;\n";
} }
if (is_union) if (is_union)
piBreak; break;
} }
if (is_union) return; if (is_union) return;
piForeachC (PICodeParser::Entity * ce, e->children) { piForeachC (PICodeParser::Entity * ce, e->children) {

View File

@@ -370,7 +370,7 @@ void procQt() {
} }
} }
} }
piBreak; break;
} }
} }
} }

View File

@@ -192,11 +192,10 @@ public:
addrs_tl->content << TileList::Row(a.address.toString() + addrs_tl->content << TileList::Row(a.address.toString() +
" | p = " + PIString::fromNumber(a.ping) + " | p = " + PIString::fromNumber(a.ping) +
" | a = " + PIString::fromBool(a.isAvailable()), CellFormat()); " | a = " + PIString::fromBool(a.isAvailable()), CellFormat());
typedef PIPair<PIString, PIVector <PIPeer::PeerInfo* > > PeerPair;
PIStringList peermap; PIStringList peermap;
piForeachC(PeerPair &p , daemon_._peerMap()) { for (auto p = daemon_._peerMap().constBegin(); p != daemon_._peerMap().constEnd(); p++) {
PIString s = p.first + " | "; PIString s = p.key() + " | ";
piForeachCR(PIPeer::PeerInfo * pp, p.second) s += " -> " + pp->name; piForeachCR(PIPeer::PeerInfo * pp, p.value()) s += " -> " + pp->name;
peermap << s; peermap << s;
} }
piForeachC(PIString &s , peermap) piForeachC(PIString &s , peermap)