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
746d8959
Commit
746d8959
authored
14 years ago
by
Jorrit Fahlke
Browse files
Options
Downloads
Patches
Plain Diff
Allow parsing config files from a C++ stream, e.g. std::cin.
[[Imported from SVN: r5999]]
parent
724e5484
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
dune/common/configparser.cc
+9
-2
9 additions, 2 deletions
dune/common/configparser.cc
dune/common/configparser.hh
+13
-0
13 additions, 0 deletions
dune/common/configparser.hh
with
22 additions
and
2 deletions
dune/common/configparser.cc
+
9
−
2
View file @
746d8959
...
...
@@ -24,6 +24,13 @@ void ConfigParser::parseFile(std::string file)
if
(
!
in
)
DUNE_THROW
(
IOError
,
"Could not open configuration file "
<<
file
);
parseStream
(
in
,
"file '"
+
file
+
"'"
);
}
void
ConfigParser
::
parseStream
(
std
::
istream
&
in
,
const
std
::
string
srcname
)
{
string
prefix
;
set
<
string
>
keysInFile
;
while
(
!
in
.
eof
())
...
...
@@ -76,7 +83,8 @@ void ConfigParser::parseFile(std::string file)
}
if
(
keysInFile
.
count
(
key
)
!=
0
)
DUNE_THROW
(
Exception
,
"Key '"
<<
key
<<
"' appears twice in file '"
<<
file
<<
"' !"
);
DUNE_THROW
(
Exception
,
"Key '"
<<
key
<<
"' appears twice in "
<<
srcname
<<
" !"
);
else
{
(
*
this
)[
key
]
=
value
;
...
...
@@ -87,7 +95,6 @@ void ConfigParser::parseFile(std::string file)
}
}
in
.
close
();
return
;
}
...
...
This diff is collapsed.
Click to expand it.
dune/common/configparser.hh
+
13
−
0
View file @
746d8959
...
...
@@ -4,6 +4,7 @@
#define DUNE_CONFIGPARSER_HH
#include
<istream>
#include
<map>
#include
<vector>
#include
<string>
...
...
@@ -68,6 +69,18 @@ namespace Dune {
ConfigParser
();
/** \brief parse C++ stream
*
* Parses C++ stream and build hierarchical config structure.
*
* \param in The stream to parse
* \param srcname Name of the configuration source for error
* messages, "stdin" or a filename.
*/
void
parseStream
(
std
::
istream
&
in
,
const
std
::
string
srcname
=
"stream"
);
/** \brief parse file
*
* Parses file with given name and build hierarchical config structure.
...
...
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