Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Dmitri Naumov
ogs
Commits
e2ba306b
Commit
e2ba306b
authored
9 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[BL] changed map key type
parent
d5163998
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
BaseLib/ConfigTreeNew-impl.h
+6
-4
6 additions, 4 deletions
BaseLib/ConfigTreeNew-impl.h
BaseLib/ConfigTreeNew.cpp
+32
-15
32 additions, 15 deletions
BaseLib/ConfigTreeNew.cpp
BaseLib/ConfigTreeNew.h
+6
-3
6 additions, 3 deletions
BaseLib/ConfigTreeNew.h
with
44 additions
and
22 deletions
BaseLib/ConfigTreeNew-impl.h
+
6
−
4
View file @
e2ba306b
...
...
@@ -71,7 +71,7 @@ ConfigTreeNew::
getConfParamList
(
std
::
string
const
&
param
)
const
{
checkUnique
(
param
);
markVisited
<
T
>
(
param
,
true
);
markVisited
<
T
>
(
param
,
false
,
true
);
auto
p
=
_tree
->
equal_range
(
param
);
return
Range
<
ValueIterator
<
T
>
>
(
...
...
@@ -144,7 +144,7 @@ ConfigTreeNew::
getAttribute
(
std
::
string
const
&
attr
)
const
{
checkUniqueAttr
(
attr
);
markVisited
(
attr
,
true
);
markVisited
<
T
>
(
attr
,
true
);
if
(
auto
attrs
=
_tree
->
get_child_optional
(
"<xmlattr>"
))
{
if
(
auto
a
=
attrs
->
get_child_optional
(
attr
))
{
...
...
@@ -166,11 +166,13 @@ getAttribute(std::string const& attr) const
template
<
typename
T
>
ConfigTreeNew
::
CountType
&
ConfigTreeNew
::
markVisited
(
std
::
string
const
&
key
,
bool
const
peek_only
)
const
markVisited
(
std
::
string
const
&
key
,
bool
const
is_attr
,
bool
const
peek_only
)
const
{
auto
const
type
=
std
::
type_index
(
typeid
(
T
));
auto
p
=
_visited_params
.
emplace
(
key
,
CountType
{
peek_only
?
0
:
1
,
type
});
auto
p
=
_visited_params
.
emplace
(
std
::
make_pair
(
is_attr
,
key
),
CountType
{
peek_only
?
0
:
1
,
type
});
if
(
!
p
.
second
)
{
// no insertion happened
auto
&
v
=
p
.
first
->
second
;
...
...
This diff is collapsed.
Click to expand it.
BaseLib/ConfigTreeNew.cpp
+
32
−
15
View file @
e2ba306b
...
...
@@ -211,7 +211,7 @@ void ConfigTreeNew::checkUnique(const std::string &key) const
{
checkKeyname
(
key
);
if
(
_visited_params
.
find
(
key
)
!=
_visited_params
.
end
())
{
if
(
_visited_params
.
find
(
{
false
,
key
}
)
!=
_visited_params
.
end
())
{
error
(
"Key <"
+
key
+
"> has already been processed."
);
}
}
...
...
@@ -220,7 +220,7 @@ void ConfigTreeNew::checkUniqueAttr(const std::string &attr) const
{
checkKeyname
(
attr
);
if
(
_visited_params
.
find
(
"<xmlattr>."
+
attr
)
!=
_visited_params
.
end
())
{
if
(
_visited_params
.
find
(
{
true
,
attr
}
)
!=
_visited_params
.
end
())
{
error
(
"Attribute
\"
"
+
attr
+
"
\"
has already been processed."
);
}
}
...
...
@@ -229,16 +229,17 @@ ConfigTreeNew::CountType&
ConfigTreeNew
::
markVisited
(
std
::
string
const
&
key
,
bool
const
peek_only
)
const
{
return
markVisited
<
ConfigTreeNew
>
(
key
,
peek_only
);
return
markVisited
<
ConfigTreeNew
>
(
key
,
false
,
peek_only
);
}
void
ConfigTreeNew
::
markVisitedDecrement
(
std
::
string
const
&
key
)
const
markVisitedDecrement
(
bool
const
is_attr
,
std
::
string
const
&
key
)
const
{
auto
const
type
=
std
::
type_index
(
typeid
(
nullptr
));
auto
p
=
_visited_params
.
emplace
(
key
,
CountType
{
-
1
,
type
});
auto
p
=
_visited_params
.
emplace
(
std
::
make_pair
(
is_attr
,
key
),
CountType
{
-
1
,
type
});
if
(
!
p
.
second
)
{
// no insertion happened
auto
&
v
=
p
.
first
->
second
;
...
...
@@ -276,24 +277,40 @@ ConfigTreeNew::checkAndInvalidate()
for
(
auto
const
&
p
:
*
_tree
)
{
DBUG
(
"-- %s <%s> "
,
_path
.
c_str
(),
p
.
first
.
c_str
());
if
(
p
.
first
!=
"<xmlattr>"
)
// attributes are handled below
markVisitedDecrement
(
p
.
first
);
markVisitedDecrement
(
false
,
p
.
first
);
DBUG
(
"tag %s"
,
p
.
first
.
c_str
());
}
// iterate over attributes
if
(
auto
attrs
=
_tree
->
get_child_optional
(
"<xmlattr>"
))
{
DBUG
(
"has attributes"
);
for
(
auto
const
&
p
:
*
attrs
)
{
markVisitedDecrement
(
"<xmlattr>."
+
p
.
first
);
// markVisitedDecrement("<xmlattr>"
);
markVisitedDecrement
(
true
,
p
.
first
);
DBUG
(
"attr %s"
,
p
.
first
.
c_str
()
);
}
}
for
(
auto
const
&
p
:
_visited_params
)
{
if
(
p
.
second
.
count
>
0
)
{
warning
(
"Key <"
+
p
.
first
+
"> has been read "
+
std
::
to_string
(
p
.
second
.
count
)
+
" time(s) more than it was present in the configuration tree."
);
}
else
if
(
p
.
second
.
count
<
0
)
{
warning
(
"Key <"
+
p
.
first
+
"> has been read "
+
std
::
to_string
(
-
p
.
second
.
count
)
+
" time(s) less than it was present in the configuration tree."
);
for
(
auto
const
&
p
:
_visited_params
)
{
auto
const
&
tag
=
std
::
get
<
1
>
(
p
.
first
);
auto
const
&
count
=
p
.
second
.
count
;
if
(
std
::
get
<
0
>
(
p
.
first
))
{
// tag
if
(
count
>
0
)
{
warning
(
"XML attribute
\"
"
+
tag
+
"
\"
has been read "
+
std
::
to_string
(
count
)
+
" time(s) more than it was present in the configuration tree."
);
}
else
if
(
count
<
0
)
{
warning
(
"XML attribute
\"
"
+
tag
+
"
\"
has been read "
+
std
::
to_string
(
-
count
)
+
" time(s) less than it was present in the configuration tree."
);
}
}
else
{
// XML attribute
if
(
count
>
0
)
{
warning
(
"Key <"
+
tag
+
"> has been read "
+
std
::
to_string
(
count
)
+
" time(s) more than it was present in the configuration tree."
);
}
else
if
(
count
<
0
)
{
warning
(
"Key <"
+
tag
+
"> has been read "
+
std
::
to_string
(
-
count
)
+
" time(s) less than it was present in the configuration tree."
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
BaseLib/ConfigTreeNew.h
+
6
−
3
View file @
e2ba306b
...
...
@@ -396,7 +396,8 @@ private:
* \c param peek_only if true, do not change the read-count of the given key.
*/
template
<
typename
T
>
CountType
&
markVisited
(
std
::
string
const
&
key
,
bool
peek_only
=
false
)
const
;
CountType
&
markVisited
(
std
::
string
const
&
key
,
bool
const
is_attr
,
bool
peek_only
=
false
)
const
;
/*! Keeps track of the key \c key and its value type ConfigTree.
*
...
...
@@ -408,7 +409,7 @@ private:
//! Used in the destructor to compute the difference between number of reads of a parameter
//! and the number of times it exists in the ConfigTree
void
markVisitedDecrement
(
std
::
string
const
&
key
)
const
;
void
markVisitedDecrement
(
bool
const
is_attr
,
std
::
string
const
&
key
)
const
;
//! TODO doc
bool
hasChildren
(
ConfigTreeNew
const
&
ct
)
const
;
...
...
@@ -431,6 +432,8 @@ private:
//! \todo add file name
using
KeyType
=
std
::
pair
<
bool
,
std
::
string
>
;
//! A map key -> (count, type) keeping track which parameters have been read how often
//! and which datatype they have.
//!
...
...
@@ -438,7 +441,7 @@ private:
//! Therefore it has to be mutable in order to be able to read from
//! constant instances, e.g., those passed as constant references to
//! temporaries.
mutable
std
::
map
<
std
::
string
,
CountType
>
_visited_params
;
mutable
std
::
map
<
KeyType
,
CountType
>
_visited_params
;
//! \todo doc
mutable
bool
_have_read_data
=
false
;
...
...
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