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
4ea0d354
Commit
4ea0d354
authored
19 years ago
by
Carsten Gräser
Browse files
Options
Downloads
Patches
Plain Diff
class name changed
[[Imported from SVN: r2228]]
parent
d8766664
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/configparser.cc
+17
-15
17 additions, 15 deletions
common/configparser.cc
common/configparser.hh
+45
-25
45 additions, 25 deletions
common/configparser.hh
with
62 additions
and
40 deletions
common/configparser.cc
+
17
−
15
View file @
4ea0d354
...
...
@@ -8,10 +8,12 @@
#include
<assert.h>
Config
::
Config
()
using
namespace
dune
;
ConfigParser
::
ConfigParser
()
{}
void
Config
::
parseFile
(
string
file
)
void
Config
Parser
::
parseFile
(
string
file
)
{
ifstream
in
(
file
.
c_str
());
assert
(
in
);
...
...
@@ -44,7 +46,7 @@ void Config::parseFile(string file)
}
void
Config
::
parseCmd
(
int
argc
,
char
*
argv
[])
void
Config
Parser
::
parseCmd
(
int
argc
,
char
*
argv
[])
{
string
v
=
""
;
string
k
=
""
;
...
...
@@ -65,12 +67,12 @@ void Config::parseCmd(int argc, char* argv [])
return
;
}
void
Config
::
report
()
const
void
Config
Parser
::
report
()
const
{
report
(
""
);
}
void
Config
::
report
(
const
string
prefix
)
const
void
Config
Parser
::
report
(
const
string
prefix
)
const
{
typedef
map
<
string
,
string
>::
const_iterator
ValueIt
;
ValueIt
vit
=
values
.
begin
();
...
...
@@ -89,7 +91,7 @@ void Config::report(const string prefix) const
}
}
bool
Config
::
hasKey
(
const
string
&
key
)
bool
Config
Parser
::
hasKey
(
const
string
&
key
)
{
int
dot
=
key
.
find
(
"."
);
...
...
@@ -106,7 +108,7 @@ bool Config::hasKey(const string& key)
return
(
values
.
count
(
key
)
!=
0
);
}
bool
Config
::
hasSub
(
const
string
&
key
)
bool
Config
Parser
::
hasSub
(
const
string
&
key
)
{
int
dot
=
key
.
find
(
"."
);
...
...
@@ -123,7 +125,7 @@ bool Config::hasSub(const string& key)
return
(
subs
.
count
(
key
)
!=
0
);
}
Config
&
Config
::
sub
(
const
string
&
key
)
Config
Parser
&
Config
Parser
::
sub
(
const
string
&
key
)
{
int
dot
=
key
.
find
(
"."
);
...
...
@@ -136,7 +138,7 @@ Config& Config::sub(const string& key)
return
subs
[
key
];
}
string
&
Config
::
operator
[]
(
const
string
&
key
)
string
&
Config
Parser
::
operator
[]
(
const
string
&
key
)
{
int
dot
=
key
.
find
(
"."
);
...
...
@@ -149,7 +151,7 @@ string& Config::operator[] (const string& key)
return
values
[
key
];
}
string
Config
::
get
(
const
string
&
key
,
string
defaultValue
)
string
Config
Parser
::
get
(
const
string
&
key
,
string
defaultValue
)
{
if
(
hasKey
(
key
))
return
(
*
this
)[
key
];
...
...
@@ -158,14 +160,14 @@ string Config::get(const string& key, string defaultValue)
}
string
Config
::
get
(
const
string
&
key
,
char
*
defaultValue
)
string
Config
Parser
::
get
(
const
string
&
key
,
char
*
defaultValue
)
{
string
s
=
defaultValue
;
return
get
(
key
,
s
);
}
int
Config
::
get
(
const
string
&
key
,
int
defaultValue
)
int
Config
Parser
::
get
(
const
string
&
key
,
int
defaultValue
)
{
stringstream
stream
;
stream
<<
defaultValue
;
...
...
@@ -174,7 +176,7 @@ int Config::get(const string& key, int defaultValue)
return
atoi
(
ret
.
c_str
());
}
double
Config
::
get
(
const
string
&
key
,
double
defaultValue
)
double
Config
Parser
::
get
(
const
string
&
key
,
double
defaultValue
)
{
stringstream
stream
;
stream
<<
defaultValue
;
...
...
@@ -183,7 +185,7 @@ double Config::get(const string& key, double defaultValue)
return
atof
(
ret
.
c_str
());
}
bool
Config
::
get
(
const
string
&
key
,
bool
defaultValue
)
bool
Config
Parser
::
get
(
const
string
&
key
,
bool
defaultValue
)
{
stringstream
stream
;
if
(
defaultValue
)
...
...
@@ -196,7 +198,7 @@ bool Config::get(const string& key, bool defaultValue)
return
(
atoi
(
ret
.
c_str
())
!=
0
);
}
string
Config
::
trim
(
string
s
)
string
Config
Parser
::
trim
(
string
s
)
{
int
i
=
0
;
while
(
s
[
i
]
==
' '
)
...
...
This diff is collapsed.
Click to expand it.
common/configparser.hh
+
45
−
25
View file @
4ea0d354
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef
_
_CONFIGPARSER_
_
HH
__
#define
_
_CONFIGPARSER_
_
HH
__
#ifndef
DUNE
_CONFIGPARSER_HH
#define
DUNE
_CONFIGPARSER_HH
#include
<map>
#include
<string>
#include
<iostream>
using
namespace
std
;
namespace
dune
{
/** \brief Parser for hierarchical parameter files
* \ingroup Common
*
* This class parses files into a hierachical structure.
*
*/
class
Config
{
public:
class
Config
Parser
{
public:
Config
();
void
parseFile
(
string
file
);
void
parseCmd
(
int
argc
,
char
*
argv
[]);
/** \brief Parser for hierarchical parameter files
*
* This class parses files into a hierachical structure.
*
*/
ConfigParser
();
bool
Config
::
hasKey
(
const
string
&
key
);
bool
Config
::
hasSub
(
const
string
&
key
);
void
parseFile
(
string
file
);
void
parseCmd
(
int
argc
,
char
*
argv
[]
);
string
&
operator
[]
(
const
string
&
key
);
bool
hasKey
(
const
string
&
key
);
bool
hasSub
(
const
string
&
key
);
void
report
()
const
;
void
report
(
const
string
prefix
)
const
;
string
&
operator
[]
(
const
string
&
key
);
Config
&
sub
(
const
string
&
key
);
void
report
()
const
;
void
report
(
const
string
prefix
)
const
;
string
get
(
const
string
&
key
,
string
defaultValue
);
string
get
(
const
string
&
key
,
char
*
defaultValue
);
int
get
(
const
string
&
key
,
int
defaultValue
);
double
get
(
const
string
&
key
,
double
defaultValue
);
bool
get
(
const
string
&
key
,
bool
defaultValue
);
ConfigParser
&
sub
(
const
string
&
key
);
string
get
(
const
string
&
key
,
string
defaultValue
);
string
get
(
const
string
&
key
,
char
*
defaultValue
);
int
get
(
const
string
&
key
,
int
defaultValue
);
double
get
(
const
string
&
key
,
double
defaultValue
);
private:
map
<
string
,
string
>
values
;
map
<
string
,
Config
>
subs
;
string
trim
(
string
s
);
/** \brief kurz
*
* langes
* \param key Der Suchschlssel
* \param defaultValue
* \return
*/
bool
get
(
const
string
&
key
,
bool
defaultValue
);
private:
map
<
string
,
string
>
values
;
map
<
string
,
Config
>
subs
;
string
trim
(
string
s
);
};
};
}
// end namespace dune
...
...
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