preCICE
v3.1.2
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
Functions
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
Variables
_
a
b
c
d
e
f
g
h
i
m
n
p
r
s
t
Typedefs
b
d
e
g
l
m
p
r
s
t
u
v
Enumerations
Enumerator
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
~
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
~
Variables
_
a
b
c
d
e
f
g
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Typedefs
a
b
c
d
e
f
i
k
m
n
o
p
r
s
t
v
w
Enumerations
Enumerator
c
d
e
i
l
m
n
o
r
s
u
v
w
Related Symbols
Files
File List
File Members
All
_
a
b
c
d
e
f
g
i
j
m
n
o
p
r
s
t
v
Functions
a
b
c
g
m
p
r
s
t
v
Variables
Typedefs
Macros
b
d
f
m
n
p
t
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
src
xml
ValueParser.cpp
Go to the documentation of this file.
1
#include "
xml/ValueParser.hpp
"
2
#include <boost/algorithm/string/constants.hpp>
3
#include <boost/algorithm/string/split.hpp>
4
#include <
ostream
>
5
#include <
sstream
>
6
#include <
stdexcept
>
7
#include <
vector
>
8
9
namespace
precice::xml
{
10
11
namespace
{
12
constexpr
static
const
char
*PARSING_LOCALE =
"en_US.UTF-8"
;
13
14
double
parseDouble(
const
std::string
&rawValue)
15
{
16
std::istringstream
iss{rawValue};
17
try
{
18
iss.imbue(
std::locale
(PARSING_LOCALE));
19
}
catch
(...) {
20
}
21
double
value;
22
iss >> value;
23
if
(!iss.eof()) {
24
throw
std::runtime_error
{
"Could not fully parse value \""
+ rawValue +
"\" as a double."
};
25
}
26
return
value;
27
}
28
}
// namespace
29
30
void
readValueSpecific
(
const
std::string
&
rawValue
,
double
&value)
31
{
32
if
(
rawValue
.find(
'/'
) != std::string::npos) {
33
std::string
left =
rawValue
.substr(0,
rawValue
.find(
'/'
));
34
std::string
right =
rawValue
.substr(
rawValue
.find(
'/'
) + 1,
rawValue
.size() -
rawValue
.find(
'/'
) - 1);
35
36
value =
parseDouble
(left) /
parseDouble
(right);
37
}
else
{
38
value =
parseDouble
(
rawValue
);
39
}
40
}
30
void
readValueSpecific
(
const
std::string
&
rawValue
,
double
&value) {
…
}
41
42
void
readValueSpecific
(
const
std::string
&
rawValue
,
int
&value)
43
{
44
std::istringstream
iss
{
rawValue
};
45
try
{
46
iss
.imbue(
std::locale
(
PARSING_LOCALE
));
47
}
catch
(...) {
48
}
49
iss
>> value;
50
if
(!
iss
.eof()) {
51
throw
std::runtime_error
{
"Could not fully parse value \""
+
rawValue
+
"\" as an int."
};
52
}
53
}
42
void
readValueSpecific
(
const
std::string
&
rawValue
,
int
&value) {
…
}
54
55
void
readValueSpecific
(
const
std::string
&
rawValue
, Eigen::VectorXd &value)
56
{
57
std::vector<std::string>
components
;
58
boost::split(
59
components
,
rawValue
, [](
char
c) {
return
c ==
';'
; }, boost::algorithm::token_compress_on);
60
const
int
size =
components
.size();
61
if
(
size < 2 || size >
3) {
62
throw
std::runtime_error
{
"The value \""
+
rawValue
+
"\" is not a 2D or 3D vector."
};
63
}
64
65
Eigen::VectorXd
vec
(size);
66
for
(
int
i = 0; i != size; ++i) {
67
vec
(i) =
parseDouble
(
components
[i]);
68
}
69
value =
vec
;
70
}
55
void
readValueSpecific
(
const
std::string
&
rawValue
, Eigen::VectorXd &value) {
…
}
71
72
}
// namespace precice::xml
ValueParser.hpp
std::istringstream
std::string
precice::xml::XMLAttribute
Definition
XMLAttribute.hpp:20
std::locale
precice::xml
contains the XML configuration parser.
Definition
CommunicationConfiguration.hpp:9
precice::xml::readValueSpecific
void readValueSpecific(const std::string &rawValue, double &value)
Definition
ValueParser.cpp:30
ostream
std::runtime_error
sstream
stdexcept
vector