Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Timo Koch
dune-common
Commits
98c37dc8
Commit
98c37dc8
authored
20 years ago
by
Christian Engwer
Browse files
Options
Downloads
Patches
Plain Diff
Made TestIterator a GenericIterator for all Container classes with operator[]
[[Imported from SVN: r1101]]
parent
33cfe205
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/genericiterator.hh
+82
-0
82 additions, 0 deletions
common/genericiterator.hh
common/test/iteratorfacadetest.hh
+3
-77
3 additions, 77 deletions
common/test/iteratorfacadetest.hh
with
85 additions
and
77 deletions
common/genericiterator.hh
0 → 100644
+
82
−
0
View file @
98c37dc8
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// $Id$
#ifndef DUNE_GENERICITERATOR_HH
#define DUNE_GENERICITERATOR_HH
#include
<dune/common/iteratorfacades.hh>
template
<
class
C
,
class
T
>
class
GenericIterator
:
public
Dune
::
RandomAccessIteratorFacade
<
GenericIterator
<
C
,
T
>
,
T
,
T
&
,
int
>
{
friend
class
GenericIterator
<
typename
Dune
::
RemoveConst
<
C
>::
Type
,
typename
Dune
::
RemoveConst
<
T
>::
Type
>
;
friend
class
GenericIterator
<
const
typename
Dune
::
RemoveConst
<
C
>::
Type
,
const
typename
Dune
::
RemoveConst
<
T
>::
Type
>
;
public:
// Constructors needed by the base iterators.
GenericIterator
()
:
container_
(
0
),
position_
(
0
)
{}
GenericIterator
(
C
&
cont
,
int
pos
)
:
container_
(
&
cont
),
position_
(
pos
)
{}
GenericIterator
(
const
GenericIterator
<
typename
Dune
::
RemoveConst
<
C
>::
Type
,
typename
Dune
::
RemoveConst
<
T
>::
Type
>&
other
)
:
container_
(
other
.
container_
),
position_
(
other
.
position_
)
{}
GenericIterator
(
const
GenericIterator
<
const
typename
Dune
::
RemoveConst
<
C
>::
Type
,
const
typename
Dune
::
RemoveConst
<
T
>::
Type
>&
other
)
:
container_
(
other
.
container_
),
position_
(
other
.
position_
)
{}
// Methods needed by the forward iterator
bool
equals
(
const
GenericIterator
<
typename
Dune
::
RemoveConst
<
C
>::
Type
,
typename
Dune
::
RemoveConst
<
T
>::
Type
>&
other
)
const
{
return
position_
==
other
.
position_
&&
container_
==
other
.
container_
;
}
bool
equals
(
const
GenericIterator
<
const
typename
Dune
::
RemoveConst
<
C
>::
Type
,
const
typename
Dune
::
RemoveConst
<
T
>::
Type
>&
other
)
const
{
return
position_
==
other
.
position_
&&
container_
==
other
.
container_
;
}
T
&
dereference
()
const
{
return
container_
->
operator
[](
position_
);
}
void
increment
(){
++
position_
;
}
// Additional function needed by BidirectionalIterator
void
decrement
(){
--
position_
;
}
// Additional function needed by RandomAccessIterator
T
&
elementAt
(
int
i
)
const
{
return
container_
->
operator
[](
position_
+
i
);
}
void
advance
(
int
n
){
position_
=
position_
+
n
;
}
std
::
ptrdiff_t
distanceTo
(
GenericIterator
<
const
typename
Dune
::
RemoveConst
<
C
>::
Type
,
const
typename
Dune
::
RemoveConst
<
T
>::
Type
>
other
)
const
{
assert
(
other
.
container_
==
container_
);
return
other
.
position_
-
position_
;
}
std
::
ptrdiff_t
distanceTo
(
GenericIterator
<
typename
Dune
::
RemoveConst
<
C
>::
Type
,
typename
Dune
::
RemoveConst
<
T
>::
Type
>
other
)
const
{
assert
(
other
.
container_
==
container_
);
return
other
.
position_
-
position_
;
}
private
:
C
*
container_
;
size_t
position_
;
};
#endif
This diff is collapsed.
Click to expand it.
common/test/iteratorfacadetest.hh
+
3
−
77
View file @
98c37dc8
...
...
@@ -3,16 +3,15 @@
#ifndef __DUNE_ITERATORFACADETEST_HH__
#define __DUNE_ITERATORFACADETEST_HH__
#include
<dune/common/iteratorfacades.hh>
#include
<dune/common/genericiterator.hh>
#include
<dune/common/typetraits.hh>
template
<
class
C
,
class
T
>
class
TestIterator
;
template
<
class
T
>
class
TestContainer
{
public:
typedef
Test
Iterator
<
TestContainer
<
T
>
,
T
>
iterator
;
typedef
Generic
Iterator
<
TestContainer
<
T
>
,
T
>
iterator
;
typedef
Test
Iterator
<
const
TestContainer
<
T
>
,
const
T
>
const_iterator
;
typedef
Generic
Iterator
<
const
TestContainer
<
T
>
,
const
T
>
const_iterator
;
TestContainer
(){
for
(
int
i
=
0
;
i
<
100
;
i
++
)
...
...
@@ -47,77 +46,4 @@ private:
T
values_
[
100
];
};
template
<
class
C
,
class
T
>
class
TestIterator
:
public
Dune
::
RandomAccessIteratorFacade
<
TestIterator
<
C
,
T
>
,
T
,
T
&
,
int
>
{
friend
class
TestIterator
<
typename
Dune
::
RemoveConst
<
C
>::
Type
,
typename
Dune
::
RemoveConst
<
T
>::
Type
>
;
friend
class
TestIterator
<
const
typename
Dune
::
RemoveConst
<
C
>::
Type
,
const
typename
Dune
::
RemoveConst
<
T
>::
Type
>
;
public:
// Constructors needed by the base iterators.
TestIterator
()
:
container_
(
0
),
position_
(
0
)
{
}
TestIterator
(
C
&
cont
,
int
pos
)
:
container_
(
&
cont
),
position_
(
pos
)
{}
TestIterator
(
const
TestIterator
<
typename
Dune
::
RemoveConst
<
C
>::
Type
,
typename
Dune
::
RemoveConst
<
T
>::
Type
>&
other
)
:
container_
(
other
.
container_
),
position_
(
other
.
position_
)
{}
TestIterator
(
const
TestIterator
<
const
typename
Dune
::
RemoveConst
<
C
>::
Type
,
const
typename
Dune
::
RemoveConst
<
T
>::
Type
>&
other
)
:
container_
(
other
.
container_
),
position_
(
other
.
position_
)
{}
// Methods needed by the forward iterator
bool
equals
(
const
TestIterator
<
typename
Dune
::
RemoveConst
<
C
>::
Type
,
typename
Dune
::
RemoveConst
<
T
>::
Type
>&
other
)
const
{
return
position_
==
other
.
position_
&&
container_
==
other
.
container_
;
}
bool
equals
(
const
TestIterator
<
const
typename
Dune
::
RemoveConst
<
C
>::
Type
,
const
typename
Dune
::
RemoveConst
<
T
>::
Type
>&
other
)
const
{
return
position_
==
other
.
position_
&&
container_
==
other
.
container_
;
}
T
&
dereference
()
const
{
return
container_
->
operator
[](
position_
);
}
void
increment
(){
++
position_
;
}
// Additional function needed by BidirectionalIterator
void
decrement
(){
--
position_
;
}
// Additional function needed by RandomAccessIterator
T
&
elementAt
(
int
i
)
const
{
return
container_
->
operator
[](
position_
+
i
);
}
void
advance
(
int
n
){
position_
=
position_
+
n
;
}
std
::
ptrdiff_t
distanceTo
(
TestIterator
<
const
typename
Dune
::
RemoveConst
<
C
>::
Type
,
const
typename
Dune
::
RemoveConst
<
T
>::
Type
>
other
)
const
{
assert
(
other
.
container_
==
container_
);
return
other
.
position_
-
position_
;
}
std
::
ptrdiff_t
distanceTo
(
TestIterator
<
typename
Dune
::
RemoveConst
<
C
>::
Type
,
typename
Dune
::
RemoveConst
<
T
>::
Type
>
other
)
const
{
assert
(
other
.
container_
==
container_
);
return
other
.
position_
-
position_
;
}
private
:
C
*
container_
;
size_t
position_
;
};
#endif
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