diff --git a/lib/main/containers/picontainers.cpp b/lib/main/containers/picontainers.cpp index d4a356c8..43d1ffde 100644 --- a/lib/main/containers/picontainers.cpp +++ b/lib/main/containers/picontainers.cpp @@ -28,147 +28,347 @@ * \fn PIVector::PIVector(); * Contructs an empty vector - * \fn PIVector::PIVector(ullong size, const Type & value = Type()); + * \fn PIVector::PIVector(size_t size, const T & value = T()); * \brief Contructs vector with size "size" filled elements "value" * \details Example: \snippet picontainers.cpp PIVector::PIVector - * \fn const Type & PIVector::at(ullong index) const; + * \fn const T & PIVector::at(size_t index) const; * \brief Read-only access to element by index "index" * \details Example: \snippet picontainers.cpp PIVector::at_c * \sa \a operator[] - * \fn Type & PIVector::at(ullong index); + * \fn T & PIVector::at(size_t index); * \brief Full access to element by index "index" * \details Example: \snippet picontainers.cpp PIVector::at * \sa \a operator[] - * \fn const Type * PIVector::data(ullong index = 0) const; + * \fn const T * PIVector::data(size_t index = 0) const; * \brief Read-only pointer to element by index "index" * \details Example: \snippet picontainers.cpp PIVector::data_c - * \fn Type * PIVector::data(ullong index = 0); + * \fn T * PIVector::data(size_t index = 0); * \brief Pointer to element by index "index" * \details Example: \snippet picontainers.cpp PIVector::data - * \fn ullong PIVector::size() const; + * \fn size_t PIVector::size() const; * \brief Elements count - * \fn int PIVector::size_s() const; + * \fn ssize_t PIVector::size_s() const; * \brief Elements count * \fn bool PIVector::isEmpty() const; * \brief Return \c "true" if vector is empty, i.e. size = 0 - * \fn bool PIVector::has(const Type & t) const; + * \fn bool PIVector::has(const T & t) const; - * \fn bool PIVector::contains(const Type & v) const; + * \fn bool PIVector::contains(const T & v) const; * \brief Return \c "true" if vector has at least one element equal "t" - * \fn int PIVector::etries(const Type & t) const; + * \fn int PIVector::etries(const T & t) const; * \brief Return how many times element "t" appears in vector - * \fn static int PIVector::compare_func(const Type * t0, const Type * t1); - * \brief Standard compare function for type "Type". Return 0 if t0 = t1, -1 if t0 < t1 and 1 if t0 > t1. + * \fn ssize_t PIVector::indexOf(const T & t) const; + * \brief Return index of first element equal "t" or -1 if there is no such element - * \fn void PIVector::resize(ullong size, const Type & new_type = Type()); + * \fn ssize_t PIVector::lastIndexOf(const T & t) const; + * \brief Return index of last element equal "t" or -1 if there is no such element + + * \fn static int PIVector::compare_func(const T * t0, const T * t1); + * \brief Standard compare function for type "T". Return 0 if t0 = t1, -1 if t0 < t1 and 1 if t0 > t1. + + * \fn void PIVector::resize(size_t size, const T & new_type = T()); * \brief Resize vector to size "size" * \details Elements removed from end of vector if new size < old size, or added new elements = "new_type" if new size > old size.\n * Example: \snippet picontainers.cpp PIVector::resize * \sa \a size(), \a clear() - * \fn PIVector & PIVector::enlarge(ullong size); + * \fn PIVector & PIVector::enlarge(size_t size); * \brief Increase vector size with "size" elements * \fn void PIVector::clear(); * \brief Clear vector. Equivalent to call "resize(0)" - * \fn PIVector & PIVector::sort(CompareFunc compare = compare_func); + * \fn PIVector & PIVector::sort(CompareFunc compare = compare_func); * \brief Sort vector using quick sort algorithm and standard compare function * \details Example: \snippet picontainers.cpp PIVector::sort_0 * With custom compare function: \snippet picontainers.cpp PIVector::sort_1 - * \fn PIVector & PIVector::fill(const Type & t); + * \fn PIVector & PIVector::fill(const T & t); * \brief Fill vector with elements "t" leave size is unchanged and return reference to vector * \details Example: \snippet picontainers.cpp PIVector::fill - * \fn Type & PIVector::back(); + * \fn PIVector & PIVector::assign(const T & t = T()); + * \brief Synonym of \a fill(t) + + * \fn PIVector & PIVector::assign(size_t new_size, const T & t); + * \brief Resize to "new_size", then fill with "t" + + * \fn T & PIVector::back(); * \brief Last element of the vector - * \fn const Type & PIVector::back() const; + * \fn const T & PIVector::back() const; * \brief Last element of the vector - * \fn Type & PIVector::front(); + * \fn T & PIVector::front(); * \brief First element of the vector - * \fn const Type & PIVector::front() const; + * \fn const T & PIVector::front() const; * \brief First element of the vector - * \fn PIVector & PIVector::push_back(const Type & t); + * \fn PIVector & PIVector::push_back(const T & t); * \brief Add new element "t" at the end of vector and return reference to vector - * \fn PIVector & PIVector::push_front(const Type & t); + * \fn PIVector & PIVector::push_front(const T & t); * \brief Add new element "t" at the beginning of vector and return reference to vector - * \fn PIVector & PIVector::pop_back(); + * \fn PIVector & PIVector::pop_back(); * \brief Remove one element from the end of vector and return reference to vector - * \fn PIVector & PIVector::pop_front(); + * \fn PIVector & PIVector::pop_front(); * \brief Remove one element from the beginning of vector and return reference to vector - * \fn Type PIVector::take_back(); + * \fn T PIVector::take_back(); * \brief Remove one element from the end of vector and return it - * \fn Type PIVector::take_front(); + * \fn T PIVector::take_front(); * \brief Remove one element from the beginning of vector and return it - * \fn PIVector & PIVector::remove(uint index); + * \fn PIVector & PIVector::remove(size_t index); * \brief Remove one element by index "index" and return reference to vector * \details Example: \snippet picontainers.cpp PIVector::remove_0 * \sa \a removeOne(), \a removeAll() - * \fn PIVector & PIVector::remove(uint index, uint count); + * \fn PIVector & PIVector::remove(size_t index, size_t count); * \brief Remove "count" elements by first index "index" and return reference to vector * \details Example: \snippet picontainers.cpp PIVector::remove_1 * \sa \a removeOne(), \a removeAll() - * \fn PIVector & PIVector::removeOne(const Type & v); + * \fn PIVector & PIVector::removeOne(const T & v); * \brief Remove no more than one element equal "v" and return reference to vector * \details Example: \snippet picontainers.cpp PIVector::removeOne * \sa \a remove(), \a removeAll() - * \fn PIVector & PIVector::removeAll(const Type & v); + * \fn PIVector & PIVector::removeAll(const T & v); * \brief Remove all elements equal "v" and return reference to vector * \details Example: \snippet picontainers.cpp PIVector::removeAll * \sa \a remove(), \a removeOne() - * \fn PIVector & PIVector::insert(uint pos, const Type & t); + * \fn PIVector & PIVector::insert(size_t pos, const T & t); * \brief Insert element "t" after index "pos" and return reference to vector * \details Example: \snippet picontainers.cpp PIVector::insert_0 - * \fn PIVector & PIVector::insert(uint pos, const PIVector & t); + * \fn PIVector & PIVector::insert(size_t pos, const PIVector & t); * \brief Insert other vector "t" after index "pos" and return reference to vector * \details Example: \snippet picontainers.cpp PIVector::insert_1 - * \fn Type & PIVector::operator [](uint index); + * \fn T & PIVector::operator [](size_t index); * \brief Full access to element by index "index" * \details Example: \snippet picontainers.cpp PIVector::() * \sa \a at() - * \fn const Type & PIVector::operator [](uint index) const; + * \fn const T & PIVector::operator [](size_t index) const; * \brief Read-only access to element by index "index" * \details Example: \snippet picontainers.cpp PIVector::()_c * \sa \a at() - * \fn PIVector & PIVector::operator <<(const Type & t); + * \fn PIVector & PIVector::operator <<(const T & t); * \brief Add new element "t" at the end of vector and return reference to vector - * \fn PIVector & PIVector::operator <<(const PIVector & t); + * \fn PIVector & PIVector::operator <<(const PIVector & t); * \brief Add vector "t" at the end of vector and return reference to vector - * \fn bool PIVector::operator ==(const PIVector & t); + * \fn bool PIVector::operator ==(const PIVector & t); * \brief Compare with vector "t" - * \fn bool PIVector::operator !=(const PIVector & t); + * \fn bool PIVector::operator !=(const PIVector & t); * \brief Compare with vector "t" * */ + + + + +/** \class PIMap + * \brief Associative array + * \details This class used to store Key = Value array of any + * type of data. \a value() returns value for key and leave map + * unchaged in any case. \a operator [] create entry in map if + * there is no entry for given key. You can retrieve all + * keys by method \a keys() and all values by methos \a values(). + * To iterate all entries use class PIMapIterator, or methods + * \a makeIterator() and \a makeReverseIterator(). + + * \fn PIMap::PIMap(); + * \brief Contructs an empty map + + * \fn PIMap::PIMap(const PIMap & other); + * \brief Contructs a copy of "other" + + * \fn PIMap & PIMap::operator =(const PIMap & other); + * \brief Copy operator + + * \fn PIMap::PIMap(const PIMap & other); + * \brief Contructs a copy of "other" + +* \fn PIMapIterator PIMap::makeIterator() const +* \brief Returns PIMapIterator for this map + +* \fn PIMapIterator PIMap::makeReverseIterator() const +* \brief Returns reverse PIMapIterator for this map + + +* \fn size_t PIMap::size() const +* \brief Returns entries count + +* \fn int PIMap::size_s() const +* \brief Returns entries count + +* \fn size_t PIMap::length() const +* \brief Returns entries count + +* \fn bool PIMap::isEmpty() const +* \brief Returns if map is empty + + +* \fn T & PIMap::operator [](const Key & key) +* \brief Returns value for key "key". If there is no key in map, create one. + +* \fn const T PIMap::operator [](const Key & key) const +* \brief Returns value for key "key". If there is no key in map, returns default T(). + +* \fn T & PIMap::at(const Key & key) +* \brief Equivalent to operator [] + +* \fn const T PIMap::at(const Key & key) const +* \brief Equivalent to operator [] + + +* \fn PIMap & PIMap::operator <<(const PIMap & other) +* \brief Insert all etries of "other" to this map. Override existing values. + +* \fn bool PIMap::operator ==(const PIMap & t) const +* \brief Compare operator + +* \fn bool PIMap::operator !=(const PIMap & t) const +* \brief Compare operator + +* \fn bool PIMap::contains(const Key & key) const +* \brief Returns "true" if map contains entry with key "key" + + +* \fn PIMap & PIMap::reserve(size_t new_size) +* \brief Reserve space for "new_size" entries + +* \fn PIMap & PIMap::removeOne(const Key & key) +* \brief Remove entry with key "key" + +* \fn PIMap & PIMap::remove(const Key & key) +* \brief Equivalent \a removeOne(key) + +* \fn PIMap & PIMap::erase(const Key & key) +* \brief Equivalent \a removeOne(key) + +* \fn PIMap & PIMap::clear() +* \brief Clear map + + +* \fn void PIMap::swap(PIMap & other) +* \brief Swap map with "other" + + +* \fn PIMap & PIMap::insert(const Key & key, const T & value) +* \brief Insert or rewrite entry with key "key" and value "value" + +* \fn const T PIMap::value(const Key & key, const T & default = T()) +* \brief Returns value for key "key". If there is no key in map, returns "default". + +* \fn PIVector PIMap::values() const +* \brief Returns all values as PIVector + +* \fn Key PIMap::key(const T & value, const Key & default = Key()) const +* \brief Returns key for first founded value "value". If there is no such value in map, returns "default". + +* \fn PIVector PIMap::keys() const +* \brief Returns all keys as PIVector + + * */ + + + + +/** \class PIMapIterator + * \brief Helper class to iterate over PIMap + * \details This class used to access keys and values in PIMap. + * You can use constructor to create iterator, or use \a PIMap::makeIterator() + * and \a PIMap::makeReverseIterator() methods. + * + * First usage variant: + * \code + * PIMap m; + * m[1] = "one"; + * m[2] = "two"; + * m[4] = "four"; + * + * PIMapIterator it(m); + * while (it.next()) { + * piCout << it.key() << it.value(); + * } + * // 1 one + * // 2 two + * // 4 four + * \endcode + * + * Using hasNext(): + * \code + * while (it.hasNext()) { + * it.next(); + * \endcode + * + * Using map method: + * \code + * auto it = m.makeIterator(); + * \endcode + * + * Write access: + * \code + * while (it.next()) { + * it.valueRef().append("_!"); + * piCout << it.key() << it.value(); + * } + * + * // 1 one_! + * // 2 two_! + * // 4 four_! + * \endcode + * + * Reverse iterator: + * \code + * auto it = m.makeReverseIterator(); + * while (it.next()) { + * piCout << it.key() << it.value(); + * } + * + * // 4 four + * // 2 two + * // 1 one + * \endcode + +* \fn PIMapIterator(const PIMap & map, bool reverse = false) +* \brief Contructs iterator for "map". Current position is invalid. + +* \fn const Key & PIMapIterator::key() const +* \brief Returns current entry key + +* \fn const T & PIMapIterator::value() const +* \brief Returns current entry value + +* \fn T & PIMapIterator::valueRef() const +* \brief Returns reference to current entry value + +* \fn bool PIMapIterator::hasNext() +* \brief Returns if iterator can jump to next entry + +* \fn bool PIMapIterator::next() +* \brief Jump to next entry and return if new position is valid. + + * */ diff --git a/lib/main/introspection/piintrospection_server_p.cpp b/lib/main/introspection/piintrospection_server_p.cpp index e5935f10..f0aee35c 100644 --- a/lib/main/introspection/piintrospection_server_p.cpp +++ b/lib/main/introspection/piintrospection_server_p.cpp @@ -214,9 +214,10 @@ PIByteArray PIIntrospection::packThreads() { if (p) { p->mutex.lock(); PIMap & tm(p->threads); - for (PIMap::iterator i = tm.begin(); i != tm.end(); ++i) { - i.value().classname = PIStringAscii(i.key()->className()); - i.value().name = i.key()->name(); + auto it = tm.makeIterator(); + while (it.next()) { + it.valueRef().classname = PIStringAscii(it.key()->className()); + it.valueRef().name = it.key()->name(); } ret << tm.values(); p->mutex.unlock(); diff --git a/lib/main/io_utils/piconnection.cpp b/lib/main/io_utils/piconnection.cpp index 785c5ebf..c82d8c7c 100644 --- a/lib/main/io_utils/piconnection.cpp +++ b/lib/main/io_utils/piconnection.cpp @@ -388,8 +388,9 @@ bool PIConnection::removeDevice(const PIString & full_path) { } bounded_extractors.remove(dev); channels_.remove(dev); - for (auto it = channels_.begin(); it != channels_.end(); it++) - it.value().removeAll(dev); + auto it = channels_.makeIterator(); + while (it.next()) + it.valueRef().removeAll(dev); __device_pool__->lock(); if (diags_.value(dev, 0) != 0) delete diags_.value(dev); @@ -411,8 +412,9 @@ void PIConnection::removeAllDevices() { s.value()->unlock(); } channels_.remove(d); - for (PIMap >::iterator it = channels_.begin(); it != channels_.end(); ++it) - it.value().removeAll(d); + auto it = channels_.makeIterator(); + while (it.next()) + it.valueRef().removeAll(d); if (diags_.value(d, 0) != 0) delete diags_.value(d); diags_.remove(d); @@ -566,8 +568,9 @@ void PIConnection::removeAllFilters() { 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.value()->extractor); + auto it = channels_.makeIterator(); + while (it.next()) + it.valueRef().removeAll(i.value()->extractor); if (diags_.value(i.value()->extractor, 0) != 0) delete diags_.value(i.value()->extractor); diags_.remove(i.value()->extractor); @@ -658,8 +661,9 @@ bool PIConnection::removeChannel(const PIString & name0) { if (pe0 != 0) dev0 = pe0; if (dev0 == 0) return false; channels_.remove(dev0); - for (PIMap >::iterator it = channels_.begin(); it != channels_.end(); ++it) - it.value().removeAll(dev0); + auto it = channels_.makeIterator(); + while (it.next()) + it.valueRef().removeAll(dev0); return true; } @@ -1240,8 +1244,9 @@ void PIConnection::Sender::tick(void * , int) { void PIConnection::unboundExtractor(PIPacketExtractor * pe) { if (pe == 0) return; channels_.remove(pe); - for (PIMap >::iterator it = channels_.begin(); it != channels_.end(); ++it) - it.value().removeAll(pe); + auto it = channels_.makeIterator(); + while (it.next()) + it.valueRef().removeAll(pe); bounded_extractors.remove(pe); PIVector k = bounded_extractors.keys(); piForeach (PIIODevice * i, k) { diff --git a/lib/main/resources/piresources.cpp b/lib/main/resources/piresources.cpp index e3a691d6..035d4d8f 100644 --- a/lib/main/resources/piresources.cpp +++ b/lib/main/resources/piresources.cpp @@ -36,13 +36,12 @@ PIByteArray PIResources::get(const PIString & name) { void PIResources::dump() { - PIMap & sm(PIResourcesStorage::instance()->sections); - PIMap::iterator si; - for (si = sm.begin(); si != sm.end(); ++si) { + auto si = PIResourcesStorage::instance()->sections.makeIterator(); + while (si.next()) { piCout << "Section [" << si.key() << "]"; if (!si.value()) continue; - PIMap::iterator fi; - for (fi = si.value()->entries.begin(); fi != si.value()->entries.end(); ++fi) { + auto fi = si.value()->entries.makeIterator(); + while (fi.next()) { PIString s = fi.key() + ": "; s << (fi.value() ? fi.value()->size_s() : 0) << " b"; piCout << " " << s; diff --git a/lib/main/resources/piresourcesstorage.cpp b/lib/main/resources/piresourcesstorage.cpp index b08dba70..fd6e20eb 100644 --- a/lib/main/resources/piresourcesstorage.cpp +++ b/lib/main/resources/piresourcesstorage.cpp @@ -31,8 +31,8 @@ PIResourcesStorage::Section::~Section() { void PIResourcesStorage::Section::add(const PIResourcesStorage::Section & s) { - PIMap::const_iterator i; - for (i = s.entries.begin(); i != s.entries.end(); ++i) { + auto i = s.entries.makeIterator(); + while (i.next()) { if (!i.value()) continue; if (entries.value(i.key(), 0)) continue; entries[i.key()] = i.value(); @@ -83,10 +83,10 @@ void PIResourcesStorage::registerSection(const uchar * rc_data, const uchar * rc piForeachC (PIResourcesStorage::__RCEntry & e, el) { ebs[e.section] << e; } - PIMap >::iterator it; - for (it = ebs.begin(); it != ebs.end(); ++it) { + auto it = ebs.makeIterator(); + while (it.next()) { PIResourcesStorage::Section s; - PIVector & itv(it.value()); + const PIVector & itv(it.value()); piForeachC (PIResourcesStorage::__RCEntry & e, itv) { //piCout << "add" << e.name << e.alias << PIString::readableSize(e.size); PIByteArray * eba = new PIByteArray(&(rc_data[e.offset]), e.size); @@ -114,8 +114,8 @@ PIByteArray PIResourcesStorage::get(const PIString & section_name, const PIStrin PIByteArray PIResourcesStorage::get(const PIString & entry_name) const { - PIMap::const_iterator i; - for (i = sections.begin(); i != sections.end(); ++i) { + auto i = sections.makeIterator(); + while (i.next()) { if (!i.value()) continue; PIByteArray * ba = i.value()->entries.value(entry_name, 0); if (!ba) continue; diff --git a/lib/main/system/pisystemmonitor.cpp b/lib/main/system/pisystemmonitor.cpp index 6b28f9b1..98e259a6 100644 --- a/lib/main/system/pisystemmonitor.cpp +++ b/lib/main/system/pisystemmonitor.cpp @@ -331,9 +331,10 @@ void PISystemMonitor::run() { tstat.cpu_load_system = piClampf(tstat.cpu_load_system, 0.f, 100.f); tstat.cpu_load_user = piClampf(tstat.cpu_load_user , 0.f, 100.f); - for (PIMap::iterator i = cur_tm.begin(); i != cur_tm.end(); ++i) { + auto i = cur_tm.makeIterator(); + while (i.next()) { if (!last_tm.contains(i.key())) continue; - ThreadStats & ts_new(i.value()); + ThreadStats & ts_new(i.valueRef()); ThreadStats & ts_old(last_tm[i.key()]); ts_new.cpu_load_kernel = calcThreadUsage(ts_new.kernel_time, ts_old.kernel_time); ts_new.cpu_load_user = calcThreadUsage(ts_new.user_time, ts_old.user_time); diff --git a/utils/code_model_generator/main.cpp b/utils/code_model_generator/main.cpp index cb42eaac..b207d679 100755 --- a/utils/code_model_generator/main.cpp +++ b/utils/code_model_generator/main.cpp @@ -87,7 +87,8 @@ void makeClassInfo(PIFile & f, const PICodeParser::Entity * e) { f << "\tci->name = \"" << e->name << "\";\n"; f << "\tci->has_name = " << (e->has_name ? "true" : "false") << ";\n"; if (!e->meta.isEmpty()) { - for (PICodeParser::MetaMap::const_iterator i = e->meta.begin(); i != e->meta.end(); ++i) + auto i = e->meta.makeIterator(); + while (i.next()) f << "\tci->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n"; } f << "\t(*classesInfo)[ci->name] = ci;\n"; @@ -176,14 +177,16 @@ void makeEnumInfo(PIFile & f, const PICodeParser::Enum * e) { f << "\t(*enumsInfo)[\"" << e->name << "\"] = ei;\n"; f << "\tei->name = \"" << e->name << "\";\n"; if (!e->meta.isEmpty()) { - for (PICodeParser::MetaMap::const_iterator i = e->meta.begin(); i != e->meta.end(); ++i) + auto i = e->meta.makeIterator(); + while (i.next()) f << "\tei->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n"; } } piForeachC (PICodeParser::EnumeratorInfo & m, e->members) { f << "\tei->members << PICodeInfo::EnumeratorInfo(\"" << m.name << "\", " << m.value << ");\n"; if (!m.meta.isEmpty()) { - for (PICodeParser::MetaMap::const_iterator i = m.meta.begin(); i != m.meta.end(); ++i) + auto i = m.meta.makeIterator(); + while (i.next()) f << "\tei->members.back().meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n"; } } diff --git a/utils/deploy_tool/main.cpp b/utils/deploy_tool/main.cpp index 46badca3..45455398 100644 --- a/utils/deploy_tool/main.cpp +++ b/utils/deploy_tool/main.cpp @@ -583,8 +583,9 @@ int main(int argc, char * argv[]) { qt_filters["platforms"] = platforms; qt_filters["styles" ] = styles ; - for (PIMap::iterator it = qt_filters.begin(); it != qt_filters.end(); ++it) - it.value().forEachInplace([](PIString i)->PIString{ + auto it = qt_filters.makeIterator(); + while (it.next()) + it.valueRef().forEachInplace([](PIString i)->PIString{ if (!i.startsWith("*")) i.prepend("*"); if (!i.endsWith("*")) i.append("*"); return i;