Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QObject with ranges
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vitaly Fanaskov
QObject with ranges
Commits
1e279e81
Commit
1e279e81
authored
5 years ago
by
vt4a2h
Browse files
Options
Downloads
Patches
Plain Diff
Implement lazy tree traversing
The implementation is based on coroutines
parent
449d4a6f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/qrangecoro_p.h
+91
-0
91 additions, 0 deletions
src/qrangecoro_p.h
with
91 additions
and
0 deletions
src/qrangecoro_p.h
0 → 100644
+
91
−
0
View file @
1e279e81
#ifndef QRANGEFALLBACK_H
#define QRANGEFALLBACK_H
#include
<range/v3/view_facade.hpp>
#include
<cppcoro/generator.hpp>
#include
<cppcoro/recursive_generator.hpp>
#include
<QtCore/QObject>
namespace
qt
::
detail
{
cppcoro
::
recursive_generator
<
QObject
*>
takeChildRecursivelyImpl
(
const
QObjectList
&
children
,
Qt
::
FindChildOptions
opts
)
{
for
(
QObject
*
c
:
children
)
{
if
(
opts
==
Qt
::
FindChildrenRecursively
)
{
co_yield
takeChildRecursivelyImpl
(
c
->
children
(),
opts
);
}
co_yield
c
;
}
}
cppcoro
::
recursive_generator
<
QObject
*>
takeChildRecursively
(
QObject
*
root
,
Qt
::
FindChildOptions
opts
=
Qt
::
FindChildrenRecursively
)
{
if
(
root
)
{
co_yield
takeChildRecursivelyImpl
(
root
->
children
(),
opts
);
}
}
template
<
class
T
=
QObject
>
class
children_view
:
public
ranges
::
view_facade
<
children_view
<
T
>>
{
friend
ranges
::
range_access
;
struct
Data
{
T
*
obj
;
cppcoro
::
recursive_generator
<
QObject
*>
gen
;
};
std
::
shared_ptr
<
Data
>
m_data
;
struct
cursor
;
cursor
begin_cursor
()
{
return
cursor
(
m_data
->
gen
.
begin
());
}
public
:
children_view
()
=
default
;
explicit
children_view
(
T
*
o
,
Qt
::
FindChildOptions
opts
=
Qt
::
FindChildrenRecursively
)
:
m_data
(
std
::
make_shared
<
Data
>
(
Data
{
o
,
takeChildRecursively
(
o
,
opts
)}))
{}
explicit
children_view
(
T
&
o
,
Qt
::
FindChildOptions
opts
=
Qt
::
FindChildrenRecursively
)
:
children_view
(
&
o
,
opts
)
{}
};
template
<
class
T
>
struct
children_view
<
T
>::
cursor
{
cppcoro
::
recursive_generator
<
QObject
*>::
iterator
it
;
decltype
(
auto
)
read
()
const
{
return
*
it
;
}
void
next
()
{
++
it
;
}
auto
equal
(
ranges
::
default_sentinel_t
)
const
{
return
it
==
cppcoro
::
recursive_generator
<
QObject
*>::
iterator
(
nullptr
);
}
explicit
cursor
(
cppcoro
::
recursive_generator
<
QObject
*>::
iterator
it
)
:
it
(
it
)
{}
cursor
()
=
default
;
};
}
// qt::detail
#endif // QRANGEFALLBACK_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment