Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor 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
schwede
openstructure
Commits
9b789a74
Commit
9b789a74
authored
11 years ago
by
Marco Biasini
Browse files
Options
Downloads
Patches
Plain Diff
bool properties are numeric, too
parent
5aa899e9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/base/src/generic_property.hh
+46
-18
46 additions, 18 deletions
modules/base/src/generic_property.hh
with
46 additions
and
18 deletions
modules/base/src/generic_property.hh
+
46
−
18
View file @
9b789a74
...
...
@@ -212,27 +212,41 @@ public:
CheckHandleValidity
(
*
static_cast
<
const
H
*>
(
this
));
if
(
HasProp
(
key
))
{
GenericPropValue
value
=
this
->
GetImpl
()
->
GenericProp
(
key
);
if
(
value
.
which
()
==
1
)
{
return
boost
::
get
<
Real
>
(
this
->
GetImpl
()
->
GenericProp
(
key
));
}
else
if
(
value
.
which
()
==
2
)
{
return
boost
::
get
<
int
>
(
this
->
GetImpl
()
->
GenericProp
(
key
));
switch
(
value
.
which
())
{
case
1
:
return
boost
::
get
<
Real
>
(
value
);
case
2
:
return
static_cast
<
Real
>
(
boost
::
get
<
int
>
(
value
));
case
3
:
return
static_cast
<
Real
>
(
boost
::
get
<
bool
>
(
value
));
}
std
::
ostringstream
m
(
""
);
m
<<
"property '"
<<
key
<<
"' is not numeric"
;
throw
GenericPropError
(
m
.
str
());
}
else
{
std
::
ostringstream
m
(
""
);
m
<<
"unknown property "
<<
key
;
throw
GenericPropError
(
m
.
str
());
}
std
::
ostringstream
m
(
""
);
m
<<
"unknown property "
<<
key
;
throw
GenericPropError
(
m
.
str
());
}
/// \brief returns integer property, raises an exception if it does not exist
int
GetIntProp
(
const
String
&
key
)
const
{
CheckHandleValidity
(
*
static_cast
<
const
H
*>
(
this
));
return
this
->
gp_get
<
int
>
(
key
);
if
(
HasProp
(
key
)){
GenericPropValue
value
=
this
->
GetImpl
()
->
GenericProp
(
key
);
switch
(
value
.
which
())
{
case
2
:
return
boost
::
get
<
int
>
(
value
);
case
3
:
return
boost
::
get
<
bool
>
(
value
);
}
std
::
ostringstream
m
(
""
);
m
<<
"property '"
<<
key
<<
"' is not integral"
;
throw
GenericPropError
(
m
.
str
());
}
std
::
ostringstream
m
(
""
);
m
<<
"unknown property "
<<
key
;
throw
GenericPropError
(
m
.
str
());
}
/// \brief returns boolean property, raises an exception if it does not exist
...
...
@@ -256,24 +270,38 @@ public:
CheckHandleValidity
(
*
static_cast
<
const
H
*>
(
this
));
if
(
this
->
HasProp
(
key
))
{
GenericPropValue
value
=
GetImpl
()
->
GenericProp
(
key
);
if
(
value
.
which
()
==
1
)
{
return
boost
::
get
<
Real
>
(
GetImpl
()
->
GenericProp
(
key
));
}
else
if
(
value
.
which
()
==
2
)
{
return
boost
::
get
<
int
>
(
GetImpl
()
->
GenericProp
(
key
));
switch
(
value
.
which
())
{
case
1
:
return
boost
::
get
<
Real
>
(
value
);
case
2
:
return
static_cast
<
Real
>
(
boost
::
get
<
int
>
(
value
));
case
3
:
return
static_cast
<
Real
>
(
boost
::
get
<
bool
>
(
value
));
}
std
::
ostringstream
m
(
""
);
m
<<
"property '"
<<
key
<<
"' is not numeric"
;
throw
GenericPropError
(
m
.
str
());
}
else
{
return
def
;
}
return
def
;
}
/// \brief returns integer property, or the given default if it does not exist
int
GetIntProp
(
const
String
&
key
,
int
def
)
const
{
CheckHandleValidity
(
*
static_cast
<
const
H
*>
(
this
));
return
this
->
gp_get
<
int
>
(
key
,
def
);
if
(
this
->
HasProp
(
key
))
{
GenericPropValue
value
=
GetImpl
()
->
GenericProp
(
key
);
switch
(
value
.
which
())
{
case
2
:
return
boost
::
get
<
int
>
(
value
);
case
3
:
return
static_cast
<
int
>
(
boost
::
get
<
bool
>
(
value
));
}
std
::
ostringstream
m
(
""
);
m
<<
"property '"
<<
key
<<
"' is not integral"
;
throw
GenericPropError
(
m
.
str
());
}
return
def
;
}
/// \brief returns boolean property, or the given default if it does not exist
...
...
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