Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HEPnOS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
sds
HEP
HEPnOS
Commits
31a57565
Commit
31a57565
authored
Apr 13, 2018
by
Matthieu Dorier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added iterator functionalities to DataSet
parent
c4044fd9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
207 additions
and
7 deletions
+207
-7
include/hepnos/DataSet.hpp
include/hepnos/DataSet.hpp
+125
-2
include/hepnos/DataStore.hpp
include/hepnos/DataStore.hpp
+3
-1
src/DataSet.cpp
src/DataSet.cpp
+75
-0
src/DataStore.cpp
src/DataStore.cpp
+4
-4
No files found.
include/hepnos/DataSet.hpp
View file @
31a57565
...
...
@@ -257,8 +257,131 @@ class DataSet {
*/
DataSet
createDataSet
(
const
std
::
string
&
name
);
typedef
DataStore
::
const_iterator
const_dataset_iterator
;
typedef
DataStore
::
iterator
dataset_iterator
;
typedef
DataStore
::
const_iterator
const_iterator
;
typedef
DataStore
::
iterator
iterator
;
/**
* @brief Accesses an existing DataSet using the []
* operator. If no DataSet correspond to the provided name,
* the function returns a DataSet instance d such that
* d.valid() is false.
*
* @param datasetName Name of the DataSet to retrieve.
*
* @return a DataSet corresponding to the provided name.
*/
DataSet
operator
[](
const
std
::
string
&
datasetName
)
const
;
/**
* @brief Searches this DataSet for an DataSet with
* the provided name and returns an iterator to it if found,
* otherwise it returns an iterator to DataStore::end().
*
* @param datasetName Name of the DataSet to find.
*
* @return an iterator pointing to the DataSet if found,
* DataSet::end() otherwise.
*/
iterator
find
(
const
std
::
string
&
datasetName
);
/**
* @brief Searches this DataSet for an DataSet with
* the provided name and returns a const_iterator to it
* if found, otherwise it returns an iterator to DataSet::end().
*
* @param datasetName Name of the DataSet to find.
*
* @return a const_iterator pointing to the DataSet if found,
* DataSet::cend() otherwise.
*/
const_iterator
find
(
const
std
::
string
&
datasetName
)
const
;
/**
* @brief Returns an iterator referring to the first DataSet
* in this DataSet.
*
* @return an iterator referring to the first DataSet in this DataSet.
*/
iterator
begin
();
/**
* @brief Returns an iterator referring to the end of the DataSet.
* The DataSet pointed to by this iterator is not valid (that is,
* `end()->valid()` return `false`).
*
* @return an iterator referring to the end of the DataSet.
*/
iterator
end
();
/**
* @brief Returns a const_iterator referring to the first DataSet
* in this DataSet.
*
* @return a const_iterator referring to the first DataSet in this DataSet.
*/
const_iterator
cbegin
()
const
;
/**
* @brief Returns a const_iterator referring to the end of the DataSet.
* The DataSet pointed to by this iterator is not valid (that is,
* `cend()->valid()` return `false`).
*
* @return a const_iterator referring to the end of the DataStore.
*/
const_iterator
cend
()
const
;
/**
* @brief Returns an iterator pointing to the first DataSet in this
* DataSet, whose name is not considered to go before lb
* (i.e., either it is equal or goes after, alphabetically).
*
* @param lb DataSet name to search for.
*
* @return An iterator to the the first DataSet in this DataSet
* whose name is not considered to go before lb, or DataStore::end()
* if all keys are considered to go before it.
*/
iterator
lower_bound
(
const
std
::
string
&
lb
);
/**
* @brief Returns a const_iterator pointing to the first DataSet in this
* DataSet whose name is not considered to go before lb
* (i.e., either it is equal or goes after, alphabetically).
*
* @param lb DataSet name to search for.
*
* @return A const_iterator to the the first DataSet in the DataSet
* whose name is not considered to go before lb, or DataSet::cend()
* if all DataSet names are considered to go before it.
*/
const_iterator
lower_bound
(
const
std
::
string
&
lb
)
const
;
/**
* @brief Returns an iterator pointing to the first DataSet in the
* DataStore whose key is considered to go after ub.
*
* @param ub DataSet name to search for.
*
* @return An iterator to the the first DataSet in this DataSet,
* whose name is considered to go after ub, or DataSet::end() if
* no DataSet names are considered to go after it.
*/
iterator
upper_bound
(
const
std
::
string
&
ub
);
/**
* @brief Returns a const_iterator pointing to the first DataSet in this
* DataSet whose key is considered to go after ub.
*
* @param ub DataSet name to search for.
*
* @return A const_iterator to the the first DataSet in this DataSet
* whose name is considered to go after ub, or DataSet::end() if
* no DataSet names are considered to go after it.
*/
const_iterator
upper_bound
(
const
std
::
string
&
ub
)
const
;
};
}
...
...
include/hepnos/DataStore.hpp
View file @
31a57565
...
...
@@ -60,7 +60,7 @@ class DataStore {
~
DataStore
();
/**
* @brief Accesses an existin
t
DataSet using the []
* @brief Accesses an existin
g
DataSet using the []
* operator. If no DataSet correspond to the provided name,
* the function returns a DataSet instance d such that
* d.valid() is false.
...
...
@@ -268,6 +268,7 @@ class DataStore::const_iterator {
friend
class
DataStore
::
Impl
;
friend
class
DataStore
;
friend
class
DataSet
;
protected:
...
...
@@ -400,6 +401,7 @@ class DataStore::iterator : public DataStore::const_iterator {
friend
class
DataStore
::
Impl
;
friend
class
DataStore
;
friend
class
DataSet
;
private:
...
...
src/DataSet.cpp
View file @
31a57565
...
...
@@ -116,4 +116,79 @@ DataSet DataSet::createDataSet(const std::string& name) {
return
DataSet
(
*
(
m_impl
->
m_datastore
),
1
,
fullname
(),
name
);
}
DataSet
DataSet
::
operator
[](
const
std
::
string
&
datasetName
)
const
{
auto
it
=
find
(
datasetName
);
return
std
::
move
(
*
it
);
}
DataSet
::
iterator
DataSet
::
find
(
const
std
::
string
&
datasetName
)
{
int
ret
;
if
(
datasetName
.
find
(
'/'
)
!=
std
::
string
::
npos
)
{
throw
Exception
(
"Invalid character '/' in dataset name"
);
}
std
::
vector
<
char
>
data
;
bool
b
=
m_impl
->
m_datastore
->
load
(
m_impl
->
m_level
+
1
,
fullname
(),
datasetName
,
data
);
if
(
!
b
)
{
return
m_impl
->
m_datastore
->
end
();
}
return
iterator
(
*
(
m_impl
->
m_datastore
),
DataSet
(
*
(
m_impl
->
m_datastore
),
1
,
fullname
(),
datasetName
));
}
DataSet
::
const_iterator
DataSet
::
find
(
const
std
::
string
&
datasetName
)
const
{
iterator
it
=
const_cast
<
DataSet
*>
(
this
)
->
find
(
datasetName
);
return
it
;
}
DataSet
::
iterator
DataSet
::
begin
()
{
DataSet
ds
(
*
(
m_impl
->
m_datastore
),
m_impl
->
m_level
+
1
,
fullname
(),
""
);
ds
=
ds
.
next
();
if
(
ds
.
valid
())
return
iterator
(
*
(
m_impl
->
m_datastore
),
ds
);
else
return
end
();
}
DataSet
::
iterator
DataSet
::
end
()
{
return
m_impl
->
m_datastore
->
end
();
}
DataSet
::
const_iterator
DataSet
::
cbegin
()
const
{
return
const_iterator
(
const_cast
<
DataSet
*>
(
this
)
->
begin
());
}
DataSet
::
const_iterator
DataSet
::
cend
()
const
{
return
m_impl
->
m_datastore
->
cend
();
}
DataSet
::
iterator
DataSet
::
lower_bound
(
const
std
::
string
&
lb
)
{
std
::
string
lb2
=
lb
;
size_t
s
=
lb2
.
size
();
lb2
[
s
-
1
]
-=
1
;
// sdskv_list_keys's start_key is exclusive
iterator
it
=
find
(
lb2
);
if
(
it
!=
end
())
{
// we found something before the specified lower bound
++
it
;
return
it
;
}
DataSet
ds
(
*
(
m_impl
->
m_datastore
),
m_impl
->
m_level
+
1
,
fullname
(),
lb2
);
ds
=
ds
.
next
();
if
(
!
ds
.
valid
())
return
end
();
else
return
iterator
(
*
(
m_impl
->
m_datastore
),
ds
);
}
DataSet
::
const_iterator
DataSet
::
lower_bound
(
const
std
::
string
&
lb
)
const
{
iterator
it
=
const_cast
<
DataSet
*>
(
this
)
->
lower_bound
(
lb
);
return
it
;
}
DataSet
::
iterator
DataSet
::
upper_bound
(
const
std
::
string
&
ub
)
{
DataSet
ds
(
*
(
m_impl
->
m_datastore
),
m_impl
->
m_level
+
1
,
fullname
(),
ub
);
ds
=
ds
.
next
();
if
(
!
ds
.
valid
())
return
end
();
else
return
iterator
(
*
(
m_impl
->
m_datastore
),
ds
);
}
DataSet
::
const_iterator
DataSet
::
upper_bound
(
const
std
::
string
&
ub
)
const
{
iterator
it
=
const_cast
<
DataSet
*>
(
this
)
->
upper_bound
(
ub
);
return
it
;
}
}
src/DataStore.cpp
View file @
31a57565
...
...
@@ -282,7 +282,7 @@ DataStore::const_iterator DataStore::find(const std::string& datasetName) const
}
DataStore
::
iterator
DataStore
::
begin
()
{
DataSet
ds
(
*
this
,
1
,
""
);
DataSet
ds
(
*
this
,
1
,
""
,
""
);
ds
=
ds
.
next
();
if
(
ds
.
valid
())
return
iterator
(
*
this
,
ds
);
else
return
end
();
...
...
@@ -293,7 +293,7 @@ DataStore::iterator DataStore::end() {
}
DataStore
::
const_iterator
DataStore
::
cbegin
()
const
{
return
const_iterator
(
const_cast
<
DataStore
&>
(
*
this
));
return
const_iterator
(
const_cast
<
DataStore
*>
(
this
)
->
begin
(
));
}
DataStore
::
const_iterator
DataStore
::
cend
()
const
{
...
...
@@ -310,7 +310,7 @@ DataStore::iterator DataStore::lower_bound(const std::string& lb) {
++
it
;
return
it
;
}
DataSet
ds
(
*
this
,
1
,
lb2
);
DataSet
ds
(
*
this
,
1
,
""
,
lb2
);
ds
=
ds
.
next
();
if
(
!
ds
.
valid
())
return
end
();
else
return
iterator
(
*
this
,
ds
);
...
...
@@ -322,7 +322,7 @@ DataStore::const_iterator DataStore::lower_bound(const std::string& lb) const {
}
DataStore
::
iterator
DataStore
::
upper_bound
(
const
std
::
string
&
ub
)
{
DataSet
ds
(
*
this
,
1
,
ub
);
DataSet
ds
(
*
this
,
1
,
""
,
ub
);
ds
=
ds
.
next
();
if
(
!
ds
.
valid
())
return
end
();
else
return
iterator
(
*
this
,
ds
);
...
...
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