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
bca0bd28
Commit
bca0bd28
authored
6 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
[PL] Extract findParameterByName().
parent
ca1fb11c
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
ProcessLib/Utils/ProcessUtils.cpp
+20
-0
20 additions, 0 deletions
ProcessLib/Utils/ProcessUtils.cpp
ProcessLib/Utils/ProcessUtils.h
+13
-10
13 additions, 10 deletions
ProcessLib/Utils/ProcessUtils.h
with
33 additions
and
10 deletions
ProcessLib/Utils/ProcessUtils.cpp
+
20
−
0
View file @
bca0bd28
...
@@ -105,4 +105,24 @@ std::vector<std::reference_wrapper<ProcessVariable>> findProcessVariables(
...
@@ -105,4 +105,24 @@ std::vector<std::reference_wrapper<ProcessVariable>> findProcessVariables(
return
vars
;
return
vars
;
}
}
ParameterBase
*
findParameterByName
(
std
::
string
const
&
parameter_name
,
std
::
vector
<
std
::
unique_ptr
<
ParameterBase
>>
const
&
parameters
)
{
// Find corresponding parameter by name.
auto
const
it
=
std
::
find_if
(
parameters
.
cbegin
(),
parameters
.
cend
(),
[
&
parameter_name
](
std
::
unique_ptr
<
ParameterBase
>
const
&
p
)
{
return
p
->
name
==
parameter_name
;
});
if
(
it
==
parameters
.
end
())
{
return
nullptr
;
}
DBUG
(
"Found parameter `%s'."
,
(
*
it
)
->
name
.
c_str
());
return
it
->
get
();
}
}
// namespace ProcessLib
}
// namespace ProcessLib
This diff is collapsed.
Click to expand it.
ProcessLib/Utils/ProcessUtils.h
+
13
−
10
View file @
bca0bd28
...
@@ -47,6 +47,15 @@ std::vector<std::reference_wrapper<ProcessVariable>> findProcessVariables(
...
@@ -47,6 +47,15 @@ std::vector<std::reference_wrapper<ProcessVariable>> findProcessVariables(
BaseLib
::
ConfigTree
const
&
pv_config
,
BaseLib
::
ConfigTree
const
&
pv_config
,
std
::
string
const
&
tag
);
std
::
string
const
&
tag
);
/// Find an optional parameter of specific type for a given name.
///
/// \tparam ParameterDataType the data type of the parameter
/// \param parameter_name name of the requested parameter
/// \param parameters list of parameters in which it will be searched
ParameterBase
*
findParameterByName
(
std
::
string
const
&
parameter_name
,
std
::
vector
<
std
::
unique_ptr
<
ParameterBase
>>
const
&
parameters
);
/// Find an optional parameter of specific type for a given name.
/// Find an optional parameter of specific type for a given name.
///
///
/// \tparam ParameterDataType the data type of the parameter
/// \tparam ParameterDataType the data type of the parameter
...
@@ -63,22 +72,16 @@ Parameter<ParameterDataType>* findParameterOptional(
...
@@ -63,22 +72,16 @@ Parameter<ParameterDataType>* findParameterOptional(
int
const
num_components
)
int
const
num_components
)
{
{
// Find corresponding parameter by name.
// Find corresponding parameter by name.
auto
const
parameter_it
=
std
::
find_if
(
ParameterBase
*
parameter_ptr
=
parameters
.
cbegin
(),
parameters
.
cend
(),
findParameterByName
(
parameter_name
,
parameters
);
[
&
parameter_name
](
std
::
unique_ptr
<
ParameterBase
>
const
&
p
)
{
if
(
parameter_ptr
==
nullptr
)
return
p
->
name
==
parameter_name
;
});
if
(
parameter_it
==
parameters
.
end
())
{
{
return
nullptr
;
return
nullptr
;
}
}
DBUG
(
"Found parameter `%s'."
,
(
*
parameter_it
)
->
name
.
c_str
());
// Check the type correctness of the found parameter.
// Check the type correctness of the found parameter.
auto
*
const
parameter
=
auto
*
const
parameter
=
dynamic_cast
<
Parameter
<
ParameterDataType
>*>
(
parameter_
it
->
get
()
);
dynamic_cast
<
Parameter
<
ParameterDataType
>*>
(
parameter_
ptr
);
if
(
!
parameter
)
{
if
(
!
parameter
)
{
OGS_FATAL
(
"The read parameter `%s' is of incompatible type."
,
OGS_FATAL
(
"The read parameter `%s' is of incompatible type."
,
parameter_name
.
c_str
());
parameter_name
.
c_str
());
...
...
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