Commit Graph

75 Commits

Author SHA1 Message Date
Marco Bubke
6386cd54eb Utils: Add container wrapper for setUnionMerge
It works with contiguous arrays like std::vector but it is not so useful
for other containers anyway. Use the iterator interface for std::array.

Change-Id: I9f5dd665d38ca642bbd81e1925445127ea579c22
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-08-29 10:54:58 +00:00
Marco Bubke
6775347cd2 Utils: Add setUnionMerge to algorithms
Utils::setUnionMerge is an extension of std::set_union. It is not assigning
but merging equal matching values. For example two project part with the
same id will be merged in one by the merge function.

Change-Id: Ia244a7c1ff84dfdbd30f7101ed1ccbfb88393c7d
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-08-27 13:46:21 +00:00
Alessandro Portale
f6943a712a Utils: Modernize further
Many issues, mostly in headers, were not addressed in
e38410b76c

modernize-use-auto
modernize-use-nullptr
modernize-use-override
modernize-use-using
modernize-use-default-member-init
modernize-use-equals-default

Change-Id: I320a51726db881e582b898948d53735ebb06887a
Reviewed-by: hjk <hjk@qt.io>
2018-07-24 12:21:42 +00:00
Orgad Shaneh
7cee991c70 Utils: Remove superfluous qualifications
Change-Id: I36e17dac0cff87f82f0ddaf97bc613389110f218
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-19 08:21:29 +00:00
Eike Ziller
bb28b10add Introduce static_container_cast
Casting all elements of a container, similar to qobject_container_cast.

Change-Id: Ib455fe8c7fa0d4acda7e29685c3100638a0152f8
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-05-29 13:44:51 +00:00
Eike Ziller
547ecf757d Get rid of size type conversion warning in Utils::transform
When transforming between containers with different size_type, like
QList and std::vector.

Change-Id: Ife28aacdc8627e81901579cde8b563da1408d084
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2018-05-04 13:06:55 +00:00
Tobias Hunger
0bc100911d Utils: Add pointeralgorithm.h
Change-Id: I3e81bdbf22808efbe1fb5fab13bef24c8f73f404
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-03-12 14:14:10 +00:00
Tobias Hunger
831b84a6fd Utils: Add take
Add a new algorithmn to take the first match in a container out of the container.

It takes a pointer to something and will try to match against a smart pointer
stored in the container. Besides that it also accepts the usual like a predicate,
member variable or member function.

Change-Id: I4aabd4d43aa076a534da6488d0f9c3695ba79c09
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-03-12 14:14:01 +00:00
Eike Ziller
8944ba0391 Utils::transform: Add support for various map types as result
Add support for output as std::map/unordered_map/set and QMap and QHash,
when giving the full result type as template argument. For std::
(unordered_)map, the function must return a std::pair<Key,Value>, for
QMap and QHash it can also be QPair<Key,Value>.

Change-Id: If3dff17ab6aa5d1b11abc244813fd885d10c75a4
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-12-20 09:58:50 +00:00
Eike Ziller
f62b24c475 Utils::transform: Support containers without reserve()
Support containers without reserve() as result container, for example
std::set/deque/list

Change-Id: Ia96b834c67d5ee74bfb9de2cf6b86639f6b3d5d7
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-12-20 09:58:27 +00:00
Marco Bubke
91e40e12db Utils: Converter to raw pointer and references
Sometimes you want to get raw pointer container from smart pointer
container and reference container from value container.

Change-Id: Ia018d572ac0a7bf742f3937dc38ee30670a3ca73
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-20 09:58:17 +00:00
Eike Ziller
e0a23664aa Utils::transform: Allow usage with non-const source containers
Makes it possible to e.g. transform to list of reference_wrappers.

Change-Id: Ib608034fc3f296824c289edd27563bc7a196ac6d
Reviewed-by: hjk <hjk@qt.io>
2017-12-19 07:35:38 +00:00
Eike Ziller
6b48beeeb0 Support specifying complete result type in Utils::transform
Can come in handy when the function or member does not directly return
the right value type for the result list, but is implicitly convertable
to it. For example from pointer to class to pointer to superclass, or
from int to double.

const auto result
    = Utils::transform<QVector<double>>(v, &ValueType::intMember)

Change-Id: I0e1914d70bb2580b91098dd37e85a31ca14b0ae6
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-12-12 14:44:15 +00:00
Eike Ziller
6d05ba7bfc Algorithm: Fix compilation with Xcode 7.2.1
Change-Id: I4413841adc00156a4c8877c00ba6929262ae8e8f
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-12-07 09:55:49 +00:00
Eike Ziller
fb4f7e7420 Simplify transform and add support for more input container types
Change-Id: Ib75cfcc7741be686c0117fbb27df869e14db4f69
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-12-07 09:55:42 +00:00
Tobias Hunger
769afa9f97 Utils: Move variadice template arguments to the end
Move variadic template arguments to the end for all users in algorithm.h.

Change-Id: I7c8f1254e7de6ee9737e73d1a4721e71c188438e
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 14:41:22 +00:00
Tobias Hunger
2c09424c13 Utils: Clean up Utils::findOr and Utils::findOrDefault
Change-Id: I638e68480d3985b6df9a18aa96a067ee68484b12
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 14:41:15 +00:00
Tobias Hunger
b81d788793 Utils: Support more containers with Utils::transform
Support std::vector and similar classes as input and output.

Change-Id: I1d202d54c18e868ce0e71e4c2b6288565710baa8
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 14:11:28 +00:00
Tobias Hunger
b712b1bc7c Utils: Make Utils::indexOf work with all iterator types
Change-Id: I5b9b577bdfb26bd03583ca8349b960625124a929
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 13:16:51 +00:00
Tobias Hunger
33fc20ab51 Utils: Improve Utils::contains
* Consistently use anyOf to implement contains.
* Support contains over an container of std::unique_ptr matching a pointer.

Change-Id: I0180f3ec3d5935d8afeeac67a745d4b38a01674d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 13:16:43 +00:00
Tobias Hunger
9b832f670d Utils: Implement more Utils::anyOf variations
Change-Id: I0cba5b58dde6003f5c5cb399142f985cbe83f0a7
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 13:16:37 +00:00
Eike Ziller
c90e5b50dc Algorithm: Support std::vector<std::unique_ptr> with contains and findOr
Change-Id: I01cb71c06b405f071498ed8752f9acac44d2b223
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 08:59:52 +00:00
Tobias Hunger
566b118a87 Utils: Make algorithms take more containers
Change-Id: I05bd1052bbc2c6481fdec8a3763d9ae4f3dc8f44
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-11-27 15:00:16 +00:00
David Schulz
2453d20dd0 Utils: add filter and transform function for qobject container
Add function that casts QObjects of a given container to a desired type
and return the result via the same container with the desired value
type.

Change-Id: I45949c982c8dbdd0cce069d62cd2db5c8517f9f5
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-11-14 14:29:27 +00:00
Marco Bubke
4911d5bea3 Utils: Add predicates for comparison to constant values
Many STL algorithms have value version. So you can only use a predicate:

std::stable_partition(std::begin(list), std::end(list), [](int entry) {
     return entry < 20;
});

With this predicates you can write it in a shorter form:

std::stable_partition(std::begin(list), std::end(list), lessThan(20));

The find helpers are moved to predicates too.

Change-Id: I791b3105ca84ef7c5a519d22589a91b5548cf3e4
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-10-27 09:28:07 +00:00
Eike Ziller
cf57965ebc Simplify text format handling in syntax highlighters
Pass the mapping from custom enum to text style in form of a function,
which then can use a switch which is checked by compilers, and
avoids the need to lookup a different enum somewhere else to find
out what the mapping actually is.
That mapping is cached to keep performance as before.

Also, most highlighters created an enum just for the purpose of mapping
to text styles, basically creating duplicated subsets of text style like
enums everywhere. Instead provide a default, identity mapping from text
styles to text styles.

Change-Id: I2ea1ca702b99e36b8742dfda510b1b2753f0a1c2
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-05-23 07:47:22 +00:00
Eike Ziller
06250531db Simplify Utils::transform (again)
Change-Id: I14690b55e9eeeac0aff243a6dfd6b83e7325179b
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Nikita Baryshnikov <nib952051@gmail.com>
2017-03-29 09:05:42 +00:00
Orgad Shaneh
4136e36c6f Algorithm: Add a member variant for transform
Change-Id: I329ee764cc13dd8b794c6769a2baf2f41d6a9983
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-03-10 11:37:03 +00:00
Marco Bubke
38b6f4ff85 Utils: Reserve a container before you use transform
It is seen as good practice to use Container::reserve if you know the size
in advance.

Change-Id: If1398eaa099f4d3f657778aca46516f9bdec14c9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-02-08 14:24:45 +00:00
Orgad Shaneh
e3eee3b2b9 Utils: Eradicate Q_FOREACH in algorithm.h
Change-Id: I16cbe1896091e6677341dd954f58f69db1d61530
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-02-06 09:37:36 +00:00
Eike Ziller
af8812b248 Algorithm: Use decltype(auto)
Avoids some code duplication. Available with C++14 / GCC>=4.9.

Change-Id: Iae90466ec9620ffc84b7a45a55490f5fbc8c5b74
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-01-30 10:46:30 +00:00
Eike Ziller
63f66f28ac Use _t versions of various type traits
Available now after switching to C++14 and GCC>=4.9

Change-Id: I44e9859a6abe66db16d77b228466b65eadced8ae
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-01-30 10:46:22 +00:00
Eike Ziller
c269cc1c6d Revert "Revert "Revert "Algorithms: Simplify Utils::transform implementation"""
This reverts commit defb18aef4.
This reverts commit 602f8e72be.

The refactoring of transform does not compile with
MSVC2015 Update 2. Retry when we can upgrade to update 3.

Change-Id: I8bfd6ad12c71759af4840c2615d9a8f2390fd4bc
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-12-01 11:36:12 +00:00
Orgad Shaneh
a6c17fc537 Remove all QT_VERSION_CHECK
We only support Qt 5.6 now.

Change-Id: If94864400545b057623e3af0743c55ea1e84e33b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-08-12 13:29:58 +00:00
Eike Ziller
c3ee2d06ba Algorithm: Allow sorting container of pointers with member (function)
Change-Id: I2928081750f86b66e969ec2f7ade9e67ce19a825
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2016-08-09 13:17:43 +00:00
Orgad Shaneh
a23e0692b4 Utils: Introduce sort variants for member and member function
Change-Id: Iff29f2c55a08e85de7f0ff4e431f326e351e5305
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-08-09 10:51:28 +00:00
Eike Ziller
defb18aef4 Algorithm: Fix build issue with MSVC2015
Be more specific on which overload to call.

Change-Id: Ie38252403774ea34c165daedd74c02bbed693439
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-07-14 13:29:41 +00:00
Eike Ziller
602f8e72be Revert "Revert "Algorithms: Simplify Utils::transform implementation""
This reverts commit 52f1fe7033.
Revert the revert, which was done because we still support
compilation of 4.1 with GCC 4.7, and that crashes with this patch.
For master/4.2 we require GCC 4.8.

Change-Id: Ifd0b8b4641fe3dd658f9bde62b9e4f888d998ee7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2016-07-13 06:12:13 +00:00
Christian Stenger
891899dcd4 Utils: Fix compile for Qt5.5
Change-Id: I4294fb7dd448e74236e085f7a1884ecedd5a5b90
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-06-27 08:58:56 +00:00
Eike Ziller
5fcf0c438f PluginManager: Code clean up
Mostly refactor some explicit loops, and nicer reverse looping.

Change-Id: I102b86da597b37cd496762bd776af73ec407d838
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2016-06-24 12:30:05 +00:00
Nikita Baryshnikov
2fbf126e4e Utils::transform with using keyword
Change-Id: I98274bbd78a629854dd1774698158d9bdadc4096
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-06-02 20:29:58 +00:00
hjk
39a38d5679 Wholesale conversion to #pragma once
Kudos to cgmb and https://github.com/cgmb/guardonce

Change-Id: Ifa8970734b8d43fd08c9260c645bdb0228633791
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-03-30 15:20:19 +00:00
Tobias Hunger
f72370f20a Update License according to agreement with Free Qt Foundation
* Update remaining files in src

Change-Id: I1896f17fcf34f71c3310c87899fb5171b8e4afb1
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-01-19 15:59:41 +00:00
Tobias Hunger
1bb16ad6b5 Algorithm: Add filteredUnique
This methods returns a new container with only the unique elements
in the input container. Uses == for comparison of elements.

Change-Id: I80c2027b4d275d27343bd64851c17d42bc971e82
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-11-04 08:48:20 +00:00
Tobias Hunger
7d4078b963 Algorithm: Add partition functions
These take a container and a predicate and return a Partition
struct with the hit and miss fields. Any element in the original
container will end up in either hit or miss, depending on whether
the predicate returned true for the element or not.

Change-Id: Ia02cd704d6fe1388dc677308440acc48f7c9c1e1
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-11-03 10:20:51 +00:00
Tobias Hunger
3810a14552 Utils: Fix indention
Change-Id: Idc7ec5d102b0e3c838700ee7d89db7aea3399728
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-10-27 12:16:43 +00:00
Tobias Hunger
4df436f61a Algorithm: Make filtered accept a member function pointer
Change-Id: Ib71da93b3893ffb3309d00d7ce2dc803ff0eb4b4
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-10-23 11:53:49 +00:00
Tobias Hunger
1ffd78bbf5 Algorithm: Make transform work with simple iterators
Do not require containers to provide a size() method. This
makes for a less optimized insertion into the target container,
but most Qt classes should still handle this ok.

The upside is that e.g. the treemodel iterators can now be
transformed.

Change-Id: I4f149720631d9efb7b787332f039074b4c796965
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-10-21 14:07:46 +00:00
Tobias Hunger
a0269d8b27 Algorithm: Mark output of filtered as Q_REQUIRED_RESULT
Change-Id: I0518ed3c649efc8854cb5ef63c02e4def984cdd2
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-10-21 14:07:41 +00:00
Eike Ziller
9b52d193a3 Add Utils::filtered as a wrapper around std::copy_if
Change-Id: I4a189581a4a7f42f880c47b91372d7e96d50655e
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
2015-10-14 12:25:34 +00:00