Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpp-seminar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marco Bubke
cpp-seminar
Commits
b177e1a1
Commit
b177e1a1
authored
Jan 22, 2019
by
Marco Bubke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add set functions examples
parent
6f78752b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
133 additions
and
1 deletion
+133
-1
set_functions/set_functions-examples.cpp
set_functions/set_functions-examples.cpp
+131
-0
set_functions/set_functions.pro
set_functions/set_functions.pro
+2
-1
No files found.
set_functions/set_functions-examples.cpp
0 → 100644
View file @
b177e1a1
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include <iterator>
#include <QTextDocument>
#include <QTextBlock>
#include <vector>
namespace
Examples
{
class
TextBlockIterator
{
public:
using
iterator_category
=
std
::
forward_iterator_tag
;
using
value_type
=
QTextBlock
;
using
difference_type
=
int
;
using
pointer
=
QTextBlock
*
;
using
reference
=
QTextBlock
&
;
TextBlockIterator
(
const
QTextDocument
*
document
,
int
blockNumber
)
:
m_document
(
document
)
,
m_blockNumber
(
blockNumber
)
{}
TextBlockIterator
(
const
QTextBlock
&
textBlock
)
:
m_document
(
textBlock
.
document
())
,
m_blockNumber
(
textBlock
.
blockNumber
())
{}
QTextBlock
operator
*
()
{
return
m_document
->
findBlockByNumber
(
m_blockNumber
);
}
TextBlockIterator
operator
++
()
{
++
m_blockNumber
;
return
*
this
;
}
friend
bool
operator
==
(
TextBlockIterator
first
,
TextBlockIterator
second
)
{
return
first
.
m_document
==
second
.
m_document
&&
first
.
m_blockNumber
==
second
.
m_blockNumber
;
}
friend
bool
operator
!=
(
TextBlockIterator
first
,
TextBlockIterator
second
)
{
return
!
(
first
==
second
);
}
private:
const
QTextDocument
*
m_document
;
int
m_blockNumber
;
};
class
Range
{
public:
int
start
=
0
;
int
end
=
0
;
friend
bool
operator
<
(
Range
first
,
Range
second
)
{
return
std
::
tie
(
first
.
start
,
first
.
end
)
<
std
::
tie
(
second
.
start
,
second
.
end
);
}
};
using
Ranges
=
std
::
vector
<
Range
>
;
void
function
()
{
QTextDocument
document
;
Ranges
ranges
;
std
::
sort
(
ranges
.
begin
(),
ranges
.
end
());
auto
begin
=
TextBlockIterator
(
document
.
begin
());
auto
end
=
TextBlockIterator
(
document
.
end
());
std
::
vector
<
QTextBlock
>
textBlockInsideRanges
;
std
::
vector
<
QTextBlock
>
textBlockOutsideRanges
;
class
Compare
{
public:
bool
operator
()(
QTextBlock
first
,
Range
second
)
{
return
first
.
blockNumber
()
<
second
.
start
;
}
bool
operator
()(
Range
first
,
QTextBlock
second
)
{
return
first
.
end
<
second
.
blockNumber
();
}
};
std
::
set_intersection
(
begin
,
end
,
ranges
.
begin
(),
ranges
.
end
(),
std
::
back_inserter
(
textBlockInsideRanges
),
Compare
{});
std
::
set_difference
(
begin
,
end
,
ranges
.
begin
(),
ranges
.
end
(),
std
::
back_inserter
(
textBlockOutsideRanges
),
Compare
{});
}
}
set_functions/set_functions.pro
View file @
b177e1a1
...
...
@@ -3,5 +3,6 @@ include(../shared/benchmark.pri)
TARGET
=
set_functions
SOURCES
+=
\
set_functions
-
benchmark
.
cpp
set_functions
-
benchmark
.
cpp
\
set_functions
-
examples
.
cpp
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment